Skip to content
Go logging library
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml Put under zgoat May 22, 2019
LICENSE Hello, world May 17, 2019
README.markdown Correct link May 22, 2019
go.mod Rename to zlog May 22, 2019
go.sum Hello, world May 17, 2019
log.go Add Request() to log request parameters Jun 18, 2019
log_test.go Add Request() to log request parameters Jun 18, 2019
output_std.go Add Request() to log request parameters Jun 18, 2019

README.markdown

This project is considered experimental Build Status codecov GoDoc

Go logging library. Canonical import path: zgo.at/zlog.

The main goal is to offer a friendly API which gets out of your way.

Getting the maximum possible amount of performance or zero-allocations are not a goal, although simple benchmarks show it should be Fast Enough™ for most purposes (if not, there are a few max-performance libraries already).

Usage

Basics:

zlog.Print("foo")                  // 15:55:17 foo
zlog.Printf("foo %d", 1)           // 15:55:17 foo 1
zlog.Error(err)                    // 15:55:17 oh noes
zlog.Errorf("foo %d", 1)           // 15:55:17 foo 1

This all does what you expect: output a message to stdout or stderr.

You can add module information and fields for extra information:

log := zlog.Module("test")
log.Print("foo")                    // 15:56:12 test: foo

log = l.Fields(zlog.F{"foo": "bar"})
log.Print("foo")                    // 15:56:55 test: foo key="val"

Debug logs are printed only for modules marked as debug:

zlog.Module("bar").Debug("w00t")   // Prints nothing (didn't enable module "bar").
zlog.Debug("bar")                  // Enable debug logs only for module "bar".
zlog.Module("bar").Debug("w00t")   // 15:56:55 w00t

Trace logs are like debug logs, but are also printed when there is an error.

log := zlog.Module("foo")
log.Trace("useful info")
log.Error(err)
log.ResetTrace()                    // Remove all traces.

This is pretty useful for adding context to errors without clobbering your general log with mostly useless info.

Configuration

Configuration is done by setting the Config variable (usually during initialisation of your app).

It's not possible to configure individual logger instances. It's not often needed, and adds some complexity.

You can’t perform that action at this time.