Documentation ¶
Index ¶
- Constants
- Variables
- func AddLogConsFlags()
- func AddLogFileFlags()
- func Crit(msg string, ctx ...interface{})
- func CtxWith(ctx context.Context, logger Logger) context.Context
- func Debug(msg string, ctx ...interface{})
- func Error(msg string, ctx ...interface{})
- func FilterTraceHandler(handler log15.Handler) log15.Handler
- func Flush()
- func Info(msg string, ctx ...interface{})
- func Log(lvl Lvl, msg string, ctx ...interface{})
- func LogPanicAndExit()
- func RandId(idlen int) string
- func SetupFromFlags(name string) error
- func SetupLogConsole(logLevel string) error
- func SetupLogFile(name string, logDir string, logLevel string, logSize int, logAge int, ...) error
- func Trace(msg string, ctx ...interface{})
- func Warn(msg string, ctx ...interface{})
- type Handler
- type Logger
- type Lvl
Constants ¶
const ( DefaultConsoleLevel = "crit" DefaultFileLevel = "debug" DefaultFileSizeMiB = 50 DefaultFileMaxAgeDays = 7 DefaultFileMaxBackups = 10 DefaultFileFlushSeconds = 5 )
const ( LvlCrit = Lvl(log15.LvlCrit) LvlError = Lvl(log15.LvlError) LvlWarn = Lvl(log15.LvlWarn) LvlInfo = Lvl(log15.LvlInfo) LvlDebug = Lvl(log15.LvlDebug) )
const ( LvlTraceStr = "trace" // TraceMsgPrefix is prepended to TRACE level logging messages. TraceMsgPrefix = "[TRACE] " )
Variables ¶
var (
ConsoleLevel = DefaultConsoleLevel
)
Functions ¶
func AddLogConsFlags ¶
func AddLogConsFlags()
func AddLogFileFlags ¶
func AddLogFileFlags()
func CtxWith ¶ added in v0.4.0
CtxWith returns a new context, based on ctx, that embeds argument logger. The logger can be recovered using GetLogger. Attaching a logger to a context which already contains one will overwrite the existing value.
func FilterTraceHandler ¶ added in v0.4.0
func LogPanicAndExit ¶
func LogPanicAndExit()
func SetupFromFlags ¶
func SetupLogConsole ¶
SetupLogConsole sets up logging on default stderr. logLevel can be one of trace, debug, info, warn, error, and crit, and states the minimum level of logging events that gets printed to the console.
func SetupLogFile ¶
func SetupLogFile(name string, logDir string, logLevel string, logSize int, logAge int, logBackups int, logFlush int) error
SetupLogFile initializes a file for logging. The path is logDir/name.log if name doesn't already contain the .log extension, or logDir/name otherwise. logLevel can be one of trace, debug, info, warn, error, and crit and states the minimum level of logging events that get written to the file. logSize is the maximum size, in MiB, until the log rotates. logAge is the maximum number of days to retain old log files. logBackups is the maximum number of old log files to retain. If logFlush > 0, logging output is buffered, and flushed every logFlush seconds. If logFlush < 0: logging output is buffered, but must be manually flushed by calling Flush(). If logFlush = 0 logging output is unbuffered and Flush() is a no-op.
Types ¶
type Handler ¶
func DiscardHandler ¶
func DiscardHandler() Handler
type Logger ¶
type Logger interface { New(ctx ...interface{}) Logger GetHandler() Handler SetHandler(h Handler) Trace(msg string, ctx ...interface{}) Debug(msg string, ctx ...interface{}) Info(msg string, ctx ...interface{}) Warn(msg string, ctx ...interface{}) Error(msg string, ctx ...interface{}) Crit(msg string, ctx ...interface{}) }