Documentation
¶
Index ¶
- Variables
- func Debug(args ...interface{})
- func Error(args ...interface{})
- func FormatRFC3339(t time.Time) string
- func Info(args ...interface{})
- func Middleware(next http.Handler) http.Handler
- func Warn(args ...interface{})
- type JSONFormatter
- type Level
- type Logger
- func (l Logger) Debug(args ...interface{})
- func (l Logger) Error(args ...interface{})
- func (l Logger) Fatal(args ...interface{})
- func (l Logger) Fatalf(format string, args ...interface{})
- func (l Logger) Info(args ...interface{})
- func (l Logger) Middleware(next http.Handler) http.Handler
- func (l Logger) Print(args ...interface{})
- func (l Logger) Printf(format string, args ...any)
- func (l Logger) Println(args ...any)
- func (l Logger) Warn(args ...interface{})
- func (l Logger) WithError(err error) Logger
- func (l Logger) WithFields(args ...interface{}) Logger
- func (l Logger) WithLevel(lvl Level) Logger
- type PrettyFormatter
Constants ¶
This section is empty.
Variables ¶
var (
Cyan = []byte{'\033', '[', '3', '6', ';', '1', 'm'}
)
var Default = Logger{ Out: os.Stderr, Level: LevelInfo, }
Default is a shared default logger that logs to os.Stderr at LevelInfo. It is used by the package level functions for their logger.
var IsTTY bool
Functions ¶
func FormatRFC3339 ¶
Types ¶
type JSONFormatter ¶
type Level ¶
type Level int
Level is the log level we're to be writing at. Using an int allows the levels to be compared, so we can check if the log message should be written with easy comparison.
func ParseLevel ¶
ParseLevel parses a string, matching it to a Level. If the input fails to match any known level, it defaults to LevelInfo.
func (Level) Log ¶
Log writes the log line to the provider io.Writer. The first in the args is assumed to be the message, all other pairs are assumed to be key/value pairs of additional detail. If there are an odd number of args (after the first becomes the message) it is dropped. When the args are empty, this function is a noop.
The key/value pairs are all written in alphabetical order. The time, level, and message keys are added to the output.
The time will always be in UTC, formated as RFC3339.
type Logger ¶
Logger is a simple logger that has three levels: Debug, Info, and Error. Other than the name of the levels (and subsequent conditional output) the levels are identical in function. A logger without configuration writes at DebugLevel to os.Stderr.
This may not be the most efficient or featureful logger out there -- it doesn't do colors, doesn't support multiple output formats, doesn't have much in the way of fancy hooks and such -- it just does the bare minimum that I need/want it to do. It *does* provide:
- structured logging with fields
- multiple log levels
- a simple interface
- no external dependencies
If fancier/more-powerful features are needed/wanted... use a different package.
func ForRequest ¶
func WithFields ¶
func WithFields(args ...interface{}) Logger
func (Logger) Debug ¶
func (l Logger) Debug(args ...interface{})
Debug emits logs when the set level is Debug or lower
func (Logger) Error ¶
func (l Logger) Error(args ...interface{})
Error emits logs when the set level is Error or lower
func (Logger) Fatal ¶
func (l Logger) Fatal(args ...interface{})
Fatal emits logs when the set level is Fatal or lower
func (Logger) Info ¶
func (l Logger) Info(args ...interface{})
Info emits logs when the set level is Info or lower
func (Logger) Print ¶
func (l Logger) Print(args ...interface{})
Print emits a log at the current level
func (Logger) Println ¶
Println emits a log at the current level. This is a shim to comply with the Log interface from the stdlib
func (Logger) Warn ¶
func (l Logger) Warn(args ...interface{})
Warn emits logs when the set level is Warn or lower
func (Logger) WithFields ¶
WithFields provides some sugar to build the fields up over time until calling one of the Level-based functions (Debug, et. al.) and all uses of the Logger returned share the same fields.