Documentation ¶
Overview ¶
Package logging is intended mostly as a set of helper functions around configuring and using a common logger to provide structured, leveled logging.
Index ¶
- Constants
- func EnableSyslogLogging(logger *logrus.Logger, logBuffer *LogBuffer, logLevel string) error
- func GetLineNumber() int
- func SetLoggerConsoleOutput(logger *logrus.Logger, consoleOutput string) error
- func SetLoggerFormatter(logger *logrus.Logger, format string) error
- func SetLoggerLevel(logger *logrus.Logger, logLevel string) error
- func SetLoggerLogFile(logger *logrus.Logger, logFilePath string) (*os.File, error)
- type LogBuffer
- type LogRecord
Constants ¶
const ( // LogLevelEmergency represents messages at Emergency level. System is // unusable; a panic condition. This level is mapped to logrus.PanicLevel // and syslog.LOG_EMERG. logrus calls panic. LogLevelEmergency string = "emergency" // LogLevelPanic represents messages at Emergency level. System is // unusable; a panic condition. This level is mapped to logrus.PanicLevel // and syslog.LOG_EMERG. logrus calls panic. LogLevelPanic string = "panic" // LogLevelAlert represents a condition that should be corrected // immediately, such as a corrupted system database. This level is mapped // to logrus.FatalLevel and syslog.LOG_ALERT. logrus calls os.Exit(1) LogLevelAlert string = "alert" // LogLevelFatal is used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. // This level is mapped to logrus.FatalLevel and syslog.LOG_ALERT. logrus // calls os.Exit(1) LogLevelFatal string = "fatal" // LogLevelCritical is for critical conditions, such as hard device // errors. This level is mapepd to logrus.FatalLevel and syslog.LOG_CRIT. // logrus calls os.Exit(1) LogLevelCritical string = "critical" // LogLevelError is for errors that should definitely be noted. Commonly // used for hooks to send errors to an error tracking service. This level // maps to logrus.ErrorLevel and syslog.LOG_ERR. LogLevelError string = "error" // LogLevelWarn is for non-critical entries that deserve eyes. This level // maps to logrus.WarnLevel and syslog.LOG_WARNING. LogLevelWarn string = "warn" // LogLevelNotice is for normal but significant conditions; conditions // that are not error conditions, but that may require special handling. // This level maps to logrus.WarnLevel and syslog.LOG_NOTICE. LogLevelNotice string = "notice" // LogLevelInfo is for general application operational entries. This level // maps to logrus.InfoLevel and syslog.LOG_INFO. LogLevelInfo string = "info" // LogLevelDebug is for debug-level messages and is usually on enabled // when debugging. Very verbose logging. This level is mapped to // logrus.DebugLevel and syslog.LOG_DEBUG. LogLevelDebug string = "debug" // LogLevelTrace is for finer-grained informational events than debug. // This level maps to logrus.TraceLevel and syslog.LOG_DEBUG. LogLevelTrace string = "trace" )
Log levels
const ( // LogFormatText represents the logrus text formatter. LogFormatText string = "text" // LogFormatJSON represents the logrus JSON formatter. LogFormatJSON string = "json" )
Log formats used by logrus
const ( // ConsoleOutputStdout represents os.Stdout ConsoleOutputStdout string = "stdout" // ConsoleOutputStderr represents os.Stderr ConsoleOutputStderr string = "stderr" )
Variables ¶
This section is empty.
Functions ¶
func EnableSyslogLogging ¶
EnableSyslogLogging attempts to enable local syslog logging for non-Windows systems. For Windows systems the attempt is skipped.
func GetLineNumber ¶
func GetLineNumber() int
GetLineNumber is a wrapper around runtime.Caller to return only the current line number from the point this function was called. TODO: Find a better location for this utility function
func SetLoggerConsoleOutput ¶
SetLoggerConsoleOutput configures the chosen console output to one of stdout or stderr.
func SetLoggerFormatter ¶
SetLoggerFormatter sets a user-specified logging format for the provided logger object.
func SetLoggerLevel ¶
SetLoggerLevel applies the requested logger level to filter out messages with a lower level than the one configured.
Types ¶
type LogBuffer ¶
type LogBuffer []LogRecord
LogBuffer represents a slice of LogRecord objects
var Buffer LogBuffer
Buffer is a package global instance of LogBuffer intended to ease log message collection for later emission when all required logger settings have been applied.
FIXME: Moved here from Config package What is the best approach to handling this instead of using a package global?