Documentation ¶
Overview ¶
Package slog Lightweight, extensible, configurable logging library written in Go.
Source code and other details for the project are available at GitHub:
https://github.com/gookit/slog
Quick usage:
package main import ( "github.com/gookit/slog" ) func main() { slog.Info("info log message") slog.Warn("warning log message") slog.Infof("info log %s", "message") slog.Debugf("debug %s", "message") }
More usage please see README.
Example (ConfigSlog) ¶
package main import ( "github.com/tomorrowsky/slog" ) func main() { slog.Configure(func(logger *slog.SugaredLogger) { f := logger.Formatter.(*slog.TextFormatter) f.EnableColor = true }) slog.Trace("this is a simple log message") slog.Debug("this is a simple log message") slog.Info("this is a simple log message") slog.Notice("this is a simple log message") slog.Warn("this is a simple log message") slog.Error("this is a simple log message") slog.Fatal("this is a simple log message") }
Output:
Example (QuickStart) ¶
package main import ( "github.com/tomorrowsky/slog" ) func main() { slog.Info("info log message") slog.Warn("warning log message") slog.Infof("info log %s", "message") slog.Debugf("debug %s", "message") }
Output:
Example (UseJSONFormat) ¶
package main import ( "github.com/tomorrowsky/slog" ) func main() { // use JSON formatter slog.SetFormatter(slog.NewJSONFormatter()) slog.Info("info log message") slog.Warn("warning log message") slog.WithData(slog.M{ "key0": 134, "key1": "abc", }).Infof("info log %s", "message") r := slog.WithFields(slog.M{ "category": "service", "IP": "127.0.0.1", }) r.Infof("info %s", "message") r.Debugf("debug %s", "message") }
Output:
Index ¶
- Constants
- Variables
- func AddHandler(h Handler)
- func AddHandlers(hs ...Handler)
- func AddProcessor(p Processor)
- func AddProcessors(ps ...Processor)
- func Configure(fn func(logger *SugaredLogger))
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func EncodeToString(v interface{}) string
- func Error(args ...interface{})
- func ErrorT(err error)
- func Errorf(format string, args ...interface{})
- func Exit(code int)
- func ExitHandlers() []func()
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Flush() error
- func FlushDaemon()
- func FlushTimeout(timeout time.Duration)
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func LevelName(l Level) string
- func Notice(args ...interface{})
- func Noticef(format string, args ...interface{})
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func PrependExitHandler(handler func())
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func PushHandler(h Handler)
- func PushHandlers(hs ...Handler)
- func RegisterExitHandler(handler func())
- func Reset()
- func ResetExitHandlers(applyToStd bool)
- func SetExitFunc(fn func(code int))
- func SetFormatter(f Formatter)
- func SetLogLevel(l Level)
- func Trace(args ...interface{})
- func Tracef(format string, args ...interface{})
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type FlushCloseWriter
- type Formattable
- type FormattableHandler
- type Formatter
- type FormatterFunc
- type FormatterWriterHandler
- type Handler
- type JSONFormatter
- type Level
- type Levels
- type Logger
- func (l *Logger) AddHandler(h Handler)
- func (l *Logger) AddHandlers(hs ...Handler)
- func (l *Logger) AddProcessor(p Processor)
- func (l *Logger) AddProcessors(ps ...Processor)
- func (l *Logger) Close()
- func (l *Logger) Configure(fn func(l *Logger)) *Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) ErrorT(err error)
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Exit(code int)
- func (l *Logger) ExitHandlers() []func()
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(format string, args ...interface{})
- func (l *Logger) Fatalln(args ...interface{})
- func (l *Logger) Flush()
- func (l *Logger) FlushAll()
- func (l *Logger) FlushDaemon()
- func (l *Logger) FlushTimeout(timeout time.Duration)
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Log(level Level, args ...interface{})
- func (l *Logger) Logf(level Level, format string, args ...interface{})
- func (l *Logger) Name() string
- func (l *Logger) Notice(args ...interface{})
- func (l *Logger) Noticef(format string, args ...interface{})
- func (l *Logger) Panic(args ...interface{})
- func (l *Logger) Panicf(format string, args ...interface{})
- func (l *Logger) Panicln(args ...interface{})
- func (l *Logger) PrependExitHandler(handler func())
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(format string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) PushHandler(h Handler)
- func (l *Logger) PushHandlers(hs ...Handler)
- func (l *Logger) PushProcessor(p Processor)
- func (l *Logger) RegisterExitHandler(handler func())
- func (l *Logger) Reset()
- func (l *Logger) ResetExitHandlers()
- func (l *Logger) ResetHandlers()
- func (l *Logger) ResetProcessors()
- func (l *Logger) SetHandlers(hs []Handler)
- func (l *Logger) SetName(name string)
- func (l *Logger) SetProcessors(ps []Processor)
- func (l *Logger) Sync() error
- func (l *Logger) Trace(args ...interface{})
- func (l *Logger) Tracef(format string, args ...interface{})
- func (l *Logger) VisitAll(fn func(handler Handler) error)
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) Warning(args ...interface{})
- func (l *Logger) WithContext(ctx context.Context) *Record
- func (l *Logger) WithData(data M) *Record
- func (l *Logger) WithFields(fields M) *Record
- func (l *Logger) WithTime(t time.Time) *Record
- type M
- type Processable
- type ProcessableHandler
- type Processor
- type ProcessorFunc
- type Record
- func (r *Record) AddData(data M) *Record
- func (r *Record) AddExtra(data M) *Record
- func (r *Record) AddField(name string, val interface{}) *Record
- func (r *Record) AddFields(fields M) *Record
- func (r *Record) AddValue(key string, value interface{}) *Record
- func (r *Record) Copy() *Record
- func (r *Record) Debug(args ...interface{})
- func (r *Record) Debugf(format string, args ...interface{})
- func (r *Record) Error(args ...interface{})
- func (r *Record) Errorf(format string, args ...interface{})
- func (r *Record) Fatal(args ...interface{})
- func (r *Record) Fatalf(format string, args ...interface{})
- func (r *Record) Fatalln(args ...interface{})
- func (r *Record) Info(args ...interface{})
- func (r *Record) Infof(format string, args ...interface{})
- func (r *Record) LevelName() string
- func (r *Record) Log(level Level, args ...interface{})
- func (r *Record) Logf(level Level, format string, args ...interface{})
- func (r *Record) MicroSecond() int
- func (r *Record) NewBuffer() *bytes.Buffer
- func (r *Record) Notice(args ...interface{})
- func (r *Record) Noticef(format string, args ...interface{})
- func (r *Record) Panic(args ...interface{})
- func (r *Record) Panicf(format string, args ...interface{})
- func (r *Record) Panicln(args ...interface{})
- func (r *Record) Print(args ...interface{})
- func (r *Record) Printf(format string, args ...interface{})
- func (r *Record) Println(args ...interface{})
- func (r *Record) SetContext(ctx context.Context) *Record
- func (r *Record) SetData(data M) *Record
- func (r *Record) SetExtra(data M) *Record
- func (r *Record) SetExtraValue(k string, v interface{})
- func (r *Record) SetFields(fields M) *Record
- func (r *Record) SetTime(t time.Time) *Record
- func (r *Record) Trace(args ...interface{})
- func (r *Record) Tracef(format string, args ...interface{})
- func (r *Record) WithContext(ctx context.Context) *Record
- func (r *Record) WithData(data M) *Record
- func (r *Record) WithError(err error) *Record
- func (r *Record) WithField(name string, val interface{}) *Record
- func (r *Record) WithFields(fields M) *Record
- func (r *Record) WithTime(t time.Time) *Record
- type StringMap
- type SugaredLogger
- func (sl *SugaredLogger) Close() error
- func (sl *SugaredLogger) Configure(fn func(sl *SugaredLogger)) *SugaredLogger
- func (sl *SugaredLogger) Flush() error
- func (sl *SugaredLogger) FlushAll() error
- func (sl *SugaredLogger) Handle(record *Record) error
- func (sl *SugaredLogger) IsHandling(level Level) bool
- func (sl *SugaredLogger) Reset()
- type TextFormatter
Examples ¶
Constants ¶
const DefaultTemplate = "[{{datetime}}] [{{channel}}] [{{level}}] [{{caller}}] {{message}} {{data}} {{extra}}\n"
const NamedTemplate = "{{datetime}} channel={{channel}} level={{level}} [file={{caller}}] message={{message}} data={{data}}\n"
Variables ¶
var ( FieldKeyTime = "time" // FieldKeyData = "data" FieldKeyData = "data" // FieldKeyCaller filename with line with func name. eg: "logger_test.go:48->TestLogger_ReportCaller" FieldKeyCaller = "caller" // FieldKeyFLine filename with line. eg: "logger_test.go:48" FieldKeyFLine = "fline" // FieldKeyPkg package name. "github.com/gookit/slog_test" FieldKeyPkg = "package" // FieldKeyFunc package with func name. eg: "github.com/gookit/slog_test.TestLogger_ReportCaller" FieldKeyFunc = "func" // FieldKeyFunc only func name. eg: "TestLogger_ReportCaller" FieldKeyFcName = "fcname" // FieldKeyFile full filepath with line. eg: "/work/go/gookit/slog/logger_test.go:48" FieldKeyFile = "file" FieldKeyDatetime = "datetime" FieldKeyTimestamp = "timestamp" FieldKeyLevel = "level" FieldKeyError = "error" FieldKeyExtra = "extra" FieldKeyChannel = "channel" FieldKeyMessage = "message" )
var ( DefaultChannelName = "application" DefaultTimeFormat = "2006/01/02 15:04:05" )
var ( // AllLevels exposing all logging levels AllLevels = Levels{ PanicLevel, FatalLevel, ErrorLevel, WarnLevel, NoticeLevel, InfoLevel, DebugLevel, TraceLevel, } DangerLevels = Levels{PanicLevel, FatalLevel, ErrorLevel, WarnLevel} NormalLevels = Levels{InfoLevel, NoticeLevel, DebugLevel, TraceLevel} // PrintLevel for use logger.Print / Printf / Println PrintLevel = InfoLevel // LevelNames all level mapping name LevelNames = map[Level]string{ PanicLevel: "PANIC", FatalLevel: "FATAL", ErrorLevel: "ERROR", NoticeLevel: "NOTICE", WarnLevel: "WARNING", InfoLevel: "INFO", DebugLevel: "DEBUG", TraceLevel: "TRACE", } )
var ( // DefaultFields default log export fields DefaultFields = []string{ FieldKeyDatetime, FieldKeyChannel, FieldKeyLevel, FieldKeyCaller, FieldKeyMessage, FieldKeyData, FieldKeyExtra, } // NoTimeFields log export fields without time NoTimeFields = []string{ FieldKeyChannel, FieldKeyLevel, FieldKeyMessage, FieldKeyData, FieldKeyExtra, } )
var ColorTheme = map[Level]color.Color{ FatalLevel: color.FgRed, ErrorLevel: color.FgMagenta, WarnLevel: color.FgYellow, NoticeLevel: color.OpBold, InfoLevel: color.FgGreen, DebugLevel: color.FgCyan, }
ColorTheme for format log to console
var DoNothingOnExit = func(code int) {
}
DoNothingOnExit handler. use for testing.
var (
// ErrorKey Define the key when adding errors using WithError.
ErrorKey = "error"
)
Functions ¶
func Exit ¶
func Exit(code int)
Exit runs all the logger exit handlers and then terminates the program using os.Exit(code)
func FlushDaemon ¶
func FlushDaemon()
FlushDaemon run flush handle on daemon
Usage:
go slog.FlushDaemon()
func Noticef ¶
func Noticef(format string, args ...interface{})
Noticef logs a message at level Notice
func PrependExitHandler ¶
func PrependExitHandler(handler func())
PrependExitHandler prepend register an exit-handler on global exitHandlers
func Printf ¶
func Printf(format string, args ...interface{})
Printf logs a message at level PrintLevel
func RegisterExitHandler ¶
func RegisterExitHandler(handler func())
RegisterExitHandler register an exit-handler on global exitHandlers
func ResetExitHandlers ¶
func ResetExitHandlers(applyToStd bool)
ResetExitHandlers reset all exitHandlers
Types ¶
type FlushCloseWriter ¶
type FlushCloseWriter interface { Flush() error // WriteCloser the output writer io.WriteCloser }
FlushCloseWriter is the interface satisfied by logging destinations.
type Formattable ¶
type Formattable struct {
// contains filtered or unexported fields
}
Formattable definition
func (*Formattable) FormatRecord ¶
func (f *Formattable) FormatRecord(record *Record) ([]byte, error)
FormatRecord to bytes
func (*Formattable) Formatter ¶
func (f *Formattable) Formatter() Formatter
Formatter get formatter. if not set, will return TextFormatter
func (*Formattable) SetFormatter ¶
func (f *Formattable) SetFormatter(formatter Formatter)
SetFormatter to handler
type FormattableHandler ¶
type FormattableHandler interface { // Formatter get the log formatter Formatter() Formatter // SetFormatter set the log formatter SetFormatter(Formatter) }
FormattableHandler interface
type Formatter ¶
type Formatter interface { // Format you can format record and write result to record.Buffer Format(record *Record) ([]byte, error) }
Formatter interface
type FormatterFunc ¶
FormatterFunc wrapper definition
type FormatterWriterHandler ¶
type FormatterWriterHandler interface { Handler // Formatter record formatter Formatter() Formatter // Writer the output writer Writer() io.Writer }
FormatterWriterHandler interface
type Handler ¶
type Handler interface { // Closer Close handler. // You should first call Flush() on close logic. // Refer the FileHandler.Close() handle io.Closer // Flush logs to disk Flush() error // IsHandling Checks whether the given record will be handled by this handler. IsHandling(level Level) bool // Handle a log record. // All records may be passed to this method, and the handler should discard // Those that it does not want to handle. Handle(*Record) error }
Handler interface definition
type JSONFormatter ¶
type JSONFormatter struct { // Fields exported log fields. Fields []string // Aliases for output fields. you can change export field name. // item: `"field" : "output name"` // eg: {"message": "msg"} export field will display "msg" Aliases StringMap // PrettyPrint will indent all json logs PrettyPrint bool // TimeFormat the time format layout. default is time.RFC3339 TimeFormat string }
JSONFormatter definition
func NewJSONFormatter ¶
func NewJSONFormatter(fn ...func(*JSONFormatter)) *JSONFormatter
NewJSONFormatter create new JSONFormatter
func (*JSONFormatter) Configure ¶
func (f *JSONFormatter) Configure(fn func(*JSONFormatter)) *JSONFormatter
Configure current formatter
type Level ¶
type Level uint32
Level type
const ( // PanicLevel level, highest level of severity. will call panic() if the logging level <= PanicLevel. PanicLevel Level = 100 // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level <= FatalLevel. FatalLevel Level = 200 // ErrorLevel level. Runtime errors. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel Level = 300 // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel Level = 400 // NoticeLevel level Uncommon events NoticeLevel Level = 500 // InfoLevel level. Examples: User logs in, SQL logs. InfoLevel Level = 600 // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel Level = 700 // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel Level = 800 )
These are the different logging levels. You can set the logging level to log handler
func (Level) ShouldHandling ¶
ShouldHandling compare level
type Logger ¶
type Logger struct { // options // ReportCaller on log message ReportCaller bool LowerLevelName bool MaxCallerDepth int ExitFunc func(code int) // contains filtered or unexported fields }
Logger definition. The logger implements the `github.com/gookit/gsr.Logger`
func New ¶
func New() *Logger
New create an new logger
Example ¶
package main import ( "github.com/tomorrowsky/slog" "github.com/tomorrowsky/slog/handler" ) func main() { mylog := slog.New() mylog.AddHandler(handler.MustFileHandler("app.log", false)) mylog.Info("info log message") mylog.Warn("warning log message") mylog.Infof("info log %s", "message") }
Output:
func NewWithConfig ¶
NewWithConfig create an new logger with config func
func NewWithHandlers ¶
NewWithHandlers create an new logger with handlers
func (*Logger) AddProcessors ¶
AddProcessors to the logger
func (*Logger) Debug ¶
func (l *Logger) Debug(args ...interface{})
Debug logs a message at level Debug
func (*Logger) Error ¶
func (l *Logger) Error(args ...interface{})
Error logs a message at level error
func (*Logger) ExitHandlers ¶
func (l *Logger) ExitHandlers() []func()
ExitHandlers get all exitHandlers of the logger
func (*Logger) Fatal ¶
func (l *Logger) Fatal(args ...interface{})
Fatal logs a message at level Fatal
func (*Logger) Fatalln ¶
func (l *Logger) Fatalln(args ...interface{})
Fatalln logs a message at level Fatal
func (*Logger) Flush ¶
func (l *Logger) Flush()
Flush flushes all the logs to disk. alias of the FlushAll()
func (*Logger) FlushAll ¶
func (l *Logger) FlushAll()
FlushAll flushes all the logs and attempts to "sync" their data to disk. l.mu is held.
func (*Logger) FlushDaemon ¶
func (l *Logger) FlushDaemon()
FlushDaemon run flush handle on daemon
Usage:
go slog.FlushDaemon()
func (*Logger) FlushTimeout ¶
FlushTimeout flush logs on limit time. refer from glog package
func (*Logger) Notice ¶
func (l *Logger) Notice(args ...interface{})
Notice logs a message at level Notice
func (*Logger) Panic ¶
func (l *Logger) Panic(args ...interface{})
Panic logs a message at level Panic
func (*Logger) Panicln ¶
func (l *Logger) Panicln(args ...interface{})
Panicln logs a message at level Panic
func (*Logger) PrependExitHandler ¶
func (l *Logger) PrependExitHandler(handler func())
PrependExitHandler prepend register an exit-handler on global exitHandlers
func (*Logger) Print ¶
func (l *Logger) Print(args ...interface{})
Print logs a message at level PrintLevel
func (*Logger) Println ¶
func (l *Logger) Println(args ...interface{})
Println logs a message at level PrintLevel
func (*Logger) PushHandler ¶
PushHandler to the l. alias of AddHandler()
func (*Logger) PushHandlers ¶
PushHandlers to the logger
func (*Logger) PushProcessor ¶
PushProcessor to the logger alias of AddProcessor()
func (*Logger) RegisterExitHandler ¶
func (l *Logger) RegisterExitHandler(handler func())
RegisterExitHandler register an exit-handler on global exitHandlers
func (*Logger) ResetExitHandlers ¶
func (l *Logger) ResetExitHandlers()
ResetExitHandlers reset logger exitHandlers
func (*Logger) SetProcessors ¶
SetProcessors for the logger
func (*Logger) Trace ¶
func (l *Logger) Trace(args ...interface{})
Trace logs a message at level Trace
func (*Logger) Warning ¶
func (l *Logger) Warning(args ...interface{})
Warning logs a message at level Warn
func (*Logger) WithContext ¶
WithContext new record with context.Context
func (*Logger) WithFields ¶
WithFields new record with fields
type Processable ¶
type Processable struct {
// contains filtered or unexported fields
}
Processable definition
func (*Processable) AddProcessor ¶
func (p *Processable) AddProcessor(processor Processor)
AddProcessor to the handler
func (*Processable) ProcessRecord ¶
func (p *Processable) ProcessRecord(r *Record)
ProcessRecord process records
type ProcessableHandler ¶
type ProcessableHandler interface { // AddProcessor add an processor AddProcessor(Processor) // ProcessRecord handle an record ProcessRecord(record *Record) }
ProcessableHandler interface
type Processor ¶
type Processor interface { // Process record Process(record *Record) }
Processor interface definition
type ProcessorFunc ¶
type ProcessorFunc func(record *Record)
ProcessorFunc wrapper definition
var MemoryUsage ProcessorFunc = func(record *Record) { stat := new(runtime.MemStats) runtime.ReadMemStats(stat) record.SetExtraValue("memoryUsage", stat.Alloc) }
MemoryUsage Get memory usage.
type Record ¶
type Record struct { Time time.Time Level Level // Channel log channel name. eg: "order", "goods", "user" Channel string Message string // Ctx context.Context Ctx context.Context // Buffer Can use Buffer on formatter Buffer *bytes.Buffer // Fields custom fields data. // Contains all the fields set by the user. Fields M // Data log context data Data M // Extra log extra data Extra M // Caller information Caller *runtime.Frame // contains filtered or unexported fields }
Record a log record definition
func (*Record) Debug ¶
func (r *Record) Debug(args ...interface{})
Debug logs a message at level Debug
func (*Record) Error ¶
func (r *Record) Error(args ...interface{})
Error logs a message at level Error
func (*Record) Fatal ¶
func (r *Record) Fatal(args ...interface{})
Fatal logs a message at level Fatal
func (*Record) Fatalln ¶
func (r *Record) Fatalln(args ...interface{})
Fatalln logs a message at level Fatal
func (*Record) Notice ¶
func (r *Record) Notice(args ...interface{})
Notice logs a message at level Notice
func (*Record) Panic ¶
func (r *Record) Panic(args ...interface{})
Panic logs a message at level Panic
func (*Record) Panicln ¶
func (r *Record) Panicln(args ...interface{})
Panicln logs a message at level Panic
func (*Record) Print ¶
func (r *Record) Print(args ...interface{})
Print logs a message at level Print
func (*Record) Println ¶
func (r *Record) Println(args ...interface{})
Println logs a message at level Print
func (*Record) SetContext ¶
SetContext on record
func (*Record) SetExtraValue ¶
SetExtraValue on record
func (*Record) Trace ¶
func (r *Record) Trace(args ...interface{})
Trace logs a message at level Trace
func (*Record) WithContext ¶
WithContext on record
func (*Record) WithFields ¶
WithFields with new fields to record
type SugaredLogger ¶
type SugaredLogger struct { *Logger // Formatter log message formatter. default use TextFormatter Formatter Formatter // Output output writer Output io.Writer // Level for log handling. // Greater than or equal to this level will be recorded Level Level }
SugaredLogger definition. Is a fast and usable Logger, which already contains the default formatting and handling capabilities
func NewJSONSugared ¶
func NewJSONSugared(out io.Writer, level Level) *SugaredLogger
NewJSONSugared create new SugaredLogger with JSONFormatter
func NewSugaredLogger ¶
func NewSugaredLogger(output io.Writer, level Level) *SugaredLogger
NewSugaredLogger create new SugaredLogger
func (*SugaredLogger) Configure ¶
func (sl *SugaredLogger) Configure(fn func(sl *SugaredLogger)) *SugaredLogger
Configure current logger
func (*SugaredLogger) Flush ¶
func (sl *SugaredLogger) Flush() error
FlushAll all logs. alias of the FlushAll()
func (*SugaredLogger) Handle ¶
func (sl *SugaredLogger) Handle(record *Record) error
Handle log record
func (*SugaredLogger) IsHandling ¶
func (sl *SugaredLogger) IsHandling(level Level) bool
IsHandling Check if the current level can be handling
type TextFormatter ¶
type TextFormatter struct { // Template text template for render output log messages Template string // TimeFormat the time format layout. default is time.RFC3339 TimeFormat string // Enable color on print log to terminal EnableColor bool // ColorTheme setting on render color on terminal ColorTheme map[Level]color.Color // FullDisplay Whether to display when record.Data, record.Extra, etc. are empty FullDisplay bool // EncodeFunc data encode for Record.Data, Record.Extra, etc. // Default is encode by `fmt.Sprint()` EncodeFunc func(v interface{}) string // contains filtered or unexported fields }
TextFormatter definition
func NewTextFormatter ¶
func NewTextFormatter(template ...string) *TextFormatter
NewTextFormatter create new TextFormatter
func (*TextFormatter) FieldMap ¶
func (f *TextFormatter) FieldMap() StringMap
FieldMap get export field map
func (*TextFormatter) Format ¶
func (f *TextFormatter) Format(r *Record) ([]byte, error)
Format an log record
func (*TextFormatter) SetTemplate ¶
func (f *TextFormatter) SetTemplate(fmtTpl string)
SetTemplate set the log format template and update field-map