Documentation ¶
Index ¶
- Constants
- Variables
- func DeferExitHandler(handler func())
- func Exit(code int)
- func RegisterExitHandler(handler func())
- func SetBufferPool(bp BufferPool)
- type BufferPool
- type DefaultBufferPool
- type DefaultFormatter
- type Entry
- func (entry *Entry) Bytes() ([]byte, error)
- func (entry *Entry) Debug(args ...interface{})
- func (entry *Entry) Debugf(format string, args ...interface{})
- func (entry *Entry) Debugln(args ...interface{})
- func (entry *Entry) Dup() *Entry
- func (entry *Entry) Error(args ...interface{})
- func (entry *Entry) Errorf(format string, args ...interface{})
- func (entry *Entry) Errorln(args ...interface{})
- func (entry *Entry) Fatal(args ...interface{})
- func (entry *Entry) Fatalf(format string, args ...interface{})
- func (entry *Entry) Fatalln(args ...interface{})
- func (entry *Entry) HasCaller() bool
- func (entry *Entry) Info(args ...interface{})
- func (entry *Entry) Infof(format string, args ...interface{})
- func (entry *Entry) Infoln(args ...interface{})
- func (entry *Entry) Log(level Level, args ...interface{})
- func (entry *Entry) Logf(level Level, format string, args ...interface{})
- func (entry *Entry) Logln(level Level, args ...interface{})
- func (entry *Entry) Panic(args ...interface{})
- func (entry *Entry) Panicf(format string, args ...interface{})
- func (entry *Entry) Panicln(args ...interface{})
- func (entry *Entry) Print(args ...interface{})
- func (entry *Entry) Printf(format string, args ...interface{})
- func (entry *Entry) Println(args ...interface{})
- func (entry *Entry) String() (string, error)
- func (entry *Entry) Trace(args ...interface{})
- func (entry *Entry) Tracef(format string, args ...interface{})
- func (entry *Entry) Traceln(args ...interface{})
- func (entry *Entry) Warn(args ...interface{})
- func (entry *Entry) Warnf(format string, args ...interface{})
- func (entry *Entry) Warning(args ...interface{})
- func (entry *Entry) Warningf(format string, args ...interface{})
- func (entry *Entry) Warningln(args ...interface{})
- func (entry *Entry) Warnln(args ...interface{})
- func (entry *Entry) WithContext(context context.Context) *Entry
- func (entry *Entry) WithError(err error) *Entry
- func (entry *Entry) WithField(key string, value interface{}) *Entry
- func (entry *Entry) WithFields(fields Fields) *Entry
- func (entry *Entry) WithTime(time time.Time) *Entry
- type ExitFunc
- type FieldLogger
- type FieldMap
- type Fields
- type Formatter
- type Hook
- type JSONFormatter
- type Level
- type LevelHook
- type LogFunction
- type Logger
- func (logger *Logger) AddHook(hook Hook)
- func (logger *Logger) AddHooks(hooks ...Hook)
- func (logger *Logger) AddHooksWithSlice(hooks []Hook)
- func (logger *Logger) Debug(args ...interface{})
- func (logger *Logger) DebugFn(fn LogFunction)
- func (logger *Logger) Debugf(format string, args ...interface{})
- func (logger *Logger) Debugln(args ...interface{})
- func (logger *Logger) Error(args ...interface{})
- func (logger *Logger) ErrorFn(fn LogFunction)
- func (logger *Logger) Errorf(format string, args ...interface{})
- func (logger *Logger) Errorln(args ...interface{})
- func (logger *Logger) Exit(code int)
- func (logger *Logger) Fatal(args ...interface{})
- func (logger *Logger) FatalFn(fn LogFunction)
- func (logger *Logger) Fatalf(format string, args ...interface{})
- func (logger *Logger) Fatalln(args ...interface{})
- func (logger *Logger) Info(args ...interface{})
- func (logger *Logger) InfoFn(fn LogFunction)
- func (logger *Logger) Infof(format string, args ...interface{})
- func (logger *Logger) Infoln(args ...interface{})
- func (logger *Logger) IsLevelEnable(level Level) bool
- func (logger *Logger) LoadLoggerLevel() Level
- func (logger *Logger) Log(level Level, args ...interface{})
- func (logger *Logger) LogFn(level Level, fn LogFunction)
- func (logger *Logger) Logf(level Level, format string, args ...interface{})
- func (logger *Logger) Logln(level Level, args ...interface{})
- func (logger *Logger) NewEntry() *Entry
- func (logger *Logger) Panic(args ...interface{})
- func (logger *Logger) PanicFn(fn LogFunction)
- func (logger *Logger) Panicf(format string, args ...interface{})
- func (logger *Logger) Panicln(args ...interface{})
- func (logger *Logger) Print(args ...interface{})
- func (logger *Logger) PrintFn(fn LogFunction)
- func (logger *Logger) Printf(format string, args ...interface{})
- func (logger *Logger) Println(args ...interface{})
- func (logger *Logger) ReplaceHooks(hooks LevelHook)
- func (logger *Logger) SetBufferPool(bp BufferPool)
- func (logger *Logger) SetFormatter(formatter Formatter)
- func (logger *Logger) SetLoggerLevel(level Level)
- func (logger *Logger) SetNoLock()
- func (logger *Logger) SetOutPut(out io.Writer)
- func (logger *Logger) SetReportCaller(reportCaller bool)
- func (logger *Logger) Trace(args ...interface{})
- func (logger *Logger) TraceFn(fn LogFunction)
- func (logger *Logger) Tracef(format string, args ...interface{})
- func (logger *Logger) Traceln(args ...interface{})
- func (logger *Logger) Warn(args ...interface{})
- func (logger *Logger) WarnFn(fn LogFunction)
- func (logger *Logger) Warnf(format string, args ...interface{})
- func (logger *Logger) Warning(args ...interface{})
- func (logger *Logger) WarningFn(fn LogFunction)
- func (logger *Logger) Warningf(format string, args ...interface{})
- func (logger *Logger) Warningln(args ...interface{})
- func (logger *Logger) Warnln(args ...interface{})
- func (logger *Logger) WithContext(context context.Context) *Entry
- func (logger *Logger) WithError(err error) *Entry
- func (logger *Logger) WithField(key string, value interface{}) *Entry
- func (logger *Logger) WithFields(fields Fields) *Entry
- func (logger *Logger) WithTime(time time.Time) *Entry
- type Mutex
- type MutexWrap
- type StdLogger
Constants ¶
const ( FieldKeyMsg = "msg" FieldKeyLevel = "level" FieldKeyTime = "time" FieldKeyLogrusError = "logrus_error" FieldKeyFunc = "func" FieldKeyFile = "file" )
Variables ¶
var AllLevels = []Level{ PanicLevel, FatalLevel, ErrorLevel, WarnLevel, InfoLevel, DebugLevel, TraceLevel, }
var (
ErrorKey = "error"
)
Functions ¶
func DeferExitHandler ¶
func DeferExitHandler(handler func())
DeferExitHandler prepends a Logrus Exit handler to the list of handlers, call logrus.Exit to invoke all handlers. The handlers will also be invoked when any Fatal log entry is made.
This method is useful when a caller wishes to use logrus to log a fatal message but also needs to gracefully shutdown. An example usecase could be closing database connections, or sending a alert that the application is closing.
func Exit ¶
func Exit(code int)
Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code)
func RegisterExitHandler ¶
func RegisterExitHandler(handler func())
RegisterExitHandler appends a Logrus Exit handler to the list of handlers, call logrus.Exit to invoke all handlers. The handlers will also be invoked when any Fatal log entry is made.
This method is useful when a caller wishes to use logrus to log a fatal message but also needs to gracefully shutdown. An example usecase could be closing database connections, or sending a alert that the application is closing.
func SetBufferPool ¶
func SetBufferPool(bp BufferPool)
Types ¶
type BufferPool ¶
type DefaultBufferPool ¶
type DefaultFormatter ¶
type DefaultFormatter struct { }
func (*DefaultFormatter) Format ¶
func (df *DefaultFormatter) Format(entry *Entry)
type Entry ¶
type Entry struct { Logger *Logger Data Fields Time time.Time Level Level // 栈帧 Caller *runtime.Frame // 用于简单输出 Message string // 用于格式化输出 Buffer *bytes.Buffer Context context.Context // contains filtered or unexported fields }
func (*Entry) WithContext ¶
// 用于简单输出 Message string // 用于格式化输出 Buffer *bytes.Buffer Context context.Context err string
func (*Entry) WithFields ¶
type FieldLogger ¶
type FieldLogger interface { WithField(key string, value interface{}) *Entry WithFields(fields Fields) *Entry WithError(err error) *Entry Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Printf(format string, args ...interface{}) Warnf(format string, args ...interface{}) Warningf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) Panicf(format string, args ...interface{}) Debug(args ...interface{}) Info(args ...interface{}) Print(args ...interface{}) Warn(args ...interface{}) Warning(args ...interface{}) Error(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) Debugln(args ...interface{}) Infoln(args ...interface{}) Println(args ...interface{}) Warnln(args ...interface{}) Warningln(args ...interface{}) Errorln(args ...interface{}) Fatalln(args ...interface{}) Panicln(args ...interface{}) }
type FieldMap ¶
type FieldMap map[fieldKey]string
FieldMap allows customization of the key names for default fields.
type JSONFormatter ¶
type JSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. // The format to use is the same than for time.Format or time.Parse from the standard // library. // The standard Library already provides a set of predefined format. TimestampFormat string // DisableTimestamp allows disabling automatic timestamps in output DisableTimestamp bool // DisableHTMLEscape allows disabling html escaping in output DisableHTMLEscape bool // DataKey allows users to put all the log entry parameters into a nested dictionary at a given key. DataKey string // FieldMap allows users to customize the names of keys for default fields. // As an example: // formatter := &JSONFormatter{ // FieldMap: FieldMap{ // FieldKeyTime: "@timestamp", // FieldKeyLevel: "@level", // FieldKeyMsg: "@message", // FieldKeyFunc: "@caller", // }, // } FieldMap FieldMap // CallerPrettyfier can be set by the user to modify the content // of the function and file keys in the json data when ReportCaller is // activated. If any of the returned value is the empty string the // corresponding key will be removed from json fields. CallerPrettyfier func(*runtime.Frame) (function string, file string) // PrettyPrint will indent all json logs PrettyPrint bool }
JSONFormatter formats logs into parsable json
type Level ¶
type Level uint32
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel Level = iota // FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
func (Level) MarshalText ¶
type LogFunction ¶
type LogFunction func() []interface{}
type Logger ¶
type Logger struct { // 输出地址 Out io.Writer Hooks LevelHook Formatter Formatter // 是否上报调用者 ReportCaller bool // 当前日志登记,过滤作用 Level Level ExitFunc ExitFunc BufferPool BufferPool // contains filtered or unexported fields }
func (*Logger) AddHooksWithSlice ¶
func (*Logger) DebugFn ¶
func (logger *Logger) DebugFn(fn LogFunction)
func (*Logger) ErrorFn ¶
func (logger *Logger) ErrorFn(fn LogFunction)
func (*Logger) FatalFn ¶
func (logger *Logger) FatalFn(fn LogFunction)
func (*Logger) InfoFn ¶
func (logger *Logger) InfoFn(fn LogFunction)
func (*Logger) IsLevelEnable ¶
func (*Logger) LoadLoggerLevel ¶
func (*Logger) LogFn ¶
func (logger *Logger) LogFn(level Level, fn LogFunction)
func (*Logger) PanicFn ¶
func (logger *Logger) PanicFn(fn LogFunction)
func (*Logger) PrintFn ¶
func (logger *Logger) PrintFn(fn LogFunction)
func (*Logger) ReplaceHooks ¶
func (*Logger) SetBufferPool ¶
func (logger *Logger) SetBufferPool(bp BufferPool)
func (*Logger) SetFormatter ¶
func (*Logger) SetLoggerLevel ¶
func (*Logger) SetReportCaller ¶
func (*Logger) TraceFn ¶
func (logger *Logger) TraceFn(fn LogFunction)
func (*Logger) WarnFn ¶
func (logger *Logger) WarnFn(fn LogFunction)
func (*Logger) WarningFn ¶
func (logger *Logger) WarningFn(fn LogFunction)
func (*Logger) WithFields ¶
type StdLogger ¶
type StdLogger interface { Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) Fatalln(...interface{}) Panic(...interface{}) Panicf(string, ...interface{}) Panicln(...interface{}) }
简单定义一下自己的StdLogger接口类型 只要和打印相关的basic功能