Help us shape the future of Go! Take the 2026 Go Developer Survey

flash

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 5 Imported by: 6

README

Go Report Card Coverage Status Build Status PkgGoDev

flash

Creates an opinionated zap logger.

Logger Without Stacktrace

New Logger

Debug / Info / Error

2020-10-09T09:29:06.363+0200    INFO    test/main.go:26 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:06.364+0200    ERROR   test/main.go:27 message {"StackTrace": "off", "debug": false}
Enable Debug

Debug / Info / Error

2020-10-09T09:29:06.364+0200    DEBUG   test/main.go:33 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:06.364+0200    INFO    test/main.go:34 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:06.364+0200    ERROR   test/main.go:35 message {"StackTrace": "off", "debug": true}
Disable Debug

Debug / Info / Error

2020-10-09T09:29:06.364+0200    INFO    test/main.go:42 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:06.364+0200    ERROR   test/main.go:43 message {"StackTrace": "off", "debug": false}

Fatal

2020-10-09T09:29:06.364+0200    FATAL   test/main.go:47 message {"StackTrace": "on", "debug": false}
exit status 1

Logger With Stacktrace

New Logger

Debug / Info / Error

2020-10-09T09:29:11.889+0200    INFO    test/main.go:26 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:11.889+0200    ERROR   test/main.go:27 message {"StackTrace": "off", "debug": false}
Enable Debug (Stacktrace on Error or above)

Debug / Info / Error

2020-10-09T09:29:11.889+0200    DEBUG   test/main.go:33 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:11.889+0200    INFO    test/main.go:34 message {"StackTrace": "off", "debug": true}
2020-10-09T09:29:11.889+0200    ERROR   test/main.go:35 message {"StackTrace": "off", "debug": true}
main.main
        /export/home/sauterm/tmp/test/main.go:35
runtime.main
        /export/home/sauterm/.gimme/versions/go1.15.2.linux.amd64/src/runtime/proc.go:204
Disable Debug (Stacktrace on Fatal only)

Debug / Info / Error

2020-10-09T09:29:11.889+0200    INFO    test/main.go:42 message {"StackTrace": "off", "debug": false}
2020-10-09T09:29:11.889+0200    ERROR   test/main.go:43 message {"StackTrace": "off", "debug": false}

Fatal

2020-10-09T09:29:11.889+0200    FATAL   test/main.go:47 message {"StackTrace": "on", "debug": false}
main.main
        /export/home/sauterm/tmp/test/main.go:47
runtime.main
        /export/home/sauterm/.gimme/versions/go1.15.2.linux.amd64/src/runtime/proc.go:204
exit status 1

Documentation

Overview

Package flash configures an opinionated zap logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}

Logger is the flash logger which embeds a `zap.SugaredLogger`.

func New

func New(opts ...Option) *Logger

New creates a new Logger. If no options are specified, stacktraces and color output are disabled and the confgured level is `InfoLevel`.

func (*Logger) Disable

func (l *Logger) Disable()

Disable disables (nearly) all output. Only `FatalLevel` errors are logged.

func (*Logger) Get

func (l *Logger) Get() *zap.SugaredLogger

Get returns the embedded zap.Logger

func (*Logger) SetDebug

func (l *Logger) SetDebug(d bool)

SetDebug enables or disables `DebugLevel`.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level zapcore.Level)

SetLevel sets the chosen level. If stacktraces are enabled, it adjusts stacktrace levels accordingly.

type Option

type Option func(c *config)

Option configures zap.Config.

func WithColor

func WithColor() Option

WithColor enables color output.

func WithDebug

func WithDebug(debug bool) Option

WithDebug enables or disables `DebugLevel`.

func WithPrometheus

func WithPrometheus(appName string, registry prometheus.Registerer) Option

WithPrometheus registers a prometheus log message counter.

The created metrics are of the form:

<appName>_log_messages_total{level="info"} 4

func WithSinks added in v0.2.0

func WithSinks(sinks ...string) Option

WithSinks changes the default zap `stderr` sink.

func WithStacktrace

func WithStacktrace() Option

WithStacktrace completely enables automatic stacktrace capturing. Stacktraces are captured on `ErrorLevel` and above when in debug mode. When not in debug mode, only `FatalLevel` messages contain stacktraces.

func WithoutCaller

func WithoutCaller() Option

WithoutCaller stops annotating logs with the calling function's file name and line number.

Jump to

Keyboard shortcuts

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