package logrus

Import Path
	github.com/sirupsen/logrus (on go.dev)

Dependency Relation
	imports 18 packages, and imported by 3 packages

Involved Source Files alt_exit.go buffer_pool.go Package logrus is a structured logger for Go, completely API compatible with the standard library logger. The simplest way to use Logrus is simply the package-level exported logger: package main import ( log "github.com/sirupsen/logrus" ) func main() { log.WithFields(log.Fields{ "animal": "walrus", "number": 1, "size": 10, }).Info("A walrus appears") } Output: time="2015-09-07T08:48:33Z" level=info msg="A walrus appears" animal=walrus number=1 size=10 For a full guide visit https://github.com/sirupsen/logrus entry.go exported.go formatter.go hooks.go json_formatter.go logger.go logrus.go terminal_check_notappengine.go terminal_check_unix.go text_formatter.go writer.go
Code Examples package main import ( "os" "github.com/sirupsen/logrus" ) type DefaultFieldHook struct { GetValue func() string } func (h *DefaultFieldHook) Levels() []logrus.Level { return logrus.AllLevels } func (h *DefaultFieldHook) Fire(e *logrus.Entry) error { e.Data["aDefaultField"] = h.GetValue() return nil } func main() { l := logrus.New() l.Out = os.Stdout l.Formatter = &logrus.TextFormatter{DisableTimestamp: true, DisableColors: true} l.AddHook(&DefaultFieldHook{GetValue: func() string { return "with its default value" }}) l.Info("first log") } package main import ( "os" "github.com/sirupsen/logrus" ) var ( mystring string ) type GlobalHook struct { } func (h *GlobalHook) Levels() []logrus.Level { return logrus.AllLevels } func (h *GlobalHook) Fire(e *logrus.Entry) error { e.Data["mystring"] = mystring return nil } func main() { l := logrus.New() l.Out = os.Stdout l.Formatter = &logrus.TextFormatter{DisableTimestamp: true, DisableColors: true} l.AddHook(&GlobalHook{}) mystring = "first value" l.Info("first log") mystring = "another value" l.Info("second log") } package main import ( "github.com/sirupsen/logrus" "os" "path" "runtime" "strings" ) func main() { l := logrus.New() l.SetReportCaller(true) l.Out = os.Stdout l.Formatter = &logrus.JSONFormatter{ DisableTimestamp: true, CallerPrettyfier: func(f *runtime.Frame) (string, string) { s := strings.Split(f.Function, ".") funcname := s[len(s)-1] _, filename := path.Split(f.File) return funcname, filename }, } l.Info("example of custom format caller") } package main import ( "github.com/sirupsen/logrus" "os" ) func main() { var log = logrus.New() log.Formatter = new(logrus.JSONFormatter) log.Formatter = new(logrus.TextFormatter) //default log.Formatter.(*logrus.TextFormatter).DisableColors = true // remove colors log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output log.Level = logrus.TraceLevel log.Out = os.Stdout // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666) // if err == nil { // log.Out = file // } else { // log.Info("Failed to log to file, using default stderr") // } defer func() { err := recover() if err != nil { entry := err.(*logrus.Entry) log.WithFields(logrus.Fields{ "omg": true, "err_animal": entry.Data["animal"], "err_size": entry.Data["size"], "err_level": entry.Level, "err_message": entry.Message, "number": 100, }).Error("The ice breaks!") // or use Fatal() to force the process to exit with a nonzero code } }() log.WithFields(logrus.Fields{ "animal": "walrus", "number": 0, }).Trace("Went to the beach") log.WithFields(logrus.Fields{ "animal": "walrus", "number": 8, }).Debug("Started observing beach") log.WithFields(logrus.Fields{ "animal": "walrus", "size": 10, }).Info("A group of walrus emerges from the ocean") log.WithFields(logrus.Fields{ "omg": true, "number": 122, }).Warn("The group's number increased tremendously!") log.WithFields(logrus.Fields{ "temperature": -4, }).Debug("Temperature changes") log.WithFields(logrus.Fields{ "animal": "orca", "size": 9009, }).Panic("It's over 9000!") } package main import ( "github.com/sirupsen/logrus" slhooks "github.com/sirupsen/logrus/hooks/syslog" "log/syslog" "os" ) func main() { var log = logrus.New() log.Formatter = new(logrus.TextFormatter) // default log.Formatter.(*logrus.TextFormatter).DisableColors = true // remove colors log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output if sl, err := slhooks.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, ""); err == nil { log.Hooks.Add(sl) } log.Out = os.Stdout log.WithFields(logrus.Fields{ "animal": "walrus", "size": 10, }).Info("A group of walrus emerges from the ocean") log.WithFields(logrus.Fields{ "omg": true, "number": 122, }).Warn("The group's number increased tremendously!") log.WithFields(logrus.Fields{ "omg": true, "number": 100, }).Error("The ice breaks!") }
Package-Level Type Names (total 19, in which 16 are exported)
/* sort exporteds by: | */
( T) Get() *bytes.Buffer ( T) Put(*bytes.Buffer) func SetBufferPool(bp BufferPool)
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. When formatter is called in entry.log(), a Buffer may be set to entry Calling method, with package name Contains the context set by the user. Useful for hook processing etc. Contains all the fields set by the user. 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. Logger *Logger Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic Time at which the log entry was created Returns the bytes representation of this entry from the formatter. (*T) Debug(args ...interface{}) (*T) Debugf(format string, args ...interface{}) (*T) Debugln(args ...interface{}) (*T) Dup() *Entry (*T) Error(args ...interface{}) (*T) Errorf(format string, args ...interface{}) (*T) Errorln(args ...interface{}) (*T) Fatal(args ...interface{}) (*T) Fatalf(format string, args ...interface{}) (*T) Fatalln(args ...interface{}) ( T) HasCaller() (has bool) (*T) Info(args ...interface{}) (*T) Infof(format string, args ...interface{}) (*T) Infoln(args ...interface{}) (*T) Log(level Level, args ...interface{}) (*T) Logf(level Level, format string, args ...interface{}) (*T) Logln(level Level, args ...interface{}) (*T) Panic(args ...interface{}) (*T) Panicf(format string, args ...interface{}) (*T) Panicln(args ...interface{}) (*T) Print(args ...interface{}) (*T) Printf(format string, args ...interface{}) (*T) Println(args ...interface{}) Returns the string representation from the reader and ultimately the formatter. (*T) Trace(args ...interface{}) (*T) Tracef(format string, args ...interface{}) (*T) Traceln(args ...interface{}) (*T) Warn(args ...interface{}) (*T) Warnf(format string, args ...interface{}) (*T) Warning(args ...interface{}) (*T) Warningf(format string, args ...interface{}) (*T) Warningln(args ...interface{}) (*T) Warnln(args ...interface{}) Add a context to the Entry. Add an error as single field (using the key defined in ErrorKey) to the Entry. Add a single field to the Entry. Add a map of fields to the Entry. Overrides the time of the Entry. (*T) Writer() *io.PipeWriter (*T) WriterLevel(level Level) *io.PipeWriter *T : Ext1FieldLogger *T : FieldLogger *T : StdLogger func NewEntry(logger *Logger) *Entry func WithContext(ctx context.Context) *Entry func WithError(err error) *Entry func WithField(key string, value interface{}) *Entry func WithFields(fields Fields) *Entry func WithTime(t time.Time) *Entry func (*Entry).Dup() *Entry func (*Entry).WithContext(ctx context.Context) *Entry func (*Entry).WithError(err error) *Entry func (*Entry).WithField(key string, value interface{}) *Entry func (*Entry).WithFields(fields Fields) *Entry func (*Entry).WithTime(t time.Time) *Entry func Ext1FieldLogger.WithError(err error) *Entry func Ext1FieldLogger.WithField(key string, value interface{}) *Entry func Ext1FieldLogger.WithFields(fields Fields) *Entry func FieldLogger.WithError(err error) *Entry func FieldLogger.WithField(key string, value interface{}) *Entry func FieldLogger.WithFields(fields Fields) *Entry func (*Logger).WithContext(ctx context.Context) *Entry func (*Logger).WithError(err error) *Entry func (*Logger).WithField(key string, value interface{}) *Entry func (*Logger).WithFields(fields Fields) *Entry func (*Logger).WithTime(t time.Time) *Entry func Formatter.Format(*Entry) ([]byte, error) func Hook.Fire(*Entry) error func (*JSONFormatter).Format(entry *Entry) ([]byte, error) func LevelHooks.Fire(level Level, entry *Entry) error func (*TextFormatter).Format(entry *Entry) ([]byte, error) func github.com/antonfisher/nested-logrus-formatter.(*Formatter).Format(entry *Entry) ([]byte, error) func github.com/joonix/log.(*Formatter).Format(entry *Entry) ([]byte, error) func gitlab.com/pcanilho/go-jira-cli/cmd/logging.(*ApplicationHook).Fire(entry *Entry) error func gitlab.com/pcanilho/go-jira-cli/cmd/logging.StdoutHook.Fire(entry *Entry) error
Ext1FieldLogger (the first extension to FieldLogger) is superfluous, it is here for consistancy. Do not use. Use Logger or Entry instead. ( T) Debug(args ...interface{}) ( T) Debugf(format string, args ...interface{}) ( T) Debugln(args ...interface{}) ( T) Error(args ...interface{}) ( T) Errorf(format string, args ...interface{}) ( T) Errorln(args ...interface{}) ( T) Fatal(args ...interface{}) ( T) Fatalf(format string, args ...interface{}) ( T) Fatalln(args ...interface{}) ( T) Info(args ...interface{}) ( T) Infof(format string, args ...interface{}) ( T) Infoln(args ...interface{}) ( T) Panic(args ...interface{}) ( T) Panicf(format string, args ...interface{}) ( T) Panicln(args ...interface{}) ( T) Print(args ...interface{}) ( T) Printf(format string, args ...interface{}) ( T) Println(args ...interface{}) ( T) Trace(args ...interface{}) ( T) Tracef(format string, args ...interface{}) ( T) Traceln(args ...interface{}) ( T) Warn(args ...interface{}) ( T) Warnf(format string, args ...interface{}) ( T) Warning(args ...interface{}) ( T) Warningf(format string, args ...interface{}) ( T) Warningln(args ...interface{}) ( T) Warnln(args ...interface{}) ( T) WithError(err error) *Entry ( T) WithField(key string, value interface{}) *Entry ( T) WithFields(fields Fields) *Entry *Entry *Logger T : FieldLogger T : StdLogger
The FieldLogger interface generalizes the Entry and Logger types ( T) Debug(args ...interface{}) ( T) Debugf(format string, args ...interface{}) ( T) Debugln(args ...interface{}) ( T) Error(args ...interface{}) ( T) Errorf(format string, args ...interface{}) ( T) Errorln(args ...interface{}) ( T) Fatal(args ...interface{}) ( T) Fatalf(format string, args ...interface{}) ( T) Fatalln(args ...interface{}) ( T) Info(args ...interface{}) ( T) Infof(format string, args ...interface{}) ( T) Infoln(args ...interface{}) ( T) Panic(args ...interface{}) ( T) Panicf(format string, args ...interface{}) ( T) Panicln(args ...interface{}) ( T) Print(args ...interface{}) ( T) Printf(format string, args ...interface{}) ( T) Println(args ...interface{}) ( T) Warn(args ...interface{}) ( T) Warnf(format string, args ...interface{}) ( T) Warning(args ...interface{}) ( T) Warningf(format string, args ...interface{}) ( T) Warningln(args ...interface{}) ( T) Warnln(args ...interface{}) ( T) WithError(err error) *Entry ( T) WithField(key string, value interface{}) *Entry ( T) WithFields(fields Fields) *Entry *Entry Ext1FieldLogger (interface) *Logger T : StdLogger
FieldMap allows customization of the key names for default fields.
Fields type, used to pass to `WithFields`. func WithFields(fields Fields) *Entry func (*Entry).WithFields(fields Fields) *Entry func Ext1FieldLogger.WithFields(fields Fields) *Entry func FieldLogger.WithFields(fields Fields) *Entry func (*Logger).WithFields(fields Fields) *Entry
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`. ( T) Format(*Entry) ([]byte, error) *JSONFormatter *TextFormatter *github.com/antonfisher/nested-logrus-formatter.Formatter *github.com/joonix/log.Formatter func SetFormatter(formatter Formatter) func (*Logger).SetFormatter(formatter Formatter) func gitlab.com/pcanilho/go-jira-cli/cmd/logging.NewStdoutHook(level Level, formatter Formatter) Hook
A hook to be fired when logging on the logging levels returned from `Levels()` on your implementation of the interface. Note that this is not fired in a goroutine or a channel with workers, you should handle such functionality yourself if your call is non-blocking and you don't wish for the logging calls for levels returned from `Levels()` to block. ( T) Fire(*Entry) error ( T) Levels() []Level *gitlab.com/pcanilho/go-jira-cli/cmd/logging.ApplicationHook gitlab.com/pcanilho/go-jira-cli/cmd/logging.StdoutHook func gitlab.com/pcanilho/go-jira-cli/cmd/logging.NewApplicationHook(config logging.ApplicationHookConfig) Hook func gitlab.com/pcanilho/go-jira-cli/cmd/logging.NewStdoutHook(level Level, formatter Formatter) Hook func AddHook(hook Hook) func LevelHooks.Add(hook Hook) func (*Logger).AddHook(hook Hook)
JSONFormatter formats logs into parsable json 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. DataKey allows users to put all the log entry parameters into a nested dictionary at a given key. DisableHTMLEscape allows disabling html escaping in output DisableTimestamp allows disabling automatic timestamps in output 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", }, } PrettyPrint will indent all json logs 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. Format renders a single log entry *T : Formatter
Level type ( T) MarshalText() ([]byte, error) Convert the Level to a string. E.g. PanicLevel becomes "panic". UnmarshalText implements encoding.TextUnmarshaler. T : encoding.TextMarshaler *T : encoding.TextUnmarshaler T : fmt.Stringer func GetLevel() Level func ParseLevel(lvl string) (Level, error) func Hook.Levels() []Level func (*Logger).GetLevel() Level func gitlab.com/pcanilho/go-jira-cli/cmd/logging.(*ApplicationHook).Levels() []Level func gitlab.com/pcanilho/go-jira-cli/cmd/logging.StdoutHook.Levels() []Level func IsLevelEnabled(level Level) bool func SetLevel(level Level) func (*Entry).Log(level Level, args ...interface{}) func (*Entry).Logf(level Level, format string, args ...interface{}) func (*Entry).Logln(level Level, args ...interface{}) func (*Entry).WriterLevel(level Level) *io.PipeWriter func LevelHooks.Fire(level Level, entry *Entry) error func (*Logger).IsLevelEnabled(level Level) bool func (*Logger).Log(level Level, args ...interface{}) func (*Logger).Logf(level Level, format string, args ...interface{}) func (*Logger).LogFn(level Level, fn LogFunction) func (*Logger).Logln(level Level, args ...interface{}) func (*Logger).SetLevel(level Level) func (*Logger).WriterLevel(level Level) *io.PipeWriter func gitlab.com/pcanilho/go-jira-cli/cmd/logging.NewStdoutHook(level Level, formatter Formatter) Hook const DebugLevel const ErrorLevel const FatalLevel const InfoLevel const PanicLevel const TraceLevel const WarnLevel
Internal type for storing the hooks on a logger instance. Add a hook to an instance of logger. This is called with `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. Fire all the hooks for the passed level. Used by `entry.log` to fire appropriate hooks for a log entry. func (*Logger).ReplaceHooks(hooks LevelHooks) LevelHooks func (*Logger).ReplaceHooks(hooks LevelHooks) LevelHooks
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 func DebugFn(fn LogFunction) func ErrorFn(fn LogFunction) func FatalFn(fn LogFunction) func InfoFn(fn LogFunction) func PanicFn(fn LogFunction) func PrintFn(fn LogFunction) func TraceFn(fn LogFunction) func WarnFn(fn LogFunction) func WarningFn(fn LogFunction) func (*Logger).DebugFn(fn LogFunction) func (*Logger).ErrorFn(fn LogFunction) func (*Logger).FatalFn(fn LogFunction) func (*Logger).InfoFn(fn LogFunction) func (*Logger).LogFn(level Level, fn LogFunction) func (*Logger).PanicFn(fn LogFunction) func (*Logger).PrintFn(fn LogFunction) func (*Logger).TraceFn(fn LogFunction) func (*Logger).WarnFn(fn LogFunction) func (*Logger).WarningFn(fn LogFunction)
Function to exit the application, defaults to `os.Exit()` 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. Hooks for the logger instance. These allow firing events based on logging levels and log entries. For example, to send errors to an error tracking service, log to StatsD or dump the core on fatal errors. 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. 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. Flag for whether to log caller info (off by default) AddHook adds a hook to the logger hooks. (*T) Debug(args ...interface{}) (*T) DebugFn(fn LogFunction) (*T) Debugf(format string, args ...interface{}) (*T) Debugln(args ...interface{}) (*T) Error(args ...interface{}) (*T) ErrorFn(fn LogFunction) (*T) Errorf(format string, args ...interface{}) (*T) Errorln(args ...interface{}) (*T) Exit(code int) (*T) Fatal(args ...interface{}) (*T) FatalFn(fn LogFunction) (*T) Fatalf(format string, args ...interface{}) (*T) Fatalln(args ...interface{}) GetLevel returns the logger level. (*T) Info(args ...interface{}) (*T) InfoFn(fn LogFunction) (*T) Infof(format string, args ...interface{}) (*T) Infoln(args ...interface{}) IsLevelEnabled checks if the log level of the logger is greater than the level param (*T) Log(level Level, args ...interface{}) (*T) LogFn(level Level, fn LogFunction) (*T) Logf(level Level, format string, args ...interface{}) (*T) Logln(level Level, args ...interface{}) (*T) Panic(args ...interface{}) (*T) PanicFn(fn LogFunction) (*T) Panicf(format string, args ...interface{}) (*T) Panicln(args ...interface{}) (*T) Print(args ...interface{}) (*T) PrintFn(fn LogFunction) (*T) Printf(format string, args ...interface{}) (*T) Println(args ...interface{}) ReplaceHooks replaces the logger hooks and returns the old ones SetFormatter sets the logger formatter. SetLevel sets the logger level. 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. SetOutput sets the logger output. (*T) SetReportCaller(reportCaller bool) (*T) Trace(args ...interface{}) (*T) TraceFn(fn LogFunction) (*T) Tracef(format string, args ...interface{}) (*T) Traceln(args ...interface{}) (*T) Warn(args ...interface{}) (*T) WarnFn(fn LogFunction) (*T) Warnf(format string, args ...interface{}) (*T) Warning(args ...interface{}) (*T) WarningFn(fn LogFunction) (*T) Warningf(format string, args ...interface{}) (*T) Warningln(args ...interface{}) (*T) Warnln(args ...interface{}) Add a context to the log entry. Add an error as single field to the log entry. All it does is call `WithError` for the given `error`. 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`. Adds a struct of fields to the log entry. All it does is call `WithField` for each `Field`. Overrides the time of the log entry. Writer at INFO level. See WriterLevel for details. WriterLevel returns an io.Writer that can be used to write arbitrary text to the logger at the given log level. Each line written to the writer will be printed in the usual way using formatters and hooks. The writer is part of an io.Pipe and it is the callers responsibility to close the writer when done. This can be used to override the standard library logger easily. *T : Ext1FieldLogger *T : FieldLogger *T : StdLogger func New() *Logger func StandardLogger() *Logger func NewEntry(logger *Logger) *Entry
(*T) Disable() (*T) Lock() (*T) Unlock() *T : sync.Locker
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. ( T) Fatal(...interface{}) ( T) Fatalf(string, ...interface{}) ( T) Fatalln(...interface{}) ( T) Panic(...interface{}) ( T) Panicf(string, ...interface{}) ( T) Panicln(...interface{}) ( T) Print(...interface{}) ( T) Printf(string, ...interface{}) ( T) Println(...interface{}) *Entry Ext1FieldLogger (interface) FieldLogger (interface) *Logger *log.Logger
TextFormatter formats logs into text CallerPrettyfier can be set by the user to modify the content of the function and file keys in the data when ReportCaller is activated. If any of the returned value is the empty string the corresponding key will be removed from fields. Force disabling colors. Disables the truncation of the level text to 4 characters. DisableQuote disables quoting for all values. DisableQuote will have a lower priority than ForceQuote. If both of them are set to true, quote will be forced on all values. The fields are sorted by default for a consistent output. For applications that log extremely frequently and don't use the JSON formatter this may not be desired. Disable timestamp logging. useful when output is redirected to logging system that already adds timestamps. Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/ FieldMap allows users to customize the names of keys for default fields. As an example: formatter := &TextFormatter{ FieldMap: FieldMap{ FieldKeyTime: "@timestamp", FieldKeyLevel: "@level", FieldKeyMsg: "@message"}} Set to true to bypass checking for a TTY before outputting colors. Force quoting of all values Enable logging the full timestamp when a TTY is attached instead of just the time passed since beginning of execution. PadLevelText Adds padding the level text so that all the levels output at the same length PadLevelText is a superset of the DisableLevelTruncation option QuoteEmptyFields will wrap empty fields in quotes if true The keys sorting function, when uninitialized it uses sort.Strings. TimestampFormat to use for display when a full timestamp is printed. 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. Format renders a single log entry *T : Formatter
Package-Level Functions (total 69, in which 56 are exported)
AddHook adds a hook to the standard logger hooks.
Debug logs a message at level Debug on the standard logger.
Debugf logs a message at level Debug on the standard logger.
DebugFn logs a message from a func at level Debug on the standard logger.
Debugln logs a message at level Debug on the standard logger.
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.
Error logs a message at level Error on the standard logger.
Errorf logs a message at level Error on the standard logger.
ErrorFn logs a message from a func at level Error on the standard logger.
Errorln logs a message at level Error on the standard logger.
Exit runs all the Logrus atexit handlers and then terminates the program using os.Exit(code)
Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
FatalFn logs a message from a func at level Fatal on the standard logger then the process will exit with status set to 1.
Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
GetLevel returns the standard logger level.
Info logs a message at level Info on the standard logger.
Infof logs a message at level Info on the standard logger.
InfoFn logs a message from a func at level Info on the standard logger.
Infoln logs a message at level Info on the standard logger.
IsLevelEnabled checks if the log level of the standard logger is greater than the level param
Creates a new logger. Configuration should be set by changing `Formatter`, `Out` and `Hooks` directly on the default logger instance. You can also just instantiate your own: var log = &logrus.Logger{ Out: os.Stderr, Formatter: new(logrus.TextFormatter), Hooks: make(logrus.LevelHooks), Level: logrus.DebugLevel, } It's recommended to make this a global instance called `log`.
func NewEntry(logger *Logger) *Entry
Panic logs a message at level Panic on the standard logger.
Panicf logs a message at level Panic on the standard logger.
PanicFn logs a message from a func at level Panic on the standard logger.
Panicln logs a message at level Panic on the standard logger.
ParseLevel takes a string level and returns the Logrus log level constant.
Print logs a message at level Info on the standard logger.
Printf logs a message at level Info on the standard logger.
PrintFn logs a message from a func at level Info on the standard logger.
Println logs a message at level Info on the standard logger.
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.
SetBufferPool allows to replace the default logrus buffer pool to better meets the specific needs of an application.
SetFormatter sets the standard logger formatter.
SetLevel sets the standard logger level.
SetOutput sets the standard logger output.
SetReportCaller sets whether the standard logger will include the calling method as a field.
Trace logs a message at level Trace on the standard logger.
Tracef logs a message at level Trace on the standard logger.
TraceFn logs a message from a func at level Trace on the standard logger.
Traceln logs a message at level Trace on the standard logger.
Warn logs a message at level Warn on the standard logger.
Warnf logs a message at level Warn on the standard logger.
WarnFn logs a message from a func at level Warn on the standard logger.
Warning logs a message at level Warn on the standard logger.
Warningf logs a message at level Warn on the standard logger.
WarningFn logs a message from a func at level Warn on the standard logger.
Warningln logs a message at level Warn on the standard logger.
Warnln logs a message at level Warn on the standard logger.
WithContext creates an entry from the standard logger and adds a context to it.
WithError creates an entry from the standard logger and adds an error to it, using the value defined in ErrorKey as key.
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.
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.
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.
Package-Level Variables (total 9, in which 2 are exported)
A constant exposing all logging levels
Defines the key when adding errors using WithError.
Package-Level Constants (total 21, in which 13 are exported)
DebugLevel level. Usually only enabled when debugging. Very verbose logging.
ErrorLevel level. Logs. Used for errors that should definitely be noted. Commonly used for hooks to send errors to an error tracking service.
FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the logging level is set to Panic.
Default key names for the default fields
Default key names for the default fields
Default key names for the default fields
Default key names for the default fields
Default key names for the default fields
Default key names for the default fields
InfoLevel level. General operational entries about what's going on inside the application.
PanicLevel level, highest level of severity. Logs and then calls panic with the message passed to Debug, Info, ...
TraceLevel level. Designates finer-grained informational events than the Debug.
WarnLevel level. Non-critical entries that deserve eyes.