Documentation
¶
Overview ¶
Package log is is imported from https://github.com/sirupsen/logrus
Index ¶
- Constants
- Variables
- func Debugf(format string, args ...interface{})
- func Errorf(format string, args ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalln(args ...interface{})
- func Infof(format string, args ...interface{})
- func IsLevelEnabled(level Level) bool
- func NewClientLogFile() (io.WriteCloser, error)
- func Panic(args ...interface{})
- func Panicf(format string, args ...interface{})
- func Panicln(args ...interface{})
- func Print(args ...interface{})
- func Printf(format string, args ...interface{})
- func Println(args ...interface{})
- func RemoveOldClientLogFiles() error
- func SetBufferPool(bp BufferPool)
- func SetFormatter(formatter Formatter)
- func SetLevel(level string)
- func SetOutput(out io.Writer)
- func SetOutputToTest(t *testing.T)
- func SetReportCaller(include bool)
- func Tracef(format string, args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warningf(format string, args ...interface{})
- type BufferPool
- type CliFormatter
- type DaemonFormatter
- type Entry
- func (entry *Entry) Bytes() ([]byte, error)
- func (entry *Entry) Debugf(format string, args ...interface{})
- func (entry *Entry) Dup() *Entry
- func (entry *Entry) Errorf(format string, 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() (has bool)
- func (entry *Entry) Infof(format string, 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) Tracef(format string, args ...interface{})
- func (entry *Entry) Warnf(format string, args ...interface{})
- func (entry *Entry) Warningf(format string, args ...interface{})
- func (entry *Entry) WithContext(ctx 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(t time.Time) *Entry
- type FieldLogger
- type Fields
- type Formatter
- type Level
- type LogFunction
- type Logger
- func (logger *Logger) Debugf(format string, args ...interface{})
- func (logger *Logger) Errorf(format string, 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) Infof(format string, 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) Print(args ...interface{})
- func (logger *Logger) Printf(format string, args ...interface{})
- func (logger *Logger) Println(args ...interface{})
- func (logger *Logger) SetBufferPool(pool BufferPool)
- func (logger *Logger) SetFormatter(formatter Formatter)
- func (logger *Logger) SetLevel(level Level)
- func (logger *Logger) SetNoLock()
- func (logger *Logger) SetOutput(output io.Writer)
- func (logger *Logger) SetReportCaller(reportCaller bool)
- func (logger *Logger) Tracef(format string, args ...interface{})
- func (logger *Logger) Warnf(format string, args ...interface{})
- func (logger *Logger) Warningf(format string, args ...interface{})
- func (logger *Logger) WithContext(ctx 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(t time.Time) *Entry
- type MutexWrap
- type NilFormatter
- type StdLogger
Constants ¶
const ( FieldKeyMsg = "msg" FieldKeyLevel = "level" FieldKeyTime = "time" FieldKeyFunc = "func" FieldKeyFile = "file" )
Default key names for the default fields
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 Debugf ¶
func Debugf(format string, args ...interface{})
Debugf logs a message at level Debug on the standard logger.
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf logs a message at level Error on the standard logger.
func Fatal ¶ added in v1.9.0
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 Fatalln ¶ added in v1.9.0
func Fatalln(args ...interface{})
Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
func Infof ¶
func Infof(format string, args ...interface{})
Infof logs a message at level Info on the standard logger.
func IsLevelEnabled ¶
IsLevelEnabled checks if the log level of the standard logger is greater than the level param
func NewClientLogFile ¶
func NewClientLogFile() (io.WriteCloser, error)
NewClientLogFile returns a file handler for mieru client to write logs.
func Panic ¶ added in v1.9.0
func Panic(args ...interface{})
Panic logs a message at level Panic on the standard logger.
func Panicf ¶ added in v1.9.0
func Panicf(format string, args ...interface{})
Panicf logs a message at level Panic on the standard logger.
func Panicln ¶ added in v1.9.0
func Panicln(args ...interface{})
Panicln logs a message at level Panic on the standard logger.
func Print ¶ added in v1.9.0
func Print(args ...interface{})
Print logs a message at level Info on the standard logger.
func Printf ¶ added in v1.9.0
func Printf(format string, args ...interface{})
Printf logs a message at level Info on the standard logger.
func Println ¶ added in v1.9.0
func Println(args ...interface{})
Println logs a message at level Info on the standard logger.
func RemoveOldClientLogFiles ¶
func RemoveOldClientLogFiles() error
RemoveOldClientLogFiles deletes the oldest client log files.
func SetBufferPool ¶ added in v1.9.0
func SetBufferPool(bp BufferPool)
func SetFormatter ¶
func SetFormatter(formatter Formatter)
SetFormatter sets the standard logger formatter.
func SetOutputToTest ¶ added in v1.15.0
SetOutputToTest prints logs to the go test.
func SetReportCaller ¶ added in v1.9.0
func SetReportCaller(include bool)
SetReportCaller sets whether the standard logger will include the calling method as a field.
func Tracef ¶
func Tracef(format string, args ...interface{})
Tracef logs a message at level Trace on the standard logger.
Types ¶
type BufferPool ¶ added in v1.9.0
type CliFormatter ¶
type CliFormatter struct{}
CliFormatter is a log formatter that works best for command output. It doesn't print time, level, or field data.
type DaemonFormatter ¶
type DaemonFormatter struct {
NoTimestamp bool
}
DaemonFormatter is the a log formatter that is suitable for daemon.
type Entry ¶ added in v1.9.0
type Entry struct { Logger *Logger // 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 // When formatter is called in entry.log(), a Buffer may be set to entry Buffer *bytes.Buffer // Contains the context set by the user. Useful for hook processing etc. Context context.Context // contains filtered or unexported fields }
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.
func WithContext ¶ added in v1.9.0
WithContext creates an entry from the standard logger and adds a context to it.
func WithError ¶ added in v1.9.0
WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
func WithField ¶ added in v1.9.0
WithField creates an entry from the standard logger and adds a field to it. If you want multiple fields, use `WithFields`.
Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.
func WithFields ¶
WithFields creates an entry from the standard logger and adds multiple fields to it. This is simply a helper for `WithField`, invoking it once for each field.
Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.
func WithTime ¶ added in v1.9.0
WithTime creates an entry from the standard logger and overrides the time of logs generated with it.
Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.
func (*Entry) Bytes ¶ added in v1.9.0
Returns the bytes representation of this entry from the formatter.
func (*Entry) String ¶ added in v1.9.0
Returns the string representation from the reader and ultimately the formatter.
func (*Entry) WithContext ¶ added in v1.9.0
Add a context to the Entry.
func (*Entry) WithError ¶ added in v1.9.0
Add an error as single field (using the key defined in ErrorKey) to the Entry.
func (*Entry) WithFields ¶ added in v1.9.0
Add a map of fields to the Entry.
type FieldLogger ¶ added in v1.9.0
type FieldLogger interface { WithField(key string, value interface{}) *Entry WithFields(fields Fields) *Entry WithError(err error) *Entry Tracef(format string, args ...interface{}) 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{}) Print(args ...interface{}) Fatal(args ...interface{}) Panic(args ...interface{}) Println(args ...interface{}) Fatalln(args ...interface{}) Panicln(args ...interface{}) }
The FieldLogger interface generalizes the Entry and Logger types
type Formatter ¶ added in v1.9.0
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 ¶ added in v1.9.0
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.New()`.
func ParseLevel ¶ added in v1.9.0
ParseLevel takes a string level and returns the Logrus log level constant.
func (Level) MarshalText ¶ added in v1.9.0
func (Level) String ¶ added in v1.9.0
Convert the Level to a string. E.g. PanicLevel becomes "panic".
func (*Level) UnmarshalText ¶ added in v1.9.0
UnmarshalText implements encoding.TextUnmarshaler.
type LogFunction ¶ added in v1.9.0
type LogFunction func() []interface{}
LogFunction For big messages, it can be more efficient to pass a function and only call it if the log level is actually enables rather than generating the log message and then checking if the level is enabled
type Logger ¶ added in v1.9.0
type Logger struct { // The logs are `io.Copy`'d to this in a mutex. It's common to set this to a // file, or leave it default which is `os.Stderr`. You can also set this to // something more adventurous, such as logging to Kafka. Out io.Writer // All log entries pass through the formatter before logged to Out. The // included formatters are `TextFormatter` and `JSONFormatter` for which // TextFormatter is the default. In development (when a TTY is attached) it // logs with colors, but to a file it wouldn't. You can easily implement your // own that implements the `Formatter` interface, see the `README` or included // formatters for examples. Formatter Formatter // Flag for whether to log caller info (off by default) ReportCaller bool // The logging level the logger should log at. This is typically (and defaults // to) `logrus.Info`, which allows Info(), Warn(), Error() and Fatal() to be // logged. Level Level // Function to exit the application, defaults to `os.Exit()` ExitFunc exitFunc // The buffer pool used to format the log. If it is nil, the default global // buffer pool will be used. BufferPool BufferPool // contains filtered or unexported fields }
func StandardLogger ¶ added in v1.9.0
func StandardLogger() *Logger
func (*Logger) IsLevelEnabled ¶ added in v1.9.0
IsLevelEnabled checks if the log level of the logger is greater than the level param
func (*Logger) SetBufferPool ¶ added in v1.9.0
func (logger *Logger) SetBufferPool(pool BufferPool)
SetBufferPool sets the logger buffer pool.
func (*Logger) SetFormatter ¶ added in v1.9.0
SetFormatter sets the logger formatter.
func (*Logger) SetNoLock ¶ added in v1.9.0
func (logger *Logger) SetNoLock()
When file is opened with appending mode, it's safe to write concurrently to a file (within 4k message on Linux). In these cases user can choose to disable the lock.
func (*Logger) SetReportCaller ¶ added in v1.9.0
func (*Logger) WithContext ¶ added in v1.9.0
Add a context to the log entry.
func (*Logger) WithError ¶ added in v1.9.0
Add an error as single field to the log entry. All it does is call `WithError` for the given `error`.
func (*Logger) WithField ¶ added in v1.9.0
WithField allocates a new entry and adds a field to it. Debug, Print, Info, Warn, Error, Fatal or Panic must be then applied to this new returned entry. If you want multiple fields, use `WithFields`.
func (*Logger) WithFields ¶ added in v1.9.0
Adds a struct of fields to the log entry. All it does is call `WithField` for each `Field`.
type MutexWrap ¶ added in v1.9.0
type MutexWrap struct {
// contains filtered or unexported fields
}
type StdLogger ¶ added in v1.9.0
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 is what your logrus-enabled library should take, that way it'll accept a stdlib logger and a logrus logger. There's no standard interface, this is the closest we get, unfortunately.