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

# README

go-logger

Go Reference

This is a fork of the logger from gmkit.

A structured, leveled logger. Output is logfmt by default.

Usage

Minimal configuration

l := logger.New()

l.Info("some message", "anotherkey", "another value")

// Output would resemble:
// ts=2023-04-21T16:09:00.026753Z caller=github.com/jasonhancock/go-logger_test/example_test.go:43 src=go-logger.test level=info msg="some message" anotherkey="another value"

Customized config

l := logger.New(
	logger.WithDestination(os.Stdout),
	logger.WithName("myapp"),
	logger.WithLevel("info"),
	logger.WithFormat(logger.FormatLogFmt),
	logger.With("somekey", "someval"),
)

l.Info("some message", "anotherkey", "another value")

// Output would resemble:
// ts=2023-04-13T17:38:13.516398Z caller=github.com/jasonhancock/go-logger_test/example_test.go:11 somekey=someval src=myapp level=info msg="some message" anotherkey="another value"

JSON

l := logger.New(
	logger.WithFormat(logger.FormatJSON),
	logger.WithName("myapp"),
)

l.Info("some message", "anotherkey", "another value")

// Output would resemble:
// {"anotherkey":"another value","caller":"github.com/jasonhancock/go-logger_test/example_test.go:32","level":"info","msg":"some message","src":"myapp","ts":"2023-04-21T16:08:24.224597Z"}

Using the default logger

l := logger.Default()
l.Info("some message")

// Output would resemble:
// ts=2023-04-21T16:09:28.653472Z caller=github.com/jasonhancock/go-logger_test/example_test.go:51 src=default level=info msg="some message"

# Functions

Default returns a default logger implementation.
New initializes a new logger.
ParseLevel parses the string into a Level.
Silence returns a logger that writes everything to /dev/null.
With adds key value pairs to the logger.
WithAutoCallerPrefixTrim intelligently figures out the prefix to trim from the caller value of each log message.
WithCaller sets whether or not to include the source file and line number of where the message originated.
WithCallerPrefixTrim manually specifies a path to trim from the caller value of each log message.
WithDestination sets the target for where the output of the logger should be written.
WithFormat sets the format to log in.
WithLevel sets the logging level of the logger.
WithName specifies the name of the application.
WithTimeLocation specifies the locale to log the time in.

# Constants

Constants defining various output formats.
Constants defining various output formats.
No description provided by the author
No description provided by the author

# Variables

AvailableFormats lists the available format types.

# Structs

L is the logger implementation.

# Type aliases

Option is used to customize the logger.
No description provided by the author