structlog

package module
v0.0.0-...-46c649b Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2016 License: MIT Imports: 5 Imported by: 0

README

structlog GoDoc License Build Status Coverage Status

Package structlog provides a simple structured logging facade.

Documentation

Overview

Package structlog provides a simple structured logging facade.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Log(keyvals ...interface{}) error
}

Logger is the fundamental interface for all log operations. Log creates a log event from keyvals, a variadic sequence of alternating keys and values. Implementations must be safe for concurrent use by multiple goroutines. In particular, any implementation of Logger that appends to keyvals or modifies any of its elements must make a copy first.

This interface (and its description) has been copied from go-kit (https://github.com/go-kit/kit/blob/master/log/log.go). Note that application logging callers are not expected to check for errors, see https://github.com/go-kit/kit/issues/164.

var DefaultLogger Logger = StdLogger(1)

DefaultLogger provides a default logger. The default implementation uses the Go standard library logger. To override, set this variable early in the program initialization.

func StdLogger

func StdLogger(calldepth int) Logger

StdLogger returns a logger that logs to the standard logger. Calldepth is the count of the number of frames to skip when computing the file name and line number if Llongfile or Lshortfile is set; a value of 1 will print the details for the caller of Log.

Example
log.SetOutput(os.Stdout)
log.SetFlags(log.Lshortfile)

logger := StdLogger(1)
logger.Log("msg", "the message")
logger.Log("msg", "the message", "p1", 1, "lvl", "error")
logger.Log("msg", "the message", "p1", 1, "lvl", "warn", "p2", "param 2")
logger.Log("msg", "the message", "p1", os.Stderr, "p2", 2)
logger.Log("msg", stringer{})
logger.Log("msg", 123)
Output:

structlog_test.go:15: the message
structlog_test.go:16: error: the message: p1=1
structlog_test.go:17: warn: the message: p1=1 p2="param 2"
structlog_test.go:18: the message: p1="unsupported value type" p2=2
structlog_test.go:19: I'M A STRING
structlog_test.go:20: 123

type LoggerFunc

type LoggerFunc func(...interface{}) error

LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If f is a function with the appropriate signature, LoggerFunc(f) is a Logger object that calls f.

func (LoggerFunc) Log

func (f LoggerFunc) Log(keyvals ...interface{}) error

Log implements Logger by calling f(keyvals...).

Jump to

Keyboard shortcuts

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