You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
log - Simple leveled logging based on standard log package
Documentation
Benefits
😻 Leveled logging
😚 Simple API
🤝 fmt friendly
👌 Zero dependencies
😮💨 No global logger
👏 No structured logging bullshit
Installation
go get github.com/heartwilltell/log
Leveled logging
The StdLog implements a simple interface:
// Logger formats the message according to standard format specifiers from the fmt package// and writes the message to writer specified by the concrete interface implementation.typeLoggerinterface {
// Error formats and writes the error level message.Error(formatstring, v...any)
// Warning formats and writes the warning level message.Warning(formatstring, v...any)
// Info formats and writes the information level message.Info(formatstring, v...any)
// Debug formats and writes the debug level message.Debug(formatstring, v...any)
}
Usage
👇 The usage is pretty simple. Just create a logger instance and call any of leveled methods.
logger:=log.New()
logger.Info("Listen on port: %d", 8080)
👇 Sets the logging level to debug level.
logger:=log.New(log.WithLevel(log.DBG))
👇 Parses string to level and creates logger with warning level.
level, levelErr:=log.ParseLevel("warning")
iflevelErr!=nil {
// handle error here
}
logger:=log.New(log.WithLevel(level))