Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(args ...interface{})
- func Debugf(template string, args ...interface{})
- func Error(args ...interface{})
- func Errorf(template string, args ...interface{})
- func ExitHook(_ int)
- func Fatal(args ...interface{})
- func Fatalf(template string, args ...interface{})
- func GetCallerFrame(callerSkip int) *runtime.Frame
- func Info(args ...interface{})
- func Infof(template string, args ...interface{})
- func InitLog(opts ...OptionFunc) error
- func Panic(args ...interface{})
- func Panicf(template string, args ...interface{})
- func Print(args ...interface{})
- func Printf(template string, args ...interface{})
- func SetLogger(g ILogger)
- func Stop()
- func Warn(args ...interface{})
- func Warnf(template string, args ...interface{})
- type BaseFormatterConfig
- type ChannelEngine
- type Config
- type FileHandlerConfig
- type FormatterConfig
- type HandlerConfig
- type IEngine
- type ILogger
- type JSONFormatterConfig
- type Level
- type Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(template string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(template string, args ...interface{})
- func (l *Logger) Fatal(args ...interface{})
- func (l *Logger) Fatalf(template string, args ...interface{})
- func (l *Logger) Fatalln(args ...interface{})
- func (l *Logger) GetLevel() Level
- func (l *Logger) GetLoggerName() string
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(template string, args ...interface{})
- func (l *Logger) Panic(args ...interface{})
- func (l *Logger) Panicf(template string, args ...interface{})
- func (l *Logger) Panicln(args ...interface{})
- func (l *Logger) Print(args ...interface{})
- func (l *Logger) Printf(template string, args ...interface{})
- func (l *Logger) Println(args ...interface{})
- func (l *Logger) SetLevel(lvl Level)
- func (l *Logger) SetLoggerName(name string)
- func (l *Logger) Stop() error
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(template string, args ...interface{})
- type OptionFunc
- func SetColorRender(enable bool) OptionFunc
- func SetExitFunc(fn func(code int)) OptionFunc
- func SetLoggerLevel(lvl Level) OptionFunc
- func SetLoggerName(name string) OptionFunc
- func SetOnError(fn func(v interface{}, err error)) OptionFunc
- func SetRecordCaller(skip int) OptionFunc
- func SetThrowOnLevel(lvl Level) OptionFunc
- func SetTimeLayout(layout string) OptionFunc
- func SetTraceIDFunc(fn func(entry *message.Entry) string) OptionFunc
- func SetWorkerConfigs(list ...*WorkerConfig) OptionFunc
- type RotatorType
- type StdLogger
- type StreamHandlerConfig
- type SyslogHandlerConfig
- type TextFormatterConfig
- type Worker
- type WorkerConfig
- func (w *WorkerConfig) SetCacheSize(size int) *WorkerConfig
- func (w *WorkerConfig) SetFileHandlerConfig(c *FileHandlerConfig) *WorkerConfig
- func (w *WorkerConfig) SetFilter(f filter.IFilter) *WorkerConfig
- func (w *WorkerConfig) SetFormatter(f formatter.IFormatter) *WorkerConfig
- func (w *WorkerConfig) SetHandler(h handler.IHandler) *WorkerConfig
- func (w *WorkerConfig) SetJSONFormatterConfig(c *JSONFormatterConfig) *WorkerConfig
- func (w *WorkerConfig) SetLevel(lvl Level) *WorkerConfig
- func (w *WorkerConfig) SetStreamHandlerConfig(c *StreamHandlerConfig) *WorkerConfig
- func (w *WorkerConfig) SetSyslogHandlerConfig(c *SyslogHandlerConfig) *WorkerConfig
- func (w *WorkerConfig) SetTextFormatterConfig(c *TextFormatterConfig) *WorkerConfig
- func (w *WorkerConfig) SetXMLFormatterConfig(c *XMLFormatterConfig) *WorkerConfig
- type XMLFormatterConfig
Constants ¶
View Source
const ( PatternTemplateWithDefault = "%[LoggerName]s (%[Pid]d,%[RoutineId]d) %[DateTime]s %[LevelName]s %[ShortCaller]s %[Message]v" PatternTemplateWithSimple = "%[LevelName]s %[DateTime]s %[ShortCaller]s %[Message]v" PatternTemplateWithTrace = "<%[TradeId]s> %[LoggerName]s (%[Pid]d,%[RoutineId]d) %[DateTime]s %[LevelName]s %[ShortCaller]s %[Message]v" )
View Source
const ( FileRotatorSuffixFmt1 = "20060102150405" FileRotatorSuffixFmt2 = "2006-01-02T15-04-05" FileRotatorSuffixFmt3 = "2006-01-02_15-04-05" )
View Source
const ( FileRotatorReMatch1 = "^\\d{14}(\\.\\w+)?$" FileRotatorReMatch2 = "^\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}(\\.\\w+)?$" FileRotatorReMatch3 = "^\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}(\\.\\w+)?$" )
View Source
const (
DefaultDateTimeFormat = "01-02T15:04:05.000000" // microsecond
)
Variables ¶
View Source
var (
Conf = NewDefaultConfig()
)
Functions ¶
func GetCallerFrame ¶ added in v0.4.4
func InitLog ¶
func InitLog(opts ...OptionFunc) error
Types ¶
type BaseFormatterConfig ¶ added in v0.4.0
type BaseFormatterConfig = formatter.BaseFormatterConfig
func NewDefaultBaseFormatterConfig ¶ added in v0.4.1
func NewDefaultBaseFormatterConfig() BaseFormatterConfig
type ChannelEngine ¶ added in v0.4.0
type ChannelEngine struct {
// contains filtered or unexported fields
}
func NewChannelEngine ¶ added in v0.4.0
func NewChannelEngine(cfg *Config) (*ChannelEngine, error)
func (*ChannelEngine) Send ¶ added in v0.4.0
func (e *ChannelEngine) Send(entry *message.Entry)
func (*ChannelEngine) Start ¶ added in v0.4.0
func (e *ChannelEngine) Start() error
func (*ChannelEngine) Stop ¶ added in v0.4.0
func (e *ChannelEngine) Stop() (err error)
type Config ¶
type Config struct {
// Set the name of the Logger. If not set, the default is `glog`.
LoggerName string
// Set the global log level. Logs below this level will not be processed.
// If not set, the default is `Info Level`.
LoggerLevel Level
// What level of logging is set here will trigger an exception to be thrown.
// If this value is set, an exception will be thrown when an error of this level occurs.
// You can only choose three levels: `FatalLevel`, `PanicLevel`, and `NoneLevel`.
// The default setting is `NoneLevel`, which will not throw an exception.
// For example, if it is set to FatalLevel, an exception will be thrown
// when a FatalLevel error occurs.
ThrowOnLevel Level
// Enable recording of caller information
EnableRecordCaller bool
CallerSkipCount int
// enable color rendering. Only enabled by default in the text formatter.
EnableColorRender *bool
// time layout string, for example: "2006-01-02 15:04:05.000"
TimeLayout string
// For log processing configuration, multiple Worker coroutines can be set,
// and each Worker can set different cache sizes, log levels, formatting
// methods, filters, and output methods.
// Output currently defines multiple modes, such as console, file, network, etc.
// If not set, the default is a Worker, the cache size is 1000, the log level
// is `Info Level`, and the output mode is the console.
// Of course, if there is no suitable output method, you can customize the Handler.
WorkerConfigList []*WorkerConfig
// When ThrowOnLevel is set, if a ThrowOnLevel error occurs, this function
// will be called before exiting. The default is `os.Exit()`.
ExitFunc func(code int)
// If an unexpected error occurs in asynchronous logic, you can use this
// callback function to handle the error, such as saving it to other places
// or alerting notifications, etc. The default is to print to stderr.
OnError func(v interface{}, err error)
// Link tracking solutions are often used in microservices, where the
// tracking ID is the core of the entire call link. Customize this
// function to return the Trace ID, and then record it in the log.
TraceIDFunc func(entry *message.Entry) string
}
func NewDefaultConfig ¶ added in v0.4.0
func NewDefaultConfig() *Config
type FileHandlerConfig ¶ added in v0.4.0
type FileHandlerConfig = handler.FileHandlerConfig
func NewDefaultFileHandlerConfig ¶ added in v0.4.1
func NewDefaultFileHandlerConfig(dir string) *FileHandlerConfig
type FormatterConfig ¶ added in v0.4.0
type FormatterConfig struct {
Text *TextFormatterConfig
JSON *JSONFormatterConfig
XML *XMLFormatterConfig
}
type HandlerConfig ¶ added in v0.4.0
type HandlerConfig struct {
File *FileHandlerConfig
Stream *StreamHandlerConfig
Syslog *SyslogHandlerConfig
}
type ILogger ¶
type ILogger interface {
GetLoggerName() string
SetLoggerName(string)
GetLevel() Level
SetLevel(Level)
Debug(...interface{})
Info(...interface{})
Warn(...interface{})
Error(...interface{})
Print(...interface{})
Fatal(...interface{})
Panic(...interface{})
Debugf(template string, args ...interface{})
Infof(template string, args ...interface{})
Warnf(template string, args ...interface{})
Errorf(template string, args ...interface{})
Printf(template string, args ...interface{})
Fatalf(template string, args ...interface{})
Panicf(template string, args ...interface{})
Stop() error
}
type JSONFormatterConfig ¶ added in v0.4.0
type JSONFormatterConfig = formatter.JSONFormatterConfig
func NewDefaultJSONFormatterConfig ¶ added in v0.4.1
func NewDefaultJSONFormatterConfig() *JSONFormatterConfig
type Logger ¶
type Logger struct {
Name string
Level Level
ThrowOnLevel Level
ExitFunc func(code int) // Function to exit the application, defaults to `os.Exit()`
TraceIDFunc func(entry *message.Entry) string
// contains filtered or unexported fields
}
func (*Logger) GetLoggerName ¶ added in v0.2.12
func (*Logger) SetLoggerName ¶ added in v0.2.12
type OptionFunc ¶ added in v0.4.0
type OptionFunc func(config *Config)
func SetColorRender ¶ added in v0.4.3
func SetColorRender(enable bool) OptionFunc
SetColorRender enable color rendering. Only enabled by default in the text formatter.
func SetExitFunc ¶ added in v0.4.0
func SetExitFunc(fn func(code int)) OptionFunc
func SetLoggerLevel ¶ added in v0.4.0
func SetLoggerLevel(lvl Level) OptionFunc
SetLoggerLevel Set the global log level. Logs below this level will not be processed.
func SetLoggerName ¶ added in v0.4.0
func SetLoggerName(name string) OptionFunc
SetLoggerName Set the name of the logger, the default is the name of the program.
func SetOnError ¶ added in v0.4.0
func SetOnError(fn func(v interface{}, err error)) OptionFunc
func SetRecordCaller ¶ added in v0.4.5
func SetRecordCaller(skip int) OptionFunc
SetRecordCaller Enable recording of caller information
func SetThrowOnLevel ¶ added in v0.4.0
func SetThrowOnLevel(lvl Level) OptionFunc
SetThrowOnLevel what level of logging is set here will trigger an exception to be thrown.
func SetTimeLayout ¶ added in v0.4.3
func SetTimeLayout(layout string) OptionFunc
SetTimeLayout time layout string, for example: "2006-01-02 15:04:05.000"
func SetTraceIDFunc ¶ added in v0.4.0
func SetTraceIDFunc(fn func(entry *message.Entry) string) OptionFunc
func SetWorkerConfigs ¶ added in v0.4.0
func SetWorkerConfigs(list ...*WorkerConfig) OptionFunc
type RotatorType ¶ added in v0.4.0
type RotatorType = handler.RotatorType
const ( FileRotatorTypeTime RotatorType = 1 FileRotatorTypeSize RotatorType = 2 FileRotatorTypeTimeAndSize RotatorType = 3 )
type StreamHandlerConfig ¶ added in v0.4.0
type StreamHandlerConfig = handler.StreamHandlerConfig
type SyslogHandlerConfig ¶ added in v0.4.0
type SyslogHandlerConfig = handler.SyslogHandlerConfig
type TextFormatterConfig ¶ added in v0.4.0
type TextFormatterConfig = formatter.TextFormatterConfig
func NewDefaultTextFormatterConfig ¶ added in v0.4.1
func NewDefaultTextFormatterConfig() *TextFormatterConfig
type WorkerConfig ¶ added in v0.4.0
type WorkerConfig struct {
CacheSize int
Level Level
HandlerCfg HandlerConfig
FormatterCfg FormatterConfig
CustomHandler handler.IHandler
CustomFilter filter.IFilter
CustomFormatter formatter.IFormatter
}
func NewDefaultJsonFileWorkerConfig ¶ added in v0.4.1
func NewDefaultJsonFileWorkerConfig(dir string) *WorkerConfig
func NewDefaultStdoutWorkerConfig ¶ added in v0.4.1
func NewDefaultStdoutWorkerConfig() *WorkerConfig
func NewDefaultTextFileWorkerConfig ¶ added in v0.4.1
func NewDefaultTextFileWorkerConfig(dir string) *WorkerConfig
func NewWorkerConfig ¶ added in v0.4.0
func NewWorkerConfig(level Level, size int) *WorkerConfig
func (*WorkerConfig) SetCacheSize ¶ added in v0.4.2
func (w *WorkerConfig) SetCacheSize(size int) *WorkerConfig
func (*WorkerConfig) SetFileHandlerConfig ¶ added in v0.4.0
func (w *WorkerConfig) SetFileHandlerConfig(c *FileHandlerConfig) *WorkerConfig
func (*WorkerConfig) SetFilter ¶ added in v0.4.0
func (w *WorkerConfig) SetFilter(f filter.IFilter) *WorkerConfig
func (*WorkerConfig) SetFormatter ¶ added in v0.4.0
func (w *WorkerConfig) SetFormatter(f formatter.IFormatter) *WorkerConfig
func (*WorkerConfig) SetHandler ¶ added in v0.4.0
func (w *WorkerConfig) SetHandler(h handler.IHandler) *WorkerConfig
func (*WorkerConfig) SetJSONFormatterConfig ¶ added in v0.4.0
func (w *WorkerConfig) SetJSONFormatterConfig(c *JSONFormatterConfig) *WorkerConfig
func (*WorkerConfig) SetLevel ¶ added in v0.4.2
func (w *WorkerConfig) SetLevel(lvl Level) *WorkerConfig
func (*WorkerConfig) SetStreamHandlerConfig ¶ added in v0.4.0
func (w *WorkerConfig) SetStreamHandlerConfig(c *StreamHandlerConfig) *WorkerConfig
func (*WorkerConfig) SetSyslogHandlerConfig ¶ added in v0.4.0
func (w *WorkerConfig) SetSyslogHandlerConfig(c *SyslogHandlerConfig) *WorkerConfig
func (*WorkerConfig) SetTextFormatterConfig ¶ added in v0.4.0
func (w *WorkerConfig) SetTextFormatterConfig(c *TextFormatterConfig) *WorkerConfig
func (*WorkerConfig) SetXMLFormatterConfig ¶ added in v0.4.0
func (w *WorkerConfig) SetXMLFormatterConfig(c *XMLFormatterConfig) *WorkerConfig
type XMLFormatterConfig ¶ added in v0.4.0
type XMLFormatterConfig = formatter.XMLFormatterConfig
Click to show internal directories.
Click to hide internal directories.
