Documentation
¶
Index ¶
- Variables
- func Disable(name string)
- func Enable(name string)
- type Appender
- type Conf
- type Ctx
- type Level
- type Log
- type Logger
- func (l *Logger) AddContextKey(key string, value interface{}) *Logger
- func (l *Logger) Copy() *Logger
- func (l *Logger) Debug(msg interface{}, data ...interface{})
- func (l *Logger) Debugf(msg string, params ...interface{})
- func (l *Logger) Disable(target interface{})
- func (l *Logger) Enable(appender Appender)
- func (l *Logger) Error(msg interface{}, data ...interface{})
- func (l *Logger) Errorf(msg string, params ...interface{})
- func (l *Logger) Info(msg interface{}, data ...interface{})
- func (l *Logger) Infof(msg string, params ...interface{})
- func (l *Logger) Panic(msg interface{}, data ...interface{})
- func (l *Logger) Panicf(msg string, params ...interface{})
- func (l *Logger) SetContext(ctx Ctx) *Logger
- func (l *Logger) Warn(msg interface{}, data ...interface{})
- func (l *Logger) Warnf(msg string, params ...interface{})
- type Stdout
Constants ¶
This section is empty.
Variables ¶
var ( DEBUG = Level{ Value: 10, Name: "DEBUG", // contains filtered or unexported fields } INFO = Level{ Value: 20, Name: "INFO", // contains filtered or unexported fields } WARN = Level{ Value: 30, Name: "WARN", // contains filtered or unexported fields } ERROR = Level{ Value: 40, Name: "ERROR", // contains filtered or unexported fields } PANIC = Level{ Value: 50, Name: "PANIC", // contains filtered or unexported fields } )
Functions ¶
Types ¶
type Appender ¶
type Appender interface { // method for injecting log to some source // when appender receives Log instance through this method, // it should decide what to do with log Append(log Log) // method will return appender ID // it will be used for disabling appenders Id() string }
Interface for implementing custom appenders.
type Level ¶
type Level struct { // level priority value // bigger number has bigger priority Value int `json:"value"` // level name Name string `json:"name"` // contains filtered or unexported fields }
Representing log level
type Log ¶
type Log struct { // date and time of log Time time.Time `json:"time"` // logged message Message string `json:"message"` // log level Level Level `json:"level"` // additional data sent to log // this part should be handled by appenders // appender can decide to ignore data or to store it on specific way Data []interface{} `json:"data"` // represents data bound to contextual logger Ctx Ctx `json:"ctx"` // id of process which made log Pid int `json:"pid"` // logger instance Logger *Logger `json:"logger"` }
Representing one Log instance
type Logger ¶
type Logger struct { // name of logger // logger name will be shown in stdout appender output // also it can be used to enable/disable logger Name string `json:"name"` // minimum level of log to be shown Level Level `json:"-"` // if this flag is set to true, in case any errors in appender // appender should panic. This also depends on appender implementation, // so appender can decide to ignore or to accept information in this flag DoPanic bool `json:"-"` // contains filtered or unexported fields }
Representing one logger instance Logger can have multiple appenders, it can enable it, or disable it. Also you can define level which will be specific to this logger.
var ( // instance of default logger Default *Logger )
func (*Logger) AddContextKey ¶
func (*Logger) Debug ¶
func (l *Logger) Debug(msg interface{}, data ...interface{})
Making log with DEBUG level.
func (*Logger) Disable ¶
func (l *Logger) Disable(target interface{})
If you want to disable logs from some appender you can use this method. You have to call method either with appender instance, or you can pass appender Id as argument. If appender is found, it will be removed from list of appenders of this logger, and all other further logs won't be received by this appender.
func (*Logger) Enable ¶
When you want to send logs to another appender, you should create instance of appender and call this method. Method is expecting appender instance to be passed to this method. At the end passed appender will receive logs
func (*Logger) Error ¶
func (l *Logger) Error(msg interface{}, data ...interface{})
Making log with ERROR level.
func (*Logger) Info ¶
func (l *Logger) Info(msg interface{}, data ...interface{})
Making log with INFO level.
func (*Logger) Panic ¶
func (l *Logger) Panic(msg interface{}, data ...interface{})
Making log with PANIC level.
func (*Logger) SetContext ¶
Will set context to current logger. Later appenders will be able to extract context from Log instance.