Skip to content
/ logger Public

simple structured logging with severity awareness

License

Notifications You must be signed in to change notification settings

xh3b4sd/logger

Repository files navigation

logger

Simple structured logging with severity awareness. Logging is one essential observability technique in order to not fly blindly. Structuring logs is simple and yet powerful because it supports different formats that can be addapted to any application's needs.

Log Level Awareness

There are 4 log levels supported, namely debug, info, warning and error. Logs are emitted based on filter configurations provided to the logger creation. Below is shown which logger setting causes which behaviour of emitted logs.

logger setting emitted logs
debug debug, info, warning, error
info info, warning, error
warning warning, error
error error

Logging In Code

Below is an example of emitting info logs providing information of expected business logic behaviour.

r.log.Log(ctx, "level", "info", "message", "something important happened")

Below is an example of emitting error logs providing information of unexpected business logic behaviour. Note that stack trace logging is wel integrated with tracer.

r.log.Log(ctx, "level", "error", "message", "something bad happened", "stack", tracer.Stack(err))

Log Line Printing

Using logger prints log lines like shown in the example below. Note that you can configure the io.Writer that actually handles the byte streams. The default is configured to be os.Stdout.

{
  "time": "2006-01-02 15:04:05",
  "leve": "info",
  "mess": "something important happened",
  "stac": [
    "--REPLACED--/logger_test.go:104",
    "--REPLACED--/logger_test.go:105"
  ],
  "call": "--REPLACED--/logger_test.go:129"
}

About

simple structured logging with severity awareness

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages