Documentation ¶
Index ¶
- func EntryToString(entry Entry, byteBuffer *bytebufferpool.ByteBuffer)
- func ErrorHandler(error error, entry Entry)
- func InjectInContext(ctx context.Context, l LoggerInterface) context.Context
- type Context
- func (c *Context) Add(name string, value interface{}) *Context
- func (c *Context) Binary(name string, value []byte) *Context
- func (c *Context) ByteString(name string, value []byte) *Context
- func (c *Context) Get(name string, defaultField *Field) Field
- func (c *Context) GoString() string
- func (c *Context) Has(name string) bool
- func (c *Context) Merge(context Context) *Context
- func (c *Context) SetField(fields ...Field) *Context
- func (c *Context) Skip(name string, value string) *Context
- func (c *Context) Slice() *Fields
- func (c *Context) String() string
- func (c *Context) StringTo(byteBuffer *bytebufferpool.ByteBuffer) *Context
- type Entry
- type Field
- func Any(name string, value interface{}) Field
- func Binary(name string, value []byte) Field
- func Bool(name string, value bool) Field
- func ByteString(name string, value []byte) Field
- func Complex128(name string, value complex128) Field
- func Complex64(name string, value complex64) Field
- func Duration(name string, value time.Duration) Field
- func Error(name string, value error) Field
- func Float32(name string, value float32) Field
- func Float64(name string, value float64) Field
- func Int16(name string, value int16) Field
- func Int32(name string, value int32) Field
- func Int64(name string, value int64) Field
- func Int8(name string, value int8) Field
- func Reflect(name string, value interface{}) Field
- func Skip(name string, value string) Field
- func String(name string, value string) Field
- func Stringer(name string, value fmt.Stringer) Field
- func Time(name string, value time.Time) Field
- func Uint16(name string, value uint16) Field
- func Uint32(name string, value uint32) Field
- func Uint64(name string, value uint64) Field
- func Uint8(name string, value uint8) Field
- func Uintptr(name string, value uintptr) Field
- type FieldType
- type Fields
- func (f *Fields) Add(name string, value interface{}) *Fields
- func (f *Fields) Binary(name string, value []byte) *Fields
- func (f *Fields) ByteString(name string, value []byte) *Fields
- func (f *Fields) GoString() string
- func (f *Fields) SetField(fields ...Field) *Fields
- func (f *Fields) Skip(name string, value string) *Fields
- func (f *Fields) String() string
- func (f *Fields) StringTo(byteBuffer *bytebufferpool.ByteBuffer)
- type FormatterInterface
- type HandlerInterface
- type Level
- type LevelString
- type LogInterface
- type Logger
- func (l *Logger) Alert(message string, fields ...Field)
- func (l *Logger) Critical(message string, fields ...Field)
- func (l *Logger) Debug(message string, fields ...Field)
- func (l *Logger) Emergency(message string, fields ...Field)
- func (l *Logger) Error(message string, fields ...Field)
- func (l *Logger) Info(message string, fields ...Field)
- func (l *Logger) Log(message string, level Level, fields ...Field)
- func (l *Logger) Notice(message string, fields ...Field)
- func (l *Logger) Warning(message string, fields ...Field)
- func (l *Logger) Wrap(middlewares ...MiddlewareInterface) LoggerInterface
- func (l *Logger) WrapNew(middlewares ...MiddlewareInterface) LoggerInterface
- type LoggerInterface
- type MiddlewareInterface
- type Middlewares
- type NopFormatter
- type WrappableLoggerInterface
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EntryToString ¶
func EntryToString(entry Entry, byteBuffer *bytebufferpool.ByteBuffer)
EntryToString will write entry as string in byteBuffer
func ErrorHandler ¶
ErrorHandler will print error and entry when logging error occurred
func InjectInContext ¶
func InjectInContext(ctx context.Context, l LoggerInterface) context.Context
InjectInContext will inject a logger into the go-context
Types ¶
type Context ¶
Context contain all contextual log data we advise you to choose your data wisely You should keep a reasonable quantity of data
func NewContext ¶
NewContext will create a new context with optional fields
func (*Context) ByteString ¶
ByteString will add byteString field to context
func (*Context) GoString ¶
GoString was called by fmt.Printf("%#v", context) fmt GoStringer interface
func (*Context) StringTo ¶ added in v0.5.10
func (c *Context) StringTo(byteBuffer *bytebufferpool.ByteBuffer) *Context
type Entry ¶
Entry represents a log in its entirety it is composed of a level, a message and a context
type Field ¶
Field represents a contextual information this data was carry by Context struct
func ByteString ¶
ByteString will create ByteString Field
func Complex128 ¶
func Complex128(name string, value complex128) Field
Complex128 will create Complex128 Field
func (*Field) MarshalJSON ¶
MarshalJSON was called by json.Marshal(field) json Marshaller interface
type FieldType ¶
type FieldType uint8
FieldType represents the type of a logger context field
const ( // UnknownType is the default field type. UnknownType FieldType = iota // SkipType indicates that the field is a no-op. SkipType BoolType Int8Type Int16Type Int32Type Int64Type Uint8Type Uint16Type Uint32Type Uint64Type UintptrType Float32Type Float64Type Complex64Type Complex128Type StringType BinaryType ByteStringType ErrorType TimeType DurationType StringerType // ReflectType indicates that the field carries an interface{}, which should be serialized using reflection. ReflectType )
list of available field types
type Fields ¶
type Fields []Field
Fields was slice format of Fields
func (*Fields) ByteString ¶
ByteString will add byteString field to fields
func (*Fields) StringTo ¶ added in v0.5.10
func (f *Fields) StringTo(byteBuffer *bytebufferpool.ByteBuffer)
type FormatterInterface ¶
FormatterInterface will convert Entry into string ex: format a log entry to string/json/... format
type HandlerInterface ¶
HandlerInterface allows you to process a Entry See basic handler implementations in the handler package.
var NopHandler HandlerInterface = func(entry Entry) error { return nil }
NopHandler is a no operating handler that do nothing with received Entry
func DecorateHandler ¶
func DecorateHandler(handler HandlerInterface, middlewares ...MiddlewareInterface) HandlerInterface
DecorateHandler will return the handler after decorate with middlewares
type Level ¶
type Level int8
Level represent log Entry levelString
const ( EmergencyLevel Level = iota AlertLevel CriticalLevel ErrorLevel WarningLevel NoticeLevel InfoLevel DebugLevel )
Log Severity level
https://github.com/freebsd/freebsd/blob/master/sys/sys/syslog.h#L51 From /usr/include/sys/syslog.h. These are the same on Linux, BSD, and OS X.
func (Level) StringTo ¶ added in v0.5.10
func (l Level) StringTo(byteBuffer *bytebufferpool.ByteBuffer)
StringTo will return Level as string
type LevelString ¶
type LevelString string
LevelString represent log Entry level as string
func (LevelString) Level ¶
func (l LevelString) Level() Level
Level will return log Level for string or DebugLevel if unknown value
type LogInterface ¶
LogInterface define simplest logger contract See LoggerInterface for a more convenient one
type Logger ¶
Logger is basic implementation of WrappableLoggerInterface
Example (CallerHandler) ¶
package main import ( "bytes" "fmt" "strings" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" "github.com/gol4ng/logger/middleware" ) func main() { output := &Output{} myLogger := logger.NewLogger( middleware.Caller(3)( handler.Stream(output, formatter.NewLine("lvl: %[2]s | msg: %[1]s | ctx: %[3]v")), ), ) myLogger.Debug("Log example") myLogger.Info("Log example") myLogger.Notice("Log example") myLogger.Warning("Log example") myLogger.Error("Log example") myLogger.Critical("Log example") myLogger.Alert("Log example") myLogger.Emergency("Log example") output.Contains([]string{ "lvl: debug | msg: Log example | ctx:", "<file:/", "<line:", "lvl: info | msg: Log example | ctx:", "<file:/", "<line:", "lvl: notice | msg: Log example | ctx:", "<file:/", "<line:", "lvl: warning | msg: Log example | ctx:", "<file:/", "<line:", "lvl: error | msg: Log example | ctx:", "<file:/", "<line:", "lvl: critical | msg: Log example | ctx:", "<file:/", "<line:", "lvl: alert | msg: Log example | ctx:", "<file:/", "<line:", "lvl: emergency | msg: Log example | ctx:", "<file:/", "<line:", }) } type Output struct { bytes.Buffer } func (o *Output) Contains(str []string) { b := o.String() for _, s := range str { if strings.Contains(b, s) != true { fmt.Printf("buffer %s must contain %s\n", b, s) } } }
Output:
Example (GroupHandler) ¶
package main import ( "bytes" "fmt" "strings" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { output := &Output{} output2 := &Output{} myLogger := logger.NewLogger( handler.Group( handler.Stream(output, formatter.NewJSONEncoder()), handler.Stream(output2, formatter.NewDefaultFormatter(formatter.WithContext(true))), ), ) myLogger.Debug("Log example", logger.Any("my_key", "my_value")) myLogger.Info("Log example", logger.Any("my_key", "my_value")) myLogger.Notice("Log example", logger.Any("my_key", "my_value")) myLogger.Warning("Log example", logger.Any("my_key", "my_value")) myLogger.Error("Log example", logger.Any("my_key", "my_value")) myLogger.Critical("Log example", logger.Any("my_key", "my_value")) myLogger.Alert("Log example", logger.Any("my_key", "my_value")) myLogger.Emergency("Log example", logger.Any("my_key", "my_value")) output.Contains([]string{ `{"Message":"Log example","Level":7,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":6,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":5,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":4,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":3,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":2,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":1,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":0,"Context":{"my_key":"my_value"}}`, }) output2.Contains([]string{ `<debug> Log example {"my_key":"my_value"}`, `<info> Log example {"my_key":"my_value"}`, `<notice> Log example {"my_key":"my_value"}`, `<warning> Log example {"my_key":"my_value"}`, `<error> Log example {"my_key":"my_value"}`, `<critical> Log example {"my_key":"my_value"}`, `<alert> Log example {"my_key":"my_value"}`, `<emergency> Log example {"my_key":"my_value"}`, }) } type Output struct { bytes.Buffer } func (o *Output) Contains(str []string) { b := o.String() for _, s := range str { if strings.Contains(b, s) != true { fmt.Printf("buffer %s must contain %s\n", b, s) } } }
Output:
Example (JsonFormatter) ¶
package main import ( "bytes" "fmt" "strings" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { output := &Output{} myLogger := logger.NewLogger( handler.Stream(output, formatter.NewJSONEncoder()), ) myLogger.Debug("Log example", logger.Any("my_key", "my_value")) myLogger.Info("Log example", logger.Any("my_key", "my_value")) myLogger.Notice("Log example", logger.Any("my_key", "my_value")) myLogger.Warning("Log example", logger.Any("my_key", "my_value")) myLogger.Error("Log example", logger.Any("my_key", "my_value")) myLogger.Critical("Log example", logger.Any("my_key", "my_value")) myLogger.Alert("Log example", logger.Any("my_key", "my_value")) myLogger.Emergency("Log example", logger.Any("my_key", "my_value")) output.Contains([]string{ `{"Message":"Log example","Level":7,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":6,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":5,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":4,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":3,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":2,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":1,"Context":{"my_key":"my_value"}}`, `{"Message":"Log example","Level":0,"Context":{"my_key":"my_value"}}`, }) } type Output struct { bytes.Buffer } func (o *Output) Contains(str []string) { b := o.String() for _, s := range str { if strings.Contains(b, s) != true { fmt.Printf("buffer %s must contain %s\n", b, s) } } }
Output:
Example (LineFormatter) ¶
package main import ( "bytes" "fmt" "strings" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { output := &Output{} myLogger := logger.NewLogger( handler.Stream(output, formatter.NewLine("lvl: %[2]s | msg: %[1]s | ctx: %[3]v")), ) myLogger.Debug("Log example", logger.Any("my_key", "my_value")) myLogger.Info("Log example", logger.Any("my_key", "my_value")) myLogger.Notice("Log example", logger.Any("my_key", "my_value")) myLogger.Warning("Log example", logger.Any("my_key", "my_value")) myLogger.Error("Log example", logger.Any("my_key", "my_value")) myLogger.Critical("Log example", logger.Any("my_key", "my_value")) myLogger.Alert("Log example", logger.Any("my_key", "my_value")) myLogger.Emergency("Log example", logger.Any("my_key", "my_value")) output.Contains([]string{ "lvl: debug | msg: Log example | ctx: <my_key:my_value>", "lvl: info | msg: Log example | ctx: <my_key:my_value>", "lvl: notice | msg: Log example | ctx: <my_key:my_value>", "lvl: warning | msg: Log example | ctx: <my_key:my_value>", "lvl: error | msg: Log example | ctx: <my_key:my_value>", "lvl: critical | msg: Log example | ctx: <my_key:my_value>", "lvl: alert | msg: Log example | ctx: <my_key:my_value>", "lvl: emergency | msg: Log example | ctx: <my_key:my_value>", }) } type Output struct { bytes.Buffer } func (o *Output) Contains(str []string) { b := o.String() for _, s := range str { if strings.Contains(b, s) != true { fmt.Printf("buffer %s must contain %s\n", b, s) } } }
Output:
Example (LogRotateHandler) ¶
package main import ( "os" "time" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { lineFormatter := formatter.NewLine("lvl: %[2]s | msg: %[1]s | ctx: %[3]v") rotateLogHandler, _ := handler.LogRotateFileStream("test", os.TempDir()+"/%s.log", time.Stamp, lineFormatter, 1*time.Second) myLogger := logger.NewLogger(rotateLogHandler) myLogger.Debug("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Info("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Warning("Log example", logger.Any("ctx_key", "ctx_value")) time.Sleep(1 * time.Second) myLogger.Error("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Alert("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Critical("Log example", logger.Any("ctx_key", "ctx_value")) }
Output:
Example (MinLevelFilterHandler) ¶
package main import ( "bytes" "fmt" "strings" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" "github.com/gol4ng/logger/middleware" ) func main() { output := &Output{} myLogger := logger.NewLogger( middleware.MinLevelFilter(logger.WarningLevel)( handler.Stream(output, formatter.NewDefaultFormatter(formatter.WithContext(true))), ), ) myLogger.Debug("Log example", logger.Any("my_key", "my_value")) myLogger.Info("Log example", logger.Any("my_key", "my_value")) myLogger.Notice("Log example", logger.Any("my_key", "my_value")) myLogger.Warning("Log example", logger.Any("my_key", "my_value")) myLogger.Error("Log example", logger.Any("my_key", "my_value")) myLogger.Critical("Log example", logger.Any("my_key", "my_value")) myLogger.Alert("Log example", logger.Any("my_key", "my_value")) myLogger.Emergency("Log example", logger.Any("my_key", "my_value")) output.Contains([]string{ `<warning> Log example {"my_key":"my_value"}`, `<error> Log example {"my_key":"my_value"}`, `<critical> Log example {"my_key":"my_value"}`, `<alert> Log example {"my_key":"my_value"}`, `<emergency> Log example {"my_key":"my_value"}`, }) } type Output struct { bytes.Buffer } func (o *Output) Contains(str []string) { b := o.String() for _, s := range str { if strings.Contains(b, s) != true { fmt.Printf("buffer %s must contain %s\n", b, s) } } }
Output:
Example (PlaceholderMiddleware) ¶
package main import ( "bytes" "fmt" "strings" "time" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" "github.com/gol4ng/logger/middleware" ) func main() { output := &Output{} myLogger := logger.NewLogger( handler.Stream(output, formatter.NewLine("%[2]s %[1]s%.[3]s")), ) myLogger.Wrap(middleware.Placeholder()) myLogger.Debug("Log %ctx_key% example", logger.Any("ctx_key", false)) myLogger.Info("Log %ctx_key% example", logger.Any("ctx_key", 1234)) myLogger.Warning("Log %ctx_key% example", logger.Any("ctx_key", 5*time.Second)) myLogger.Error("Log %ctx_key% example", logger.Any("ctx_key", "ctx_value")) myLogger.Alert("Log %ctx_key% example", logger.Any("ctx_key", struct{ attr string }{attr: "attrValue"})) myLogger.Critical("Log %ctx_key% example another value %ctx_key2%", logger.Any("ctx_key", false), logger.Any("ctx_key2", 1234)) output.Contains([]string{ `debug Log false example`, `info Log 1234 example`, `warning Log 5s example`, `error Log ctx_value example`, `alert Log {attrValue} example`, `critical Log false example another value 1234`, }) } type Output struct { bytes.Buffer } func (o *Output) Contains(str []string) { b := o.String() for _, s := range str { if strings.Contains(b, s) != true { fmt.Printf("buffer %s must contain %s\n", b, s) } } }
Output:
Example (SyslogHandler) ¶
You can run the command below to show syslog messages syslog -F '$Time $Host $(Sender)[$(PID)] <$((Level)(str))>: $Message' Apr 26 12:22:06 hades my_go_logger[69302] <Notice>: <notice> Log example2 {"ctx_key":"ctx_value"} Apr 26 12:22:06 hades my_go_logger[69302] <Warning>: <warning> Log example3 {"ctx_key":"ctx_value"} Apr 26 12:22:06 hades my_go_logger[69302] <Error>: <error> Log example4 {"ctx_key":"ctx_value"} Apr 26 12:22:06 hades my_go_logger[69302] <Critical>: <critical> Log example5 {"ctx_key":"ctx_value"} Apr 26 12:22:06 hades my_go_logger[69302] <Alert>: <alert> Log example6 {"ctx_key":"ctx_value"} Apr 26 12:22:06 hades my_go_logger[69302] <Emergency>: <emergency> Log example7 {"ctx_key":"ctx_value"}
package main import ( "log/syslog" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { syslogHandler, _ := handler.Syslog( formatter.NewDefaultFormatter(formatter.WithContext(true)), "", "", syslog.LOG_DEBUG, "my_go_logger") myLogger := logger.NewLogger(syslogHandler) myLogger.Debug("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Info("Log example1", logger.Any("ctx_key", "ctx_value")) myLogger.Notice("Log example2", logger.Any("ctx_key", "ctx_value")) myLogger.Warning("Log example3", logger.Any("ctx_key", "ctx_value")) myLogger.Error("Log example4", logger.Any("ctx_key", "ctx_value")) myLogger.Critical("Log example5", logger.Any("ctx_key", "ctx_value")) myLogger.Alert("Log example6", logger.Any("ctx_key", "ctx_value")) myLogger.Emergency("Log example7", logger.Any("ctx_key", "ctx_value")) }
Output:
Example (TimeRotateHandler) ¶
package main import ( "os" "time" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" ) func main() { lineFormatter := formatter.NewLine("lvl: %[2]s | msg: %[1]s | ctx: %[3]v") rotateLogHandler, _ := handler.TimeRotateFileStream(os.TempDir()+"/%s.log", time.Stamp, lineFormatter, 1*time.Second) myLogger := logger.NewLogger(rotateLogHandler) myLogger.Debug("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Info("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Warning("Log example", logger.Any("ctx_key", "ctx_value")) time.Sleep(1 * time.Second) myLogger.Error("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Alert("Log example", logger.Any("ctx_key", "ctx_value")) myLogger.Critical("Log example", logger.Any("ctx_key", "ctx_value")) }
Output:
Example (WrapHandler) ¶
package main import ( "bytes" "fmt" "strings" "github.com/gol4ng/logger" "github.com/gol4ng/logger/formatter" "github.com/gol4ng/logger/handler" "github.com/gol4ng/logger/middleware" ) func main() { output := &Output{} myLogger := logger.NewLogger( handler.Stream(output, formatter.NewDefaultFormatter(formatter.WithContext(true))), ) myLogger.Wrap(middleware.MinLevelFilter(logger.WarningLevel)) myLogger.Debug("Log example", logger.Any("my_key", "my_value")) myLogger.Info("Log example", logger.Any("my_key", "my_value")) myLogger.Notice("Log example", logger.Any("my_key", "my_value")) myLogger.Warning("Log example", logger.Any("my_key", "my_value")) myLogger.Error("Log example", logger.Any("my_key", "my_value")) myLogger.Critical("Log example", logger.Any("my_key", "my_value")) myLogger.Alert("Log example", logger.Any("my_key", "my_value")) myLogger.Emergency("Log example", logger.Any("my_key", "my_value")) output.Contains([]string{ `<warning> Log example {"my_key":"my_value"}`, `<error> Log example {"my_key":"my_value"}`, `<critical> Log example {"my_key":"my_value"}`, `<alert> Log example {"my_key":"my_value"}`, `<emergency> Log example {"my_key":"my_value"}`, }) } type Output struct { bytes.Buffer } func (o *Output) Contains(str []string) { b := o.String() for _, s := range str { if strings.Contains(b, s) != true { fmt.Printf("buffer %s must contain %s\n", b, s) } } }
Output:
func NewLogger ¶
func NewLogger(handler HandlerInterface) *Logger
NewLogger will return a new logger
func NewNopLogger ¶
func NewNopLogger() *Logger
NewNopLogger will create a new no operating logger that log nowhere
func (*Logger) Wrap ¶
func (l *Logger) Wrap(middlewares ...MiddlewareInterface) LoggerInterface
Wrap will return the logger after decorate his handler with given middleware
func (*Logger) WrapNew ¶
func (l *Logger) WrapNew(middlewares ...MiddlewareInterface) LoggerInterface
WrapNew will return a new logger after wrap his handler with given middleware
type LoggerInterface ¶
type LoggerInterface interface { LogInterface Debug(message string, field ...Field) Info(message string, field ...Field) Notice(message string, field ...Field) Warning(message string, field ...Field) Error(message string, field ...Field) Critical(message string, field ...Field) Alert(message string, field ...Field) Emergency(message string, field ...Field) }
LoggerInterface define a convenient logger contract
func FromContext ¶
func FromContext(ctx context.Context, defaultLogger LoggerInterface) LoggerInterface
FromContext will retrieve a logger from the go-context or return defaultLogger
type MiddlewareInterface ¶
type MiddlewareInterface func(HandlerInterface) HandlerInterface
MiddlewareInterface is a function to decorate handler See middleware implementations in the middleware package.
type Middlewares ¶
type Middlewares []MiddlewareInterface
Middlewares was a collection of middleware the slice order matter when middleware are compose with DecorateHandler
func MiddlewareStack ¶
func MiddlewareStack(middlewares ...MiddlewareInterface) Middlewares
MiddlewareStack helper return Middlewares slice from given middlewares
func (Middlewares) Decorate ¶
func (m Middlewares) Decorate(handler HandlerInterface) HandlerInterface
Decorate will return the handler after decorate with middlewares
type NopFormatter ¶
type NopFormatter struct{}
NopFormatter is a no operating formatter
func NewNopFormatter ¶
func NewNopFormatter() *NopFormatter
NewNopFormatter will create a NopFormatter
func (*NopFormatter) Format ¶
func (n *NopFormatter) Format(_ Entry) string
Format will return empty string
type WrappableLoggerInterface ¶
type WrappableLoggerInterface interface { LoggerInterface // Implementation should return the same logger after wrapping it Wrap(middlewares ...MiddlewareInterface) LoggerInterface // Implementation should return a new decorated logger WrapNew(middlewares ...MiddlewareInterface) LoggerInterface }
WrappableLoggerInterface define a contract to wrap or decorate the logger with given middleware