logging

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: MIT Imports: 6 Imported by: 12

README

Build Status Code Coverage Go Report Card GoDoc

Documentation

Overview

package logging implements a Logger that, when nil, forwards to the corresponding functions in the standard log package. When not nil, it captures log calls in a buffer for later inspection. This can be useful when needing to inspect or squelch log output from test code. The main advantage to this approach is that it is not necessary to provide a non-nil instance in 'constructor' functions or wireup for production code. It is also still trivial to set a non-nil reference in test code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	*log.Logger

	Log   *bytes.Buffer
	Calls int
}

Logger is meant be included as a pointer field on a struct. Leaving the instance as a nil reference will cause any calls on the *Logger to forward to the corresponding functions from the standard log package. This is meant to be the behavior in production. In testing, set the field to a non-nil instance of a *Logger to record log statements for later inspection.

func Capture

func Capture(writers ...io.Writer) *Logger

Capture creates a new *Logger instance with a multi writer containing an internal buffer as well as any other writers provided as arguments. The prefix and flags default to the values of log.Prefix() and log.Flags(), respectively. This function is meant to be called from test code. See the godoc of the Logger struct for details.

func Discard

func Discard() *Logger

Discard creates a new *Logger instance with its internal buffer set to ioutil.Discard. This is useful if you want your production code to be quiet but your test code to be verbose. In that case, use Discard() in production code and Capture() in test code.

func (*Logger) Fatal

func (this *Logger) Fatal(v ...interface{})

Fatal -> log.Fatal (except in testing it uses log.Print)

func (*Logger) Fatalf

func (this *Logger) Fatalf(format string, v ...interface{})

Fatalf -> log.Fatalf (except in testing it uses log.Printf)

func (*Logger) Fatalln

func (this *Logger) Fatalln(v ...interface{})

Fatalln -> log.Fatalln (except in testing it uses log.Println)

func (*Logger) Flags

func (this *Logger) Flags() int

Flags -> log.Flags

func (*Logger) Output

func (this *Logger) Output(calldepth int, s string) error

Output -> log.Output

func (*Logger) Panic

func (this *Logger) Panic(v ...interface{})

Panic -> log.Panic

func (*Logger) Panicf

func (this *Logger) Panicf(format string, v ...interface{})

Panicf -> log.Panicf

func (*Logger) Panicln

func (this *Logger) Panicln(v ...interface{})

Panicln -> log.Panicln

func (*Logger) Prefix

func (this *Logger) Prefix() string

Prefix -> log.Prefix

func (*Logger) Print

func (this *Logger) Print(v ...interface{})

Print -> log.Print

func (*Logger) Printf

func (this *Logger) Printf(format string, v ...interface{})

Printf -> log.Printf

func (*Logger) Println

func (this *Logger) Println(v ...interface{})

Println -> log.Println

func (*Logger) SetFlags

func (this *Logger) SetFlags(flag int)

SetFlags -> log.SetFlags

func (*Logger) SetOutput

func (this *Logger) SetOutput(w io.Writer)

SetOutput -> log.SetOutput

func (*Logger) SetPrefix

func (this *Logger) SetPrefix(prefix string)

SetPrefix -> log.SetPrefix

Jump to

Keyboard shortcuts

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