There are five levels
// LOG levels
const (
Info = iota
Warn
Err
Debug
Trace
)
If defined level is less than level that called method is expecting, than message will not be logged. It provide you ability to increase verbosity of logs.
Example
log := litelog.New(
litelog.WithWriter(os.Stderr) // default os.Stdout
litelog.WithLevel(litelog.Warn) // default Info
)
log.Error("some error message") // will not be logged
log.Debug("some debug message") // will not be logged
log.Info("some info message") // will be logged ("[INFO] some info message")
log.Warn("some warn message") // will be logged ("[WARN] some info message")
Package provide ability to add:
- Time prefix with
litelog.WithTime(layout ...string)
method. Layout is a some time package layout const layout parameter can be empty, thanlitelog.WithTime()
method will settime.RFC3339
layout - Custom text prefix before message with
litelog.WithPrefix(pr string)
method. - Custom io.Writer object where Logger will be write mesages with
litelog.WithWriter(wr io.Writer)
method (By default os.Stdout). - Log level with
litelog.WithLevel(lev int)
method.
Info(msg string)
prints message if current level is more or equal Info with "[INFO]" prefixInfof(msg string, args ...interface{})
prints formatted message if current level is more or equal Info with "[INFO]" prefixWarn(msg string)
prints message if current level is more or equal Warn with "[WARN]" prefixWarnf(msg string, args ...interface{})
prints formatted message if current level is more or equal Warn with "[WARN]" prefixError(msg string)
prints message if current level is more or equal Err with "[ERROR]" prefixErrorf(msg string, args ...interface{})
prints formatted message if current level is more or equal Err with "[ERROR]" prefixDebug(msg string)
prints message if current level is more or equal Debug with "[DEBUG]" prefixDebugf(msg string, args ...interface{})
prints formatted message if current level is more or equal Debug with "[DEBUG]" prefixTrace(msg string)
prints message if current level is more or equal Trace with "[TRACE]" prefixTracef(msg string, args ...interface{})
prints formatted message if current level is equal Trace with "[TRACE]" prefix
Println(msg string)
prints message in provided io.WriterPrintf(msg string, args ...interface{})
prints formatted message in provided io.WriterFatal(msg string)
prints message and exit with status code 1Fatalf(msg string, args ...interface{})
prints formatted message and exit with status code 1