Documentation ¶
Overview ¶
Package logger provides a log interface
Index ¶
- Variables
- func Debug(ctx context.Context, args ...interface{})
- func Debugf(ctx context.Context, msg string, args ...interface{})
- func Error(ctx context.Context, args ...interface{})
- func Errorf(ctx context.Context, msg string, args ...interface{})
- func Fatal(ctx context.Context, args ...interface{})
- func Fatalf(ctx context.Context, msg string, args ...interface{})
- func Info(ctx context.Context, args ...interface{})
- func Infof(ctx context.Context, msg string, args ...interface{})
- func Init(opts ...Option) error
- func NewContext(ctx context.Context, l Logger) context.Context
- func NewStdLogger(l Logger, level Level) *log.Logger
- func RedirectStdLogger(l Logger, level Level) func()
- func Trace(ctx context.Context, args ...interface{})
- func Tracef(ctx context.Context, msg string, args ...interface{})
- func V(level Level) bool
- func Warn(ctx context.Context, args ...interface{})
- func Warnf(ctx context.Context, msg string, args ...interface{})
- type Field
- type Level
- type LogFunc
- type LogfFunc
- type Logger
- type Option
- func SetOption(k, v interface{}) Option
- func WithCallerSkipCount(c int) Option
- func WithContext(ctx context.Context) Option
- func WithFields(fields ...interface{}) Option
- func WithLevel(level Level) Option
- func WithName(n string) Option
- func WithOutput(out io.Writer) Option
- func WrapLogger(w Wrapper) Option
- type Options
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLogger variable DefaultLogger = NewLogger(WithLevel(ParseLevel(os.Getenv("MICRO_LOG_LEVEL")))) // DefaultLevel used by logger DefaultLevel = InfoLevel // DefaultCallerSkipCount used by logger DefaultCallerSkipCount = 2 )
Functions ¶
func NewContext ¶
NewContext stores logger into passed context
func NewStdLogger ¶
NewStdLogger returns new *log.Logger baked by logger.Logger implementation
func RedirectStdLogger ¶
RedirectStdLogger replace *log.Logger with logger.Logger implementation
Types ¶
type Level ¶
type Level int8
Level means logger level
const ( // TraceLevel level usually used to find bugs, very verbose TraceLevel Level = iota - 2 // DebugLevel level used only when enabled debugging DebugLevel // InfoLevel level used for general info about what's going on inside the application InfoLevel // WarnLevel level used for non-critical entries WarnLevel // ErrorLevel level used for errors that should definitely be noted ErrorLevel // FatalLevel level used for critical errors and then calls `os.Exit(1)` FatalLevel )
func ParseLevel ¶
ParseLevel converts a level string into a logger Level value. returns an InfoLevel if the input string does not match known values.
type Logger ¶
type Logger interface { // Init initialises options Init(opts ...Option) error // Clone create logger copy with new options Clone(opts ...Option) Logger // V compare provided verbosity level with current log level V(level Level) bool // Level sets the log level for logger Level(level Level) // The Logger options Options() Options // Fields set fields to always be logged with keyval pairs Fields(fields ...interface{}) Logger // Info level message Info(ctx context.Context, args ...interface{}) // Trace level message Trace(ctx context.Context, args ...interface{}) // Debug level message Debug(ctx context.Context, args ...interface{}) // Warn level message Warn(ctx context.Context, args ...interface{}) // Error level message Error(ctx context.Context, args ...interface{}) // Fatal level message Fatal(ctx context.Context, args ...interface{}) // Infof level message Infof(ctx context.Context, msg string, args ...interface{}) // Tracef level message Tracef(ctx context.Context, msg string, args ...interface{}) // Debug level message Debugf(ctx context.Context, msg string, args ...interface{}) // Warn level message Warnf(ctx context.Context, msg string, args ...interface{}) // Error level message Errorf(ctx context.Context, msg string, args ...interface{}) // Fatal level message Fatalf(ctx context.Context, msg string, args ...interface{}) // Log logs message with needed level Log(ctx context.Context, level Level, args ...interface{}) // Logf logs message with needed level Logf(ctx context.Context, level Level, msg string, args ...interface{}) // String returns the name of logger String() string }
Logger is a generic logging interface
func FromContext ¶
FromContext returns logger from passed context
func NewOmitLogger ¶
type Option ¶
type Option func(*Options)
Option func
func SetOption ¶
func SetOption(k, v interface{}) Option
SetOption returns a function to setup a context with given value
func WithCallerSkipCount ¶
WithCallerSkipCount set frame count to skip
func WithFields ¶
func WithFields(fields ...interface{}) Option
WithFields set default fields for the logger
func WithOutput ¶
WithOutput set default output writer for the logger
func WrapLogger ¶
WrapLogger adds a logger Wrapper to a list of options passed into the logger
type Options ¶
type Options struct { // Out holds the output writer Out io.Writer // Context holds exernal options Context context.Context // Fields holds additional metadata Fields []interface{} // Name holds the logger name Name string // Wrappers logger wrapper that called before actual Log/Logf function Wrappers []Wrapper // The logging level the logger should log Level Level // CallerSkipCount number of frmaes to skip CallerSkipCount int }
Options holds logger options