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 ¶
- type Logger
- func (this *Logger) Fatal(v ...interface{})
- func (this *Logger) Fatalf(format string, v ...interface{})
- func (this *Logger) Fatalln(v ...interface{})
- func (this *Logger) Flags() int
- func (this *Logger) Output(calldepth int, s string) error
- func (this *Logger) Panic(v ...interface{})
- func (this *Logger) Panicf(format string, v ...interface{})
- func (this *Logger) Panicln(v ...interface{})
- func (this *Logger) Prefix() string
- func (this *Logger) Print(v ...interface{})
- func (this *Logger) Printf(format string, v ...interface{})
- func (this *Logger) Println(v ...interface{})
- func (this *Logger) SetFlags(flag int)
- func (this *Logger) SetOutput(w io.Writer)
- func (this *Logger) SetPrefix(prefix string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
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 ¶
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) Fatalln ¶
func (this *Logger) Fatalln(v ...interface{})
Fatalln -> log.Fatalln (except in testing it uses log.Println)