# README
logger is a fast Go logging package made to be simple but effective.
Overview
Install with:
go get github.com/hamba/logger/v2
Formatters
- JSON
- Logfmt
- Console
Writers
- SyncWriter Write synchronised to a Writer
Note: This project has renamed the default branch from master
to main
. You will need to update your local environment.
Examples
log := logger.New(os.Stdout, logger.LogfmtFormat(), logger.Info)
// Logger can have scoped context
log = log.With(ctx.Str("env", "prod"))
// All messages can have a context
log.Warn("connection error", ctx.Str("redis", "dsn_1"), ctx.Int("timeout", conn.Timeout()))
Will log the message
lvl=warn msg="connection error" env=prod redis=dsn_1 timeout=0.500
More examples can be found in the godocs.
# Packages
Package ctx implements log context convenience functions.
# Functions
ConsoleFormat formats a log line in a console format.
JSONFormat formats a log line in json format.
LevelFromString converts a string to Level.
LogfmtFormat formats a log line in logfmt format.
New creates a new Logger.
NewSyncWriter returns a synchronised writer.
# Constants
List of predefined log Levels.
List of predefined log Levels.
List of predefined log Levels.
List of predefined log Levels.
List of predefined log Levels.
LevelKey is the key used for message levels.
MessageKey is the key used for message descriptions.
Time formats.
Time formats.
TimestampKey is the key used for timestamps.
List of predefined log Levels.
List of predefined log Levels.
# Variables
TimeFormat is the format that times will be added in.
# Structs
Event is a log event.
Logger is a logger.
SyncWriter implements a writer that is synchronised with a lock.
# Interfaces
Formatter represents a log message formatter.