log

package
v0.1.0-alpha.0...-0b1224c Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package log implements a standard convention for structured logging. Log entries are formatted as K=V pairs. By default, output is written to stdout; this can be changed with SetOutput.

Index

Constants

View Source
const (
	KeyCaller  = "at"      // location of caller
	KeyMessage = "message" // produced by Message
	KeyError   = "error"   // produced by Error
	KeyStack   = "stack"   // used by Printkv to print stack on subsequent lines

)

Conventional key names for log entries

Variables

This section is empty.

Functions

func AddPrefixkv

func AddPrefixkv(ctx context.Context, keyval ...interface{}) context.Context

AddPrefixkv appends keyval to any prefix stored in ctx, and returns a new context with the longer prefix.

func Error

func Error(ctx context.Context, err error, a ...interface{})

Error prints a log entry containing an error message assigned to the "error" key. Optionally, an error message prefix can be included. Prefix arguments are handled as in fmt.Print.

func Fatalkv

func Fatalkv(ctx context.Context, keyvals ...interface{})

Fatalkv is equivalent to Printkv() followed by a call to os.Exit(1).

func Helper

func Helper()

Helper marks the calling function as a log helper function. When logging file and line information, that function will be skipped. Helper may be called simultaneously from multiple goroutines.

func Printf

func Printf(ctx context.Context, format string, a ...interface{})

Printf prints a log entry containing a message assigned to the "message" key. Arguments are handled as in fmt.Printf.

func Printkv

func Printkv(ctx context.Context, keyvals ...interface{})

Printkv prints a structured log entry to stdout. Log fields are specified as a variadic sequence of alternating keys and values.

Duplicate keys will be preserved.

Two fields are automatically added to the log entry: t=[time] and at=[file:line] indicating the location of the caller. Use SkipFunc to prevent helper functions from showing up in the at=[file:line] field.

Printkv will also print the stack trace, if any, on separate lines following the message. The stack is obtained from the following, in order of preference:

  • a KeyStack value with type []byte or *runtime.Frames
  • a KeyError value with type error, using the result of errors.Stack

func RecoverAndLogError

func RecoverAndLogError(ctx context.Context)

RecoverAndLogError must be used inside a defer.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the log output to w. If SetOutput hasn't been called, the default behavior is to write to stdout.

func SetPrefix

func SetPrefix(keyval ...interface{})

SetPrefix sets the global output prefix.

Types

This section is empty.

Directories

Path Synopsis
Package rotation writes and rotates log files.
Package rotation writes and rotates log files.
Package splunk sends log data to a splunk server.
Package splunk sends log data to a splunk server.

Jump to

Keyboard shortcuts

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