Categorygithub.com/hamba/logger/v2
modulepackage
2.8.0
Repository: https://github.com/hamba/logger.git
Documentation: pkg.go.dev

# README

Logo

Go Report Card Build Status Coverage Status Go Reference GitHub release GitHub license

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.

# Type aliases

Field is a context field.
Level represents the predefined log level.