Documentation ¶
Overview ¶
Package logger implements a structured logger.
Index ¶
- Constants
- Variables
- func AddBackends(backends ...Backend)
- func Alert(format string, v ...interface{})
- func ClearBackends()
- func Crit(format string, v ...interface{})
- func Debug(format string, v ...interface{})
- func Emerg(format string, v ...interface{})
- func Error(format string, v ...interface{})
- func Info(format string, v ...interface{})
- func Log(level Level, format string, v ...interface{})
- func LookupLevel(c Level) string
- func Notice(format string, v ...interface{})
- func SetColor(color bool)
- func SetFields(fields Fields)
- func SetFormatter(formatter Formatter)
- func SetLevel(level Level)
- func SetTimestampFormat(format string)
- func SetTimestamps(timestamps bool)
- func SetWriter(writer io.Writer)
- func Warning(format string, v ...interface{})
- type Backend
- type Fields
- type Formatter
- type FormatterFunc
- type JSONFormatter
- type Level
- type Logger
- func (l *Logger) Alert(format string, v ...interface{})
- func (l *Logger) Crit(format string, v ...interface{})
- func (l *Logger) Debug(format string, v ...interface{})
- func (l *Logger) Emerg(format string, v ...interface{})
- func (l *Logger) Error(format string, v ...interface{})
- func (l *Logger) Info(format string, v ...interface{})
- func (l *Logger) Log(level Level, format string, v ...interface{})
- func (l *Logger) Notice(format string, v ...interface{})
- func (l *Logger) Warning(format string, v ...interface{})
- type TextFormatter
- type WriterBackend
Constants ¶
const ( // revive:disable:var-naming LOG_EMERG = Level(0) LOG_ALERT = Level(1) LOG_CRIT = Level(2) LOG_ERROR = Level(3) LOG_WARNING = Level(4) LOG_NOTICE = Level(5) LOG_INFO = Level(6) LOG_DEBUG = Level(7) )
Levels as defined by RFC5424.
Variables ¶
var DefaultLogger = &Logger{ Level: LOG_DEBUG, Fields: Fields{}, Backends: []Backend{ DefaultBackend, }, }
DefaultLogger is the default logger instance.
var LevelToString = map[Level]string{ LOG_EMERG: "EMERG", LOG_ALERT: "ALERT", LOG_CRIT: "CRIT", LOG_ERROR: "ERROR", LOG_WARNING: "WARNING", LOG_NOTICE: "NOTICE", LOG_INFO: "INFO", LOG_DEBUG: "DEBUG", }
LevelToString maps levels to string names.
var StringToLevel = map[string]Level{ "LOG_EMERG": LOG_EMERG, "EMERG": LOG_EMERG, "emerg": LOG_EMERG, "0": LOG_EMERG, "LOG_ALERT": LOG_ALERT, "ALERT": LOG_ALERT, "alert": LOG_ALERT, "1": LOG_ALERT, "LOG_CRIT": LOG_CRIT, "CRIT": LOG_CRIT, "crit": LOG_CRIT, "2": LOG_CRIT, "LOG_ERROR": LOG_ERROR, "ERROR": LOG_ERROR, "error": LOG_ERROR, "3": LOG_ERROR, "LOG_WARNING": LOG_WARNING, "WARNING": LOG_WARNING, "warning": LOG_WARNING, "4": LOG_WARNING, "LOG_NOTICE": LOG_NOTICE, "NOTICE": LOG_NOTICE, "notice": LOG_NOTICE, "5": LOG_NOTICE, "LOG_INFO": LOG_INFO, "INFO": LOG_INFO, "info": LOG_INFO, "6": LOG_INFO, "LOG_DEBUG": LOG_DEBUG, "DEBUG": LOG_DEBUG, "debug": LOG_DEBUG, "7": LOG_DEBUG, }
StringToLevel maps common string names to log levels.
Functions ¶
func SetFormatter ¶
func SetFormatter(formatter Formatter)
SetFormatter sets the formatter of the DefaultBackend.
Types ¶
type Backend ¶
Backend describes a logger backend.
var DefaultBackend Backend = &WriterBackend{ Writer: os.Stderr, Formatter: DefaultFormatter, }
DefaultBackend is the default logger backend.
type Fields ¶
type Fields map[string]interface{}
Fields is just an alias for map[string]interface{} with a few convenience methods added.
type Formatter ¶
Formatter describes a log formatter.
var DefaultFormatter Formatter = &TextFormatter{ Timestamps: true, TimestampFormat: "2006-01-02T15:04:05.000000Z", Color: stderrStat.Mode()&os.ModeCharDevice != 0, }
DefaultFormatter is the default log formatter.
type FormatterFunc ¶
FormatterFunc is a function wrapper of Formatter.
func (FormatterFunc) Format ¶
func (f FormatterFunc) Format(fields Fields) string
Format returns log fields formatted as a string.
type JSONFormatter ¶
type JSONFormatter struct { }
JSONFormatter is a simple JSON log formatter.
func (*JSONFormatter) Format ¶
func (f *JSONFormatter) Format(fields Fields) string
Format returns log fields formatted as a string.
type Level ¶
type Level int
Level represents a log level.
func LookupString ¶
LookupString returns a log level from a string.
type TextFormatter ¶
TextFormatter is a simple text log formatter.
func (*TextFormatter) Format ¶
func (f *TextFormatter) Format(fields Fields) string
Format returns log fields formatted as a string.
type WriterBackend ¶
WriterBackend is a basic io.Writer logger backend.
func (*WriterBackend) Write ¶
func (h *WriterBackend) Write(fields Fields) bool
Write writes the log message to the backend.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
backends
|
|
syslog
Package syslog provides a SysLog Logger backend.
|
Package syslog provides a SysLog Logger backend. |
compat
|
|
log
Package log contains a compatibility layer for the system "log" package.
|
Package log contains a compatibility layer for the system "log" package. |
/usr/bin/env true; exec /usr/bin/env go run "$0" "$@"
|
/usr/bin/env true; exec /usr/bin/env go run "$0" "$@" |