Documentation
¶
Overview ¶
Package logrus implements the logging API based on the Logrus logger.
Index ¶
- Constants
- type Entry
- func (entry *Entry) Debug(args ...interface{})
- func (entry *Entry) Debugf(format string, args ...interface{})
- func (entry *Entry) Debugln(args ...interface{})
- 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) Info(args ...interface{})
- func (entry *Entry) Infof(format string, args ...interface{})
- func (entry *Entry) Infoln(args ...interface{})
- func (entry *Entry) Log(lvl logrus.Level, args ...interface{})
- func (entry *Entry) Logf(lvl logrus.Level, f string, args ...interface{})
- func (entry *Entry) Logln(lvl logrus.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) WithError(err error) logging.LogWithLevel
- func (entry *Entry) WithField(key string, value interface{}) logging.LogWithLevel
- func (entry *Entry) WithFields(fields logging.Fields) logging.LogWithLevel
- type Formatter
- type LogRegistry
- func (lr *LogRegistry) AddHook(hook logrus.Hook)
- func (lr *LogRegistry) ClearRegistry()
- func (lr *LogRegistry) GetLevel(logger string) (string, error)
- func (lr *LogRegistry) ListLoggers() map[string]string
- func (lr *LogRegistry) Lookup(loggerName string) (logger logging.Logger, found bool)
- func (lr *LogRegistry) NewLogger(name string) logging.Logger
- func (lr *LogRegistry) SetLevel(logger, level string) error
- type Logger
- func (logger *Logger) AddHook(hook logrus.Hook)
- 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) Fatal(args ...interface{})
- func (logger *Logger) Fatalf(format string, args ...interface{})
- func (logger *Logger) Fatalln(args ...interface{})
- func (logger *Logger) GetLevel() logging.LogLevel
- func (logger *Logger) GetName() string
- func (logger *Logger) GetStaticFields() map[string]interface{}
- func (logger *Logger) Info(args ...interface{})
- func (logger *Logger) Infof(format string, args ...interface{})
- func (logger *Logger) Infoln(args ...interface{})
- func (logger *Logger) Log(lvl logrus.Level, args ...interface{})
- func (logger *Logger) Logf(lvl logrus.Level, f string, args ...interface{})
- func (logger *Logger) Logln(lvl logrus.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) SetFormatter(formatter logrus.Formatter)
- func (logger *Logger) SetLevel(lvl logging.LogLevel)
- func (logger *Logger) SetOutput(out io.Writer)
- func (logger *Logger) SetReportCaller(enable bool)
- func (logger *Logger) SetStaticFields(fields map[string]interface{})
- func (logger *Logger) SetVerbosity(v int)
- func (logger *Logger) StandardLogger() *logrus.Logger
- func (logger *Logger) Trace(args ...interface{})
- func (logger *Logger) Tracef(format string, args ...interface{})
- func (logger *Logger) Traceln(args ...interface{})
- func (logger *Logger) V(l int) bool
- 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) WithContext(ctx context.Context) logging.LogWithLevel
- func (logger *Logger) WithError(err error) logging.LogWithLevel
- func (logger *Logger) WithField(key string, value interface{}) logging.LogWithLevel
- func (logger *Logger) WithFields(fields logging.Fields) logging.LogWithLevel
Constants ¶
const ( LoggerKey = "logger" FunctionKey = "func" LocationKey = "loc" )
Tag names for structured fields of log entry
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is the logging entry. It has logrus' entry struct which is a final or intermediate Logrus logging entry
func (*Entry) Debug ¶
func (entry *Entry) Debug(args ...interface{})
Debug logs a message at level Debug on the standard logger.
func (*Entry) Debugln ¶
func (entry *Entry) Debugln(args ...interface{})
Debugln logs a message at level Debug on the standard logger.
func (*Entry) Error ¶
func (entry *Entry) Error(args ...interface{})
Error logs a message at level Error on the standard logger.
func (*Entry) Errorln ¶
func (entry *Entry) Errorln(args ...interface{})
Errorln logs a message at level Error on the standard logger.
func (*Entry) Fatal ¶
func (entry *Entry) Fatal(args ...interface{})
Fatal logs a message at level Fatal on the standard logger.
func (*Entry) Fatalln ¶
func (entry *Entry) Fatalln(args ...interface{})
Fatalln logs a message at level Fatal on the standard logger.
func (*Entry) Info ¶
func (entry *Entry) Info(args ...interface{})
Info logs a message at level Info on the standard logger.
func (*Entry) Infoln ¶
func (entry *Entry) Infoln(args ...interface{})
Infoln logs a message at level Info on the standard logger.
func (*Entry) Panic ¶
func (entry *Entry) Panic(args ...interface{})
Panic logs a message at level Panic on the standard logger.
func (*Entry) Panicln ¶
func (entry *Entry) Panicln(args ...interface{})
Panicln logs a message at level Panic on the standard logger.
func (*Entry) Print ¶
func (entry *Entry) Print(args ...interface{})
Print logs a message at level Info on the standard logger.
func (*Entry) Println ¶
func (entry *Entry) Println(args ...interface{})
Println logs a message at level Info on the standard logger.
func (*Entry) Trace ¶
func (entry *Entry) Trace(args ...interface{})
Trace logs a message at level Trace on the standard logger.
func (*Entry) Traceln ¶
func (entry *Entry) Traceln(args ...interface{})
Traceln logs a message at level Trace on the standard logger.
func (*Entry) Warn ¶
func (entry *Entry) Warn(args ...interface{})
Warn logs a message at level Warning on the standard logger.
func (*Entry) Warning ¶
func (entry *Entry) Warning(args ...interface{})
Warning logs a message at level Warning on the standard logger.
func (*Entry) Warningln ¶
func (entry *Entry) Warningln(args ...interface{})
Warningln logs a message at level Warn on the standard logger.
func (*Entry) Warnln ¶
func (entry *Entry) Warnln(args ...interface{})
Warnln logs a message at level Warn on the standard logger.
func (*Entry) WithError ¶
func (entry *Entry) WithError(err error) logging.LogWithLevel
WithError adds error to fields.
func (*Entry) WithField ¶
func (entry *Entry) WithField(key string, value interface{}) logging.LogWithLevel
WithField calls transforms key/value to field and passes to WithFields
func (*Entry) WithFields ¶
func (entry *Entry) WithFields(fields logging.Fields) logging.LogWithLevel
WithFields stores field entries. These entries are used later when log method (Info, Debug, etc) is called
type Formatter ¶
func DefaultFormatter ¶
func DefaultFormatter() *Formatter
DefaultFormatter returns a formatter used as the default formatter for loggers.
func NewFormatter ¶
func NewFormatter() *Formatter
type LogRegistry ¶
type LogRegistry struct {
// contains filtered or unexported fields
}
LogRegistry contains logger map and rwlock guarding access to it
func DefaultRegistry ¶
func DefaultRegistry() *LogRegistry
DefaultRegistry returns the global registry instance.
func (*LogRegistry) AddHook ¶
func (lr *LogRegistry) AddHook(hook logrus.Hook)
AddHook applies the hook to existing loggers and adds it to list of hooks to be applies for new loggers.
func (*LogRegistry) ClearRegistry ¶
func (lr *LogRegistry) ClearRegistry()
ClearRegistry removes all loggers except the default one from registry
func (*LogRegistry) GetLevel ¶
func (lr *LogRegistry) GetLevel(logger string) (string, error)
GetLevel returns the currently set log level of the logger
func (*LogRegistry) ListLoggers ¶
func (lr *LogRegistry) ListLoggers() map[string]string
ListLoggers returns a map (loggerName => log level)
func (*LogRegistry) Lookup ¶
func (lr *LogRegistry) Lookup(loggerName string) (logger logging.Logger, found bool)
Lookup returns a logger instance identified by name from registry
func (*LogRegistry) NewLogger ¶
func (lr *LogRegistry) NewLogger(name string) logging.Logger
NewLogger creates new named Logger instance. Name can be subsequently used to refer the logger in registry.
func (*LogRegistry) SetLevel ¶
func (lr *LogRegistry) SetLevel(logger, level string) error
SetLevel modifies log level of selected logger in the registry
type Logger ¶
Logger is wrapper of Logrus logger. In addition to Logrus functionality it allows to define static log fields that are added to all subsequent log entries. It also automatically appends file name and line where the log is coming from. In order to distinguish logs from different go routines a tag (number that is based on the stack address) is computed. To achieve better readability numeric value of a tag can be replaced by a string using SetTag function.
func DefaultLogger ¶
func DefaultLogger() *Logger
DefaultLogger returns a global logger. Note, that recommended approach is to create a custom logger.
func NewLogger ¶
NewLogger is a constructor creates instances of named logger. This constructor is called from LogRegistry which is useful when log levels needs to be changed by management API (such as REST)
Example:
logger := NewLogger("MyLogger")
logger.Info("informative message")
func WrapLogger ¶
WrapLogger wraps logrus.Logger and returns named Logger.
func (*Logger) Debug ¶
func (logger *Logger) Debug(args ...interface{})
Debug logs a message at level Debug on the standard logger.
func (*Logger) Debugln ¶
func (logger *Logger) Debugln(args ...interface{})
Debugln logs a message at level Debug on the standard logger.
func (*Logger) Error ¶
func (logger *Logger) Error(args ...interface{})
Error logs a message at level Error on the standard logger.
func (*Logger) Errorln ¶
func (logger *Logger) Errorln(args ...interface{})
Errorln logs a message at level Error on the standard logger.
func (*Logger) Fatal ¶
func (logger *Logger) Fatal(args ...interface{})
Fatal logs a message at level Fatal on the standard logger.
func (*Logger) Fatalln ¶
func (logger *Logger) Fatalln(args ...interface{})
Fatalln logs a message at level Fatal on the standard logger.
func (*Logger) GetStaticFields ¶
GetStaticFields returns currently set map of static fields - key-value pairs that are automatically added into log entry
func (*Logger) Info ¶
func (logger *Logger) Info(args ...interface{})
Info logs a message at level Info on the standard logger.
func (*Logger) Infoln ¶
func (logger *Logger) Infoln(args ...interface{})
Infoln logs a message at level Info on the standard logger.
func (*Logger) Panic ¶
func (logger *Logger) Panic(args ...interface{})
Panic logs a message at level Panic on the standard logger.
func (*Logger) Panicln ¶
func (logger *Logger) Panicln(args ...interface{})
Panicln logs a message at level Panic on the standard logger.
func (*Logger) Print ¶
func (logger *Logger) Print(args ...interface{})
Print logs a message at level Info on the standard logger.
func (*Logger) Println ¶
func (logger *Logger) Println(args ...interface{})
Println logs a message at level Info on the standard logger.
func (*Logger) SetFormatter ¶
func (*Logger) SetReportCaller ¶
func (*Logger) SetStaticFields ¶
SetStaticFields sets a map of fields that will be part of the each subsequent log entry of the logger
func (*Logger) SetVerbosity ¶
SetVerbosity allows to set a logger verbosity. The verbosity can be used in custom loggers passed to external libraries (like GRPC) and may not correspond with the Logger plugin log levels. See the documentation of the given library to learn about supported verbosity levels.
func (*Logger) StandardLogger ¶
func (*Logger) Trace ¶
func (logger *Logger) Trace(args ...interface{})
Trace logs a message at level Trace on the standard logger.
func (*Logger) Traceln ¶
func (logger *Logger) Traceln(args ...interface{})
Traceln logs a message at level Trace on the standard logger.
func (*Logger) Warn ¶
func (logger *Logger) Warn(args ...interface{})
Warn logs a message at level Warning on the standard logger.
func (*Logger) Warning ¶
func (logger *Logger) Warning(args ...interface{})
Warning logs a message at level Warn on the standard logger.
func (*Logger) Warningln ¶
func (logger *Logger) Warningln(args ...interface{})
Warningln logs a message at level Warn on the standard logger.
func (*Logger) Warnln ¶
func (logger *Logger) Warnln(args ...interface{})
Warnln logs a message at level Warn on the standard logger.
func (*Logger) WithContext ¶
func (logger *Logger) WithContext(ctx context.Context) logging.LogWithLevel
func (*Logger) WithField ¶
func (logger *Logger) WithField(key string, value interface{}) logging.LogWithLevel
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 LogMsg it returns.
func (*Logger) WithFields ¶
func (logger *Logger) WithFields(fields logging.Fields) logging.LogWithLevel
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 LogMsg it returns.