Clone this repo:



  1. 970db52 Merge pull request #93 from cryptix/patch-1 by Örjan Persson · 1 year, 3 months ago master
  2. e7ce12d readme: updated import path of wslog by Henry · 1 year, 4 months ago
  3. d2e44aa Merge pull request #89 from nplanel/format-callpath-depth by Örjan Persson · 1 year, 4 months ago
  4. 845ad39 [callpath] add depth (optional) parameter by Nicolas PLANEL · 1 year, 4 months ago
  5. f9dfb79 More explicit wording for by Örjan Persson · 1 year, 4 months ago

Golang logging library

godoc build

Package logging implements a logging infrastructure for Go. Its output format is customizable and supports different logging backends like syslog, file and memory. Multiple backends can be utilized with different log levels per backend and logger.

NOTE: backwards compatibility promise have been dropped for master. Please vendor this package or use for previous version. See changelog for details.


Let's have a look at an example which demonstrates most of the features found in this library.

Example Output

package main

import (


var log = logging.MustGetLogger("example")

// Example format string. Everything except the message has a custom color
// which is dependent on the log level. Many fields have a custom output
// formatting too, eg. the time returns the hour down to the milli second.
var format = logging.MustStringFormatter(
	`%{color}%{time:15:04:05.000} %{shortfunc} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,

// Password is just an example type implementing the Redactor interface. Any
// time this is logged, the Redacted() function will be called.
type Password string

func (p Password) Redacted() interface{} {
	return logging.Redact(string(p))

func main() {
	// For demo purposes, create two backend for os.Stderr.
	backend1 := logging.NewLogBackend(os.Stderr, "", 0)
	backend2 := logging.NewLogBackend(os.Stderr, "", 0)

	// For messages written to backend2 we want to add some additional
	// information to the output, including the used log level and the name of
	// the function.
	backend2Formatter := logging.NewBackendFormatter(backend2, format)

	// Only errors and more severe messages should be sent to backend1
	backend1Leveled := logging.AddModuleLevel(backend1)
	backend1Leveled.SetLevel(logging.ERROR, "")

	// Set the backends to be used.
	logging.SetBackend(backend1Leveled, backend2Formatter)

	log.Debugf("debug %s", Password("secret"))


Using go get

$ go get

After this command go-logging is ready to use. Its source will be in:


You can use go get -u to update the package.


For docs, see or run:

$ godoc

Additional resources

  • wslog -- exposes log messages through a WebSocket.