log

package module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2022 License: MIT Imports: 8 Imported by: 12

README

log

Replacement for golang log.

Benchmarks

Take with a bucket of salt.

Debug

go test -bench=. -benchmem -count=1 -parallel 8

goos: linux
goarch: amd64
pkg: github.com/wspowell/log
cpu: AMD Ryzen 9 4900HS with Radeon Graphics         
Benchmark_Context_debug_at_error_level-8                                171908761                6.958 ns/op           0 B/op          0 allocs/op
Benchmark_Context_debug_at_error_level_with_complex_parameters-8        12861198                92.07 ns/op           16 B/op          1 allocs/op
Benchmark_Context_error_at_error_level-8                                   89876             12965 ns/op             656 B/op          7 allocs/op
Benchmark_Context_debug_at_error_level_1000x-8                            176293              6803 ns/op               0 B/op          0 allocs/op
Benchmark_Context_error_at_error_level_1000x-8                                86          13025992 ns/op          656722 B/op       7002 allocs/op
Benchmark_Context_WithContext-8                                           104426             11603 ns/op            1824 B/op         15 allocs/op
Benchmark_Context_Tag-8                                                   145516              8186 ns/op              88 B/op          1 allocs/op
Benchmark_debug_at_error_level-8                                        1000000000               0.8027 ns/op          0 B/op          0 allocs/op
Benchmark_debug_at_error_level_with_complex_parameters-8                14631933                82.25 ns/op           16 B/op          1 allocs/op
Benchmark_error_at_error_level-8                                          254371              4697 ns/op             584 B/op          7 allocs/op
Benchmark_debug_at_error_level_1000x-8                                   1625730               741.1 ns/op             0 B/op          0 allocs/op
Benchmark_error_at_error_level_1000x-8                                       254           4695899 ns/op          584399 B/op       7001 allocs/op
Benchmark_error_at_error_level_1000x_zerolog-8                              2221            531979 ns/op           16011 B/op       1000 allocs/op
Benchmark_NewLog-8                                                       1487022               797.6 ns/op          1320 B/op          9 allocs/op
Benchmark_ConfigCopy_NewLog-8                                            1480128               812.2 ns/op          1320 B/op          9 allocs/op
Benchmark_Tag-8                                                         11105218               101.8 ns/op           102 B/op          1 allocs/op

Release

go test -bench=. -benchmem -count=1 -parallel 8 -tags release

goos: linux
goarch: amd64
pkg: github.com/wspowell/log
cpu: AMD Ryzen 9 4900HS with Radeon Graphics         
Benchmark_Context_debug_at_error_level-8                                165479329                7.276 ns/op           0 B/op          0 allocs/op
Benchmark_Context_debug_at_error_level_with_complex_parameters-8        13082940                92.82 ns/op           16 B/op          1 allocs/op
Benchmark_Context_error_at_error_level-8                                 1800238               666.9 ns/op            32 B/op          2 allocs/op
Benchmark_Context_debug_at_error_level_1000x-8                            170800              6969 ns/op               0 B/op          0 allocs/op
Benchmark_Context_error_at_error_level_1000x-8                              1809            666134 ns/op           32023 B/op       2000 allocs/op
Benchmark_Context_WithContext-8                                           957746              1290 ns/op            1808 B/op         15 allocs/op
Benchmark_Context_Tag-8                                                  7357278               156.0 ns/op            99 B/op          1 allocs/op
Benchmark_debug_at_error_level-8                                        1000000000               0.8073 ns/op          0 B/op          0 allocs/op
Benchmark_debug_at_error_level_with_complex_parameters-8                14169472                84.50 ns/op           16 B/op          1 allocs/op
Benchmark_error_at_error_level-8                                         2184783               544.2 ns/op            16 B/op          1 allocs/op
Benchmark_debug_at_error_level_1000x-8                                   1605920               757.2 ns/op             0 B/op          0 allocs/op
Benchmark_error_at_error_level_1000x-8                                      2229            545037 ns/op           16012 B/op       1000 allocs/op
Benchmark_error_at_error_level_1000x_zerolog-8                              2226            532053 ns/op           16012 B/op       1000 allocs/op
Benchmark_NewLog-8                                                       1425229               821.0 ns/op          1320 B/op          9 allocs/op
Benchmark_ConfigCopy_NewLog-8                                            1458351               814.2 ns/op          1320 B/op          9 allocs/op
Benchmark_Tag-8                                                         11095915               104.3 ns/op           102 B/op          1 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func Error

func Error(ctx context.Context, format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func Fatal

func Fatal(ctx context.Context, format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func Info

func Info(ctx context.Context, format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func Printf

func Printf(ctx context.Context, format string, values ...any)

func Tag

func Tag(ctx context.Context, name string, value any)

func Trace

func Trace(ctx context.Context, format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func Warn

func Warn(ctx context.Context, format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func WithContext

func WithContext(ctx context.Context, config LoggerConfig) context.Context

WithConfig adds a LoggerConfig to the Context which enables new Loggers to be created. This creates a new Logger from the LoggerConfig and adds it as a local Context value.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() *Config

NewConfig with defaults.

func (*Config) Level

func (self *Config) Level() Level

func (*Config) Output added in v0.0.9

func (self *Config) Output() io.Writer

func (*Config) Tags

func (self *Config) Tags() map[string]any

func (*Config) WithLevel added in v0.0.9

func (self *Config) WithLevel(level Level) *Config

func (*Config) WithOutput added in v0.0.9

func (self *Config) WithOutput(output io.Writer) *Config

func (*Config) WithTags added in v0.0.9

func (self *Config) WithTags(tags map[string]any) *Config

type Level

type Level int8
const (
	LevelTrace Level = iota - 1 // Match zerolog levels.
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelPanic
)

func (Level) String

func (self Level) String() string

type Log

type Log struct {
	// contains filtered or unexported fields
}

func DebugLogger added in v0.0.9

func DebugLogger() *Log

DebugLogger returns a new default logger that logs at debug level.

func DefaultLogger added in v0.0.9

func DefaultLogger() *Log

DefaultLogger returns a new default logger that logs at info level.

func ErrorLogger added in v0.0.9

func ErrorLogger() *Log

ErrorLogger returns a new default logger that logs at error level.

func NewLog

func NewLog(config LoggerConfig) *Log

func (*Log) Debug

func (self *Log) Debug(format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func (*Log) Error

func (self *Log) Error(format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func (*Log) Fatal

func (self *Log) Fatal(format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func (*Log) Info

func (self *Log) Info(format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func (*Log) Localize

func (self *Log) Localize() any

Localize Log to the next Context. Called in context.Localize(). This will copy all log tags on to the localized Log value. If a fresh Logger is desired, use WithContext() to override.

func (*Log) Panic

func (self *Log) Panic(format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func (*Log) Printf

func (self *Log) Printf(format string, values ...any)

func (*Log) Tag

func (self *Log) Tag(name string, value any)

func (*Log) Trace

func (self *Log) Trace(format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

func (*Log) Warn

func (self *Log) Warn(format string, values ...any)

nolint:goprintffuncname // reason: keep in line with logger function naming

type Logger

type Logger interface {
	Tag(name string, value any)
	Printf(format string, values ...any)
	Trace(format string, values ...any)
	Debug(format string, values ...any)
	Info(format string, values ...any)
	Warn(format string, values ...any)
	Error(format string, values ...any)
	Fatal(format string, values ...any)
}

type LoggerConfig added in v0.0.9

type LoggerConfig interface {
	Level() Level
	Tags() map[string]any
	Output() io.Writer
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL