Categorygithub.com/scylladb/go-log
modulepackage
0.0.7
Repository: https://github.com/scylladb/go-log.git
Documentation: pkg.go.dev

# README

Log

This is a wrapper over Uber zap library that replaces the sugared logger.

Features:

  • Syslog integration
  • Automatic stacktraces for errors
  • Context aware tracing ID
  • Easy to use
  • Fast!

Example:

logger, err := log.NewProduction(log.Config{
	Mode:  log.SyslogMode,
	Level: zapcore.InfoLevel,
	Encoding: log.JSONEncoding,
})
if err != nil {
	t.Fatal(err)
}
logger.Info(ctx, "Could not connect to database",
	"sleep", 5*time.Second,
	"error", errors.New("I/O error"),
)
logger.Named("sub").Error(ctx, "Unexpected error", "error", errors.New("unexpected"))

Benchmarks

Benchmark results of running against zap and zap sugared loggers on Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz.

BenchmarkZap-4                   2000000               978 ns/op             256 B/op          1 allocs/op
BenchmarkZapSugared-4            1000000              1353 ns/op             528 B/op          2 allocs/op
BenchmarkLogger-4                1000000              1167 ns/op             256 B/op          1 allocs/op

# Packages

No description provided by the author

# Functions

BaseOf unwraps l and returns the base zap.Logger.
CopyTraceID allows for copying the trace ID from a context to another context.
NewDevelopment creates a new logger that writes DebugLevel and above logs to standard error in a human-friendly format.
NewDevelopmentWithLevel creates a new logger that writes level and above logs to standard error in a human-friendly format.
NewLogger creates a new logger backed by a zap.Logger.
NewProduction builds a production Logger based on the configuration.
NewSyslogCore creates a Core that writes logs to a syslog.
ParseEncoding parses an Encoding from a string.
ParseLevel parses an AtomicLevel from a string.
TraceID returns trace ID of the context.
WithFields assigns additional fields to the logging context.
WithNewTraceID returns a new context with a random trace ID.
WithTraceID ensures that the context has a trace ID, if not returns a new context with a random trace ID.

# Constants

No description provided by the author
No description provided by the author
StderrMode logs are written to standard error.
StderrMode logs are written to standard output.

# Variables

NopLogger doesn't log anything.

# Structs

Config specifies log mode and level.
Logger logs messages.
SyslogCore is a zapcore.Core that logs to syslog.

# Type aliases

Encoding specifies log encoding.
Mode specifies logs destination.