# README
slog 
Golang simple logger wrapper. It supports leveled logger with the following levels:
- PANIC, log message and call
panic
- FATAL, log message and exit by calling
os.Exit(1)
- ERROR, log message in
error
level - WARNING, log message in
warning
level - INFO, log message in
info
level - DEBUG, log message in
debug
level - TRACE, log message in
trace
level
Logger implements the following interface:
type Logger interface {
HasLevel(lv Level) bool
SetLevel(lv Level)
// Print like methods
Trace(args ...interface{})
Debug(args ...interface{})
Print(args ...interface{})
Info(args ...interface{})
Warn(args ...interface{})
Error(args ...interface{})
Fatal(args ...interface{})
Panic(args ...interface{})
// Println like methods
Traceln(args ...interface{})
Debugln(args ...interface{})
Println(args ...interface{})
Infoln(args ...interface{})
Warnln(args ...interface{})
Errorln(args ...interface{})
Fatalln(args ...interface{})
Panicln(args ...interface{})
// Printf like methods
Tracef(format string, args ...interface{})
Debugf(format string, args ...interface{})
Printf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Panicf(format string, args ...interface{})
// Log with fields (key=value)
Tracew(msg string, keyVals ...interface{})
Debugw(msg string, keyVals ...interface{})
Printw(msg string, keyVals ...interface{})
Infow(msg string, keyVals ...interface{})
Warnw(msg string, keyVals ...interface{})
Errorw(msg string, keyVals ...interface{})
Fatalw(msg string, keyVals ...interface{})
Panicw(msg string, keyVals ...interface{})
}
Logger
can be initialized with the following constructor
New(name string, w io.Writer, l Level) (Logger, error)
NewWithOptions(w io.Writer, level Level, op Options) (Logger, error)
in which
name
specify logger name. Currently available valuesdiscard
,stdlog
andlogrus
w
logger outputl
logger levelop
loger options
Options
-
discard
, discard log ouput exceptpanic
. Options not supported. -
stdlog
, standar logger options:timestampFormat
: timestamp layout format, seetime.Time
formatdisableColor
: to disable color in log
-
logrus
, support options forlogrus.TextFormatter
formatter andlogrus.JSONFormatter
formatter.formatter
: logrus formatter, eithertext
orjson
. Default format islogrus.TextFormatter
timestampFormat
: timestamp layout format, seetime.Time
formatreportCaller
: if set totrue
, the calling method will be added as a fieldfullTimestamp
: logging the full timestamp instead of elapsed time since application started, default totrue
disableTimestamp
: disable timestamp in logfieldMap
: customize default key namesdataKey
: data key forjson
formatterprettyPrint
: pretty printjson
outputdisableHTMLEscape
: disable HTML escape injson
formatterforceColors
: for color intext
formatterdisableColors
: disable colors intext
formatterforceQuote
: force quote intext
formatterdisableQuote
: disable quote intext
formatterenvironmentOverrideColors
: override color based on environment config intext
formatterdisableSorting
: disable key sorting intext
formatterdisableLevelTruncation
: disable log level string truncation intext
formatterpadLevelText
: add padding in level string intext
formatterquoteEmptyFields
: add quote for empty log entry intext
formatter
Credits
- Color support via https://github.com/fatih/color
- Logrus logger using https://github.com/sirupsen/logrus
License
The MIT License (MIT), see LICENSE.
# Packages
No description provided by the author
# Functions
AsString convers val into string.
AsStringQ convert value into string.
ConstructorFor return sql query for given name.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FieldsToMap convert key-value array to map[string]interface{}.
may be unsafe?.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LevelFixedString return fixed string for given level.
Levels return all level.
LevelCount return number of valid log levels.
MustUse specific logger.
New create new logger with given name.
NewDiscardLogger creates discard logger.
NewLevelLoggerBase return new instance of level logger base.
NewStdLogger creates new logger with given parameters.
NewWithOptions create new logger with given name, and options for spesific logger.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ParseLevel string.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Register logger constructor.
SeparateFields into array of keys and array of values.
No description provided by the author
Simpleformatter return simple key-value formatter, separated with `sep`.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Use specific logger.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
AllLevel contains all log level.
Logger level.
Name of discard logger.
Logger level.
Logger level.
Logger level.
Logger level.
Name of the standard logger.
Logger level.
Logger level.
# Variables
Unknown field name and default logger.
Global discard logger.
Unknown field name and default logger.
# Structs
LevelLogger base.