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 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 Level
- type LogFunc
- type LogfFunc
- type Logger
- type OmitLogger
- func (w *OmitLogger) Debug(ctx context.Context, args ...interface{})
- func (w *OmitLogger) Debugf(ctx context.Context, msg string, args ...interface{})
- func (w *OmitLogger) Error(ctx context.Context, args ...interface{})
- func (w *OmitLogger) Errorf(ctx context.Context, msg string, args ...interface{})
- func (w *OmitLogger) Fatal(ctx context.Context, args ...interface{})
- func (w *OmitLogger) Fatalf(ctx context.Context, msg string, args ...interface{})
- func (w *OmitLogger) Fields(fields map[string]interface{}) Logger
- func (w *OmitLogger) Info(ctx context.Context, args ...interface{})
- func (w *OmitLogger) Infof(ctx context.Context, msg string, args ...interface{})
- func (w *OmitLogger) Init(opts ...Option) error
- func (w *OmitLogger) Log(ctx context.Context, level Level, args ...interface{})
- func (w *OmitLogger) Logf(ctx context.Context, level Level, msg string, args ...interface{})
- func (w *OmitLogger) Options() Options
- func (w *OmitLogger) String() string
- func (w *OmitLogger) Trace(ctx context.Context, args ...interface{})
- func (w *OmitLogger) Tracef(ctx context.Context, msg string, args ...interface{})
- func (w *OmitLogger) V(level Level) bool
- func (w *OmitLogger) Warn(ctx context.Context, args ...interface{})
- func (w *OmitLogger) Warnf(ctx context.Context, msg string, args ...interface{})
- type OmitWrapper
- type Option
- func SetOption(k, v interface{}) Option
- func WithCallerSkipCount(c int) Option
- func WithContext(ctx context.Context) Option
- func WithFields(fields map[string]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 ¶
View Source
var ( // DefaultLogger variable DefaultLogger Logger = NewLogger() // DefaultLevel used by logger DefaultLevel Level = InfoLevel )
Functions ¶
func NewContext ¶
NewContext stores logger into passed context
Types ¶
type Level ¶
type Level int8
Level means logger level
const ( // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel Level = iota - 2 // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // InfoLevel level. General operational entries about what's going on inside the application. InfoLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // ErrorLevel level. Used for errors that should definitely be noted. ErrorLevel // FatalLevel level. Logs and then calls `os.Exit(1)`. highest level of severity. FatalLevel )
func GetLevel ¶
GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.
type Logger ¶
type Logger interface { // Init initialises options Init(opts ...Option) error // V compare provided verbosity level with current log level V(level Level) bool // The Logger options Options() Options // Fields set fields to always be logged Fields(fields map[string]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 ¶ added in v3.4.7
type OmitLogger ¶ added in v3.4.7
type OmitLogger struct {
// contains filtered or unexported fields
}
func (*OmitLogger) Debug ¶ added in v3.4.7
func (w *OmitLogger) Debug(ctx context.Context, args ...interface{})
func (*OmitLogger) Debugf ¶ added in v3.4.7
func (w *OmitLogger) Debugf(ctx context.Context, msg string, args ...interface{})
func (*OmitLogger) Error ¶ added in v3.4.7
func (w *OmitLogger) Error(ctx context.Context, args ...interface{})
func (*OmitLogger) Errorf ¶ added in v3.4.7
func (w *OmitLogger) Errorf(ctx context.Context, msg string, args ...interface{})
func (*OmitLogger) Fatal ¶ added in v3.4.7
func (w *OmitLogger) Fatal(ctx context.Context, args ...interface{})
func (*OmitLogger) Fatalf ¶ added in v3.4.7
func (w *OmitLogger) Fatalf(ctx context.Context, msg string, args ...interface{})
func (*OmitLogger) Fields ¶ added in v3.4.7
func (w *OmitLogger) Fields(fields map[string]interface{}) Logger
func (*OmitLogger) Info ¶ added in v3.4.7
func (w *OmitLogger) Info(ctx context.Context, args ...interface{})
func (*OmitLogger) Infof ¶ added in v3.4.7
func (w *OmitLogger) Infof(ctx context.Context, msg string, args ...interface{})
func (*OmitLogger) Init ¶ added in v3.4.7
func (w *OmitLogger) Init(opts ...Option) error
func (*OmitLogger) Log ¶ added in v3.4.7
func (w *OmitLogger) Log(ctx context.Context, level Level, args ...interface{})
func (*OmitLogger) Logf ¶ added in v3.4.7
func (w *OmitLogger) Logf(ctx context.Context, level Level, msg string, args ...interface{})
func (*OmitLogger) Options ¶ added in v3.4.7
func (w *OmitLogger) Options() Options
func (*OmitLogger) String ¶ added in v3.4.7
func (w *OmitLogger) String() string
func (*OmitLogger) Trace ¶ added in v3.4.7
func (w *OmitLogger) Trace(ctx context.Context, args ...interface{})
func (*OmitLogger) Tracef ¶ added in v3.4.7
func (w *OmitLogger) Tracef(ctx context.Context, msg string, args ...interface{})
func (*OmitLogger) V ¶ added in v3.4.7
func (w *OmitLogger) V(level Level) bool
func (*OmitLogger) Warn ¶ added in v3.4.7
func (w *OmitLogger) Warn(ctx context.Context, args ...interface{})
type OmitWrapper ¶ added in v3.4.6
type OmitWrapper struct{}
func (*OmitWrapper) Log ¶ added in v3.4.6
func (w *OmitWrapper) Log(fn LogFunc) LogFunc
func (*OmitWrapper) Logf ¶ added in v3.4.6
func (w *OmitWrapper) Logf(fn LogfFunc) LogfFunc
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 ¶
WithFields set default fields for the logger
func WithOutput ¶
WithOutput set default output writer for the logger
func WrapLogger ¶ added in v3.4.6
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 map[string]interface{} // Name holds the logger name Name string // CallerSkipCount number of frmaes to skip CallerSkipCount int // The logging level the logger should log Level Level // Wrappers logger wrapper that called before actual Log/Logf function Wrappers []Wrapper }
Options holds logger options
Click to show internal directories.
Click to hide internal directories.