Documentation ¶
Overview ¶
Package log logged data by handler and use processor, exposes eight methods to write logs to the eight RFC 5424 levels.
Index ¶
- func Alert(ctx context.Context, args ...interface{})
- func AlertKV(ctx context.Context, msg string, args ...interface{})
- func Alertf(ctx context.Context, format string, args ...interface{})
- func Crit(ctx context.Context, args ...interface{})
- func CritKV(ctx context.Context, msg string, args ...interface{})
- func Critf(ctx context.Context, format string, args ...interface{})
- func Debug(ctx context.Context, args ...interface{})
- func DebugKV(ctx context.Context, msg string, args ...interface{})
- func Debugf(ctx context.Context, format string, args ...interface{})
- func Emerg(ctx context.Context, args ...interface{})
- func EmergKV(ctx context.Context, msg string, args ...interface{})
- func Emergf(ctx context.Context, format string, args ...interface{})
- func Err(ctx context.Context, args ...interface{})
- func ErrKV(ctx context.Context, msg string, args ...interface{})
- func Errf(ctx context.Context, format string, args ...interface{})
- func Info(ctx context.Context, args ...interface{})
- func InfoKV(ctx context.Context, msg string, args ...interface{})
- func Infof(ctx context.Context, format string, args ...interface{})
- func Notice(ctx context.Context, args ...interface{})
- func NoticeKV(ctx context.Context, msg string, args ...interface{})
- func Noticef(ctx context.Context, format string, args ...interface{})
- func SetLogger(l *Logger)
- func Warn(ctx context.Context, args ...interface{})
- func WarnKV(ctx context.Context, msg string, args ...interface{})
- func Warnf(ctx context.Context, format string, args ...interface{})
- type Field
- type Fields
- type Handler
- type Level
- type Logger
- func (l *Logger) Alert(ctx context.Context, args ...interface{})
- func (l *Logger) AlertKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Alertf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Crit(ctx context.Context, args ...interface{})
- func (l *Logger) CritKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Critf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Debug(ctx context.Context, args ...interface{})
- func (l *Logger) DebugKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Debugf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Emerg(ctx context.Context, args ...interface{})
- func (l *Logger) EmergKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Emergf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Err(ctx context.Context, args ...interface{})
- func (l *Logger) ErrKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Errf(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Info(ctx context.Context, args ...interface{})
- func (l *Logger) InfoKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Infof(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Notice(ctx context.Context, args ...interface{})
- func (l *Logger) NoticeKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Noticef(ctx context.Context, format string, args ...interface{})
- func (l *Logger) Warn(ctx context.Context, args ...interface{})
- func (l *Logger) WarnKV(ctx context.Context, msg string, args ...interface{})
- func (l *Logger) Warnf(ctx context.Context, format string, args ...interface{})
- type Middleware
- type Processor
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
Handler logged message
func NewHandler ¶
func NewHandler(handler Handler, mw ...Middleware) Handler
NewHandler add middleware to handler
type Level ¶
type Level uint8
Level log.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger log
func New ¶
func New(handler Handler, mw ...Middleware) *Logger
New create new logger by handler
Example ¶
ctx := context.Background() logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelInfo)) logger.Info(ctx, "same message")
Output: msg="same message"
Example (DebugKV) ¶
ctx := context.Background() logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelDebug), levelInfo) logger.DebugKV(ctx, "same message", "error", os.ErrNotExist)
Output: msg="same message" error=file does not exist level=debug
Example (Errf) ¶
ctx := context.Background() logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelInfo)) logger.Errf(ctx, "same message %d", 1)
Output: msg="same message 1"
Example (Level) ¶
ctx := context.Background() logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelError), levelInfo) logger.Info(ctx, "same message") // Output: logger.Err(ctx, "same error message")
Output: msg="same error message" level=error
type Middleware ¶
Middleware handle
func ChainMiddlerware ¶
func ChainMiddlerware(mw ...Middleware) Middleware
ChainMiddlerware chain one or more middleware
type Processor ¶
Processor processsed additional field
Example ¶
var ctxKey ctxKey = "requestID" ctx := context.WithValue(context.Background(), ctxKey, "6a5fa048-7181-11ea-bc55-0242ac130003") l := log.New(os.Stdout, "", 0) logger := New( NewStdHandler(l, LevelInfo), levelInfo, ctxProcessor(ctxKey), apiVersion, goVersion, ) logger.Info(ctx, "same message")
Output: msg="same message" level=info requestID=6a5fa048-7181-11ea-bc55-0242ac130003 api=0.1.0 go=go1.13.4
Source Files ¶
Click to show internal directories.
Click to hide internal directories.