Documentation ¶
Index ¶
- Variables
- func Close()
- func Debug(args ...interface{})
- func DebugF(format string, args ...interface{})
- func DeferExitHandler(handler func())
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Exit(code int)
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Panic(args ...interface{})
- func RegisterExitHandler(handler func())
- func Reset(transports ...EntryTransporter)
- func SetLevel(level Level)
- func SetPrefix(prefix string)
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- type Builder
- type Complex
- type Entry
- type EntryBuilder
- func (builder *EntryBuilder) Log(level Level, args ...interface{})
- func (builder *EntryBuilder) Logf(level Level, format string, args ...interface{})
- func (builder *EntryBuilder) Logln(level Level, args ...interface{})
- func (builder *EntryBuilder) WithError(err error) Builder
- func (builder *EntryBuilder) WithField(key string, value interface{}) Builder
- func (builder *EntryBuilder) WithFields(fields Fields) Builder
- type EntryTransporter
- type Factory
- type Fields
- type Formatter
- type Level
- type LineFormatter
- type Logger
- func (logger *Logger) Debug(args ...interface{})
- func (logger *Logger) Debugf(format string, args ...interface{})
- func (logger *Logger) Debugln(args ...interface{})
- func (logger *Logger) Error(args ...interface{})
- 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) Fatalf(format string, args ...interface{})
- func (logger *Logger) Fatalln(args ...interface{})
- func (logger *Logger) GetLevel() Level
- func (logger *Logger) Info(args ...interface{})
- func (logger *Logger) Infof(format string, args ...interface{})
- func (logger *Logger) Infoln(args ...interface{})
- func (logger *Logger) IsLevelEnabled(level Level) bool
- func (logger *Logger) Log(level Level, args ...interface{})
- func (logger *Logger) Logf(level Level, format string, args ...interface{})
- func (logger *Logger) Logln(level Level, args ...interface{})
- func (logger *Logger) Panic(args ...interface{})
- func (logger *Logger) Panicf(format string, args ...interface{})
- func (logger *Logger) Panicln(args ...interface{})
- func (logger *Logger) SetPrefix(prefix string)
- func (logger *Logger) SetTransporter(transporter EntryTransporter)
- func (logger *Logger) Trace(args ...interface{})
- func (logger *Logger) Tracef(format string, args ...interface{})
- func (logger *Logger) Traceln(args ...interface{})
- func (logger *Logger) Transport(entry *Entry) (err error)
- func (logger *Logger) Warn(args ...interface{})
- func (logger *Logger) Warnf(format string, args ...interface{})
- func (logger *Logger) Warning(args ...interface{})
- func (logger *Logger) Warningf(format string, args ...interface{})
- func (logger *Logger) Warningln(args ...interface{})
- func (logger *Logger) Warnln(args ...interface{})
- func (logger *Logger) WithError(err error) Builder
- func (logger *Logger) WithField(key string, value interface{}) Builder
- func (logger *Logger) WithFields(fields Fields) Builder
- type Transporter
- func (t *Transporter) Close() error
- func (t *Transporter) Level() Level
- func (t *Transporter) Output() io.Writer
- func (t *Transporter) SetFormatter(formatter Formatter)
- func (t *Transporter) SetLevel(level Level)
- func (t *Transporter) SetOutput(output io.Writer)
- func (t *Transporter) Transport(entry *Entry) error
Constants ¶
This section is empty.
Variables ¶
var AllLevels = []Level{ PanicLevel, FatalLevel, ErrorLevel, WarnLevel, InfoLevel, DebugLevel, TraceLevel, }
A constant exposing all logging levels
var ErrorKey = "error"
Defines the key when adding errors using WithError.
Functions ¶
func Debug ¶
func Debug(args ...interface{})
Debug logs a message at level Debug on the standard logger.
func DebugF ¶
func DebugF(format string, args ...interface{})
Debug logs a message at level Debug on the standard logger.
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 Error ¶
func Error(args ...interface{})
Error logs a message at level Error on the standard logger.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a message at level Error on the standard logger.
func Exit ¶
func Exit(code int)
Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code)
func Fatal ¶
func Fatal(args ...interface{})
Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
func Info ¶
func Info(args ...interface{})
Info logs a message at level Info on the standard logger.
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a message at level Info on the standard logger.
func Panic ¶
func Panic(args ...interface{})
Panic logs a message at level Panic on the standard logger.
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 Reset ¶
func Reset(transports ...EntryTransporter)
Types ¶
type Builder ¶
type Complex ¶
type Complex struct {
// contains filtered or unexported fields
}
func NewComplex ¶
func NewComplex(transports ...EntryTransporter) *Complex
func (*Complex) Reset ¶
func (c *Complex) Reset(transporters ...EntryTransporter) error
type Entry ¶
type Entry struct { // Contains all the fields set by the user. Data Fields // Time at which the log entry was created Time time.Time // Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic // This field will be set on entry firing and the value will be equal to the one in _Logger struct field. Level Level // Calling method, with package name Caller *runtime.Frame // Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic Message string Err string }
An entry is the final or intermediate Logrus logging entry. It contains all the fields passed with WithField{,s}. It's finally logged when Trace, Debug, Info, Warn, Error, Fatal or Panic is called on it. These objects can be reused and passed around as much as you wish to avoid field duplication.
type EntryBuilder ¶
type EntryBuilder struct { // Contains all the fields set by the user. Data Fields // Time at which the log entry was created Time time.Time // contains filtered or unexported fields }
func (*EntryBuilder) Log ¶
func (builder *EntryBuilder) Log(level Level, args ...interface{})
func (*EntryBuilder) Logf ¶
func (builder *EntryBuilder) Logf(level Level, format string, args ...interface{})
func (*EntryBuilder) Logln ¶
func (builder *EntryBuilder) Logln(level Level, args ...interface{})
func (*EntryBuilder) WithError ¶
func (builder *EntryBuilder) WithError(err error) Builder
Add an error as single field (using the key defined in ErrorKey) to the Entry.
func (*EntryBuilder) WithField ¶
func (builder *EntryBuilder) WithField(key string, value interface{}) Builder
Add a single field to the Entry.
func (*EntryBuilder) WithFields ¶
func (builder *EntryBuilder) WithFields(fields Fields) Builder
Add a map of fields to the Entry.
type EntryTransporter ¶
type Formatter ¶
The Formatter interface is used to implement a custom Formatter. It takes an `Entry`. It exposes all the fields, including the default ones:
* `entry.Data["msg"]`. The message passed from Info, Warn, Error .. * `entry.Data["time"]`. The timestamp. * `entry.Data["level"]. The level the entry was logged at.
Any additional fields added with `WithField` or `WithFields` are also in `entry.Data`. Format is expected to return an array of bytes which are then logged to `logger.Out`.
type Level ¶
type Level uint32
Level type
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 )
These are the different logging levels. You can set the logging level to log on your instance of logger, obtained with `logrus.Start()`.
func ParseLevel ¶
ParseLevel takes a string level and returns the Logrus log level constant.
func (Level) MarshalText ¶
func (*Level) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type LineFormatter ¶
type LineFormatter struct { TimestampFormat string CallerPrettyfier func(*runtime.Frame) (function string, file string) }
LineFormatter 格式化
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLogger ¶
func NewLogger(transporter EntryTransporter, reportCaller bool, packageName string) *Logger
func (*Logger) IsLevelEnabled ¶
IsLevelEnabled checks if the log level of the logger is greater than the level param
func (*Logger) SetTransporter ¶
func (logger *Logger) SetTransporter(transporter EntryTransporter)
func (*Logger) WithFields ¶
type Transporter ¶
type Transporter struct {
// contains filtered or unexported fields
}
func NewTransport ¶
func NewTransport(out io.Writer, level Level) *Transporter
func (*Transporter) Close ¶
func (t *Transporter) Close() error
func (*Transporter) Level ¶
func (t *Transporter) Level() Level
func (*Transporter) Output ¶
func (t *Transporter) Output() io.Writer
func (*Transporter) SetFormatter ¶
func (t *Transporter) SetFormatter(formatter Formatter)
func (*Transporter) SetLevel ¶
func (t *Transporter) SetLevel(level Level)
SetLevel sets the logger level.
func (*Transporter) SetOutput ¶
func (t *Transporter) SetOutput(output io.Writer)
func (*Transporter) Transport ¶
func (t *Transporter) Transport(entry *Entry) error