logrus

package
Version: v2.2.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 17 Imported by: 326

Documentation

Overview

Package logrus implements the logging API based on the Logrus logger.

Index

Constants

View Source
const DefaultLoggerName = "defaultLogger"

DefaultLoggerName is logger name of global instance of logger

Variables

This section is empty.

Functions

func NewJSONFormatter

func NewJSONFormatter() *lg.JSONFormatter

NewJSONFormatter creates a new instance of JSONFormatter

func NewLogRegistry

func NewLogRegistry() logging.Registry

NewLogRegistry is a constructor

func NewTextFormatter

func NewTextFormatter() *lg.TextFormatter

NewTextFormatter creates a new instance of TextFormatter

Types

type CustomFormatter

type CustomFormatter struct {

	// ShowTimestamp decides whether timestamp field should be part of the log
	ShowTimestamp bool

	// ShowLoc decides whether location of the log origin should be part of the log
	ShowLoc bool

	// ShowTag decides if the tag field should be part of the log
	ShowTag bool
}

CustomFormatter allows to turn off logging of some fields.

func NewCustomFormatter

func NewCustomFormatter() *CustomFormatter

NewCustomFormatter creates a new instance of CustomFormatter

func (*CustomFormatter) Format

func (f *CustomFormatter) Format(entry *log.Entry) ([]byte, error)

Format formats the given log entry.

type Entry added in v1.0.5

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 NewEntry

func NewEntry(logger *Logger) *Entry

NewEntry creates net entry object which stores provided logger and logrus' entry

func (*Entry) Debug added in v1.0.5

func (entry *Entry) Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func (*Entry) Debugf added in v1.0.5

func (entry *Entry) Debugf(format string, args ...interface{})

Debugf logs a message at level Debug on the standard logger.

func (*Entry) Debugln added in v1.0.5

func (entry *Entry) Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func (*Entry) Error added in v1.0.5

func (entry *Entry) Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func (*Entry) Errorf added in v1.0.5

func (entry *Entry) Errorf(format string, args ...interface{})

Errorf logs a message at level Error on the standard logger.

func (*Entry) Errorln added in v1.0.5

func (entry *Entry) Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func (*Entry) Fatal added in v1.0.5

func (entry *Entry) Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func (*Entry) Fatalf added in v1.0.5

func (entry *Entry) Fatalf(format string, args ...interface{})

Fatalf logs a message at level Debug on the standard logger.

func (*Entry) Fatalln added in v1.0.5

func (entry *Entry) Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger.

func (*Entry) Info added in v1.0.5

func (entry *Entry) Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func (*Entry) Infof added in v1.0.5

func (entry *Entry) Infof(format string, args ...interface{})

Infof logs a message at level Info on the standard logger.

func (*Entry) Infoln added in v1.0.5

func (entry *Entry) Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func (*Entry) Panic added in v1.0.5

func (entry *Entry) Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func (*Entry) Panicf added in v1.0.5

func (entry *Entry) Panicf(format string, args ...interface{})

Panicf logs a message at level Panic on the standard logger.

func (*Entry) Panicln added in v1.0.5

func (entry *Entry) Panicln(args ...interface{})

Panicln logs a message at level Panic on the standard logger.

func (*Entry) Print added in v1.0.5

func (entry *Entry) Print(args ...interface{})

Print logs a message at level Info on the standard logger.

func (*Entry) Printf added in v1.0.5

func (entry *Entry) Printf(format string, args ...interface{})

Printf logs a message at level Info on the standard logger.

func (*Entry) Println added in v1.0.5

func (entry *Entry) Println(args ...interface{})

Println logs a message at level Info on the standard logger.

func (*Entry) String added in v1.0.5

func (entry *Entry) String() (string, error)

String returns the string representation from the reader or the formatter.

func (*Entry) Warn added in v1.0.5

func (entry *Entry) Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func (*Entry) Warnf added in v1.0.5

func (entry *Entry) Warnf(format string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

func (*Entry) Warning added in v1.0.5

func (entry *Entry) Warning(args ...interface{})

Warning logs a message at level Warn on the standard logger.

func (*Entry) Warningf added in v1.0.5

func (entry *Entry) Warningf(format string, args ...interface{})

Warningf logs a message at level Warn on the standard logger.

func (*Entry) Warningln added in v1.0.5

func (entry *Entry) Warningln(args ...interface{})

Warningln logs a message at level Warn on the standard logger.

func (*Entry) Warnln added in v1.0.5

func (entry *Entry) Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

func (*Entry) WithError added in v1.0.5

func (entry *Entry) WithError(err error) *Entry

WithError calls calls WithField with error key

func (*Entry) WithField added in v1.0.5

func (entry *Entry) WithField(key string, value interface{}) *Entry

WithField calls transforms key/value to field and passes to WithFields

func (*Entry) WithFields added in v1.0.5

func (entry *Entry) WithFields(fields lg.Fields) *Entry

WithFields stores field entries. These entries are used later when log method (Info, Debug, etc) is called

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

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 Logrus logger. Note, that recommended approach is to create a custom logger.

func NewLogger

func NewLogger(name string) *Logger

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("loggerXY")
logger.Info()

func (*Logger) AddHook

func (logger *Logger) AddHook(hook lg.Hook)

AddHook adds a hook to the standard logger hooks.

func (*Logger) ClearTag

func (logger *Logger) ClearTag()

ClearTag removes the previously set string tag for the current go routine.

func (*Logger) Debug

func (logger *Logger) Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, args ...interface{})

Debugf 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) Errorf

func (logger *Logger) Errorf(format string, args ...interface{})

Errorf 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) Fatalf

func (logger *Logger) Fatalf(format string, args ...interface{})

Fatalf 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) GetLevel

func (logger *Logger) GetLevel() logging.LogLevel

GetLevel returns the standard logger level.

func (*Logger) GetName

func (logger *Logger) GetName() string

GetName return the logger name

func (*Logger) GetStaticFields

func (logger *Logger) GetStaticFields() map[string]interface{}

GetStaticFields returns currently set map of static fields - key-value pairs that are automatically added into log entry

func (*Logger) GetTag

func (logger *Logger) GetTag() string

GetTag returns the tag identifying the caller's go routine.

func (*Logger) Info

func (logger *Logger) Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func (*Logger) Infof

func (logger *Logger) Infof(format string, args ...interface{})

Infof 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) InitTag

func (logger *Logger) InitTag(tag ...string)

InitTag sets the tag for the main thread.

func (*Logger) Panic

func (logger *Logger) Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func (*Logger) Panicf

func (logger *Logger) Panicf(format string, args ...interface{})

Panicf 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) Printf

func (logger *Logger) Printf(format string, args ...interface{})

Printf 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 *Logger) SetFormatter(formatter lg.Formatter)

SetFormatter sets the standard logger formatter.

func (*Logger) SetLevel

func (logger *Logger) SetLevel(level logging.LogLevel)

SetLevel sets the standard logger level.

func (*Logger) SetOutput

func (logger *Logger) SetOutput(out io.Writer)

SetOutput sets the standard logger output.

func (*Logger) SetStaticFields

func (logger *Logger) SetStaticFields(fields map[string]interface{})

SetStaticFields sets a map of fields that will be part of the each subsequent log entry of the logger

func (*Logger) SetTag

func (logger *Logger) SetTag(tag ...string)

SetTag allows to define a string tag for the current go routine. Otherwise numeric identification is used.

func (*Logger) StandardLogger

func (logger *Logger) StandardLogger() *lg.Logger

StandardLogger returns internally used Logrus logger

func (*Logger) Warn

func (logger *Logger) Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func (*Logger) Warnf

func (logger *Logger) Warnf(format string, args ...interface{})

Warnf logs a message at level Warn 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) Warningf

func (logger *Logger) Warningf(format string, args ...interface{})

Warningf 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) 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL