Documentation ¶
Overview ¶
Package logger provides structured logging abstraction or facade, to be used by code which is not aware what logging library is used by end user.
Index ¶
- type Adapter
- type Entry
- type Field
- type Global
- func (g *Global) Debug(ctx context.Context, msg string)
- func (g *Global) Error(ctx context.Context, msg string)
- func (g *Global) Info(ctx context.Context, msg string)
- func (g *Global) SetAdapter(adapter Adapter)
- func (g *Global) Warn(ctx context.Context, msg string)
- func (g *Global) With(key string, value interface{}) Logger
- func (g *Global) WithError(err error) Logger
- type Level
- type Local
- func (l Local) Debug(ctx context.Context, msg string)
- func (l Local) Error(ctx context.Context, msg string)
- func (l Local) Info(ctx context.Context, msg string)
- func (l Local) Warn(ctx context.Context, msg string)
- func (l Local) With(key string, value interface{}) Logger
- func (l Local) WithError(err error) Logger
- func (l Local) WithSkippedCallerFrame() Logger
- type Logger
- func (l Logger) Debug(ctx context.Context, msg string)
- func (l Logger) Error(ctx context.Context, msg string)
- func (l Logger) Info(ctx context.Context, msg string)
- func (l Logger) Warn(ctx context.Context, msg string)
- func (l Logger) With(key string, value interface{}) Logger
- func (l Logger) WithError(err error) Logger
- func (l Logger) WithSkippedCallerFrame() Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct { Level Level Message string Fields []Field // Fields can be nil Error error // Error can be nil // SkippedCallerFrames can be used by logger.Adapter to extract caller information (file and line number) SkippedCallerFrames int }
Entry is a logging entry created by logger and passed to adapter.
type Global ¶
type Global struct {
// contains filtered or unexported fields
}
Global is a logger shared globally. You can use it to define global logger for your package:
package yourpackage import "github.com/elgopher/yala/logger" var log logger.Global // define global logger, no need to initialize (by default nothing is logged) func SetLoggerAdapter(adapter logger.Adapter) { log.SetAdapter(adapter) }
It is safe to use it concurrently.
func (*Global) SetAdapter ¶
SetAdapter updates adapter implementation. By default, nothing is logged.
It can be run anytime. Please note though that this method is meant to be used by end user, configuring logging from the central place (such as main.go or any other package setting up the entire application).
type Level ¶
type Level int8
Level is a severity level of message. Use Level.MoreSevereThan to compare two levels.
const ( // DebugLevel level is usually enabled only when debugging (disabled in production). Very verbose logging. DebugLevel Level = iota - 1 // InfoLevel is used for informational messages, for confirmation that the program is working as expected. InfoLevel // WarnLevel is used for non-critical entries that deserve eyes. WarnLevel // ErrorLevel is used for errors that should definitely be noted. If an application is running smoothly, // it shouldn't generate any error-level logs. ErrorLevel )
func (Level) MoreSevereThan ¶ added in v0.16.0
MoreSevereThan returns true if level is more severe than the argument.
type Local ¶
type Local struct {
Adapter Adapter
}
Local is an immutable struct to log messages or create new loggers with fields or error.
It is safe to use it concurrently.
func (Local) WithSkippedCallerFrame ¶ added in v0.12.0
WithSkippedCallerFrame creates a new Logger with one more skipped caller frame. This function is handy when you want to write your own logging helpers.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is an immutable struct to log messages or create new loggers with fields or error.
It is safe to use it concurrently.
func (Logger) WithSkippedCallerFrame ¶
WithSkippedCallerFrame creates a new Logger with one more skipped caller frame. This function is handy when you want to write your own logging helpers.