Back to godoc.org

Package logger

v0.0.0-...-99c4d88
Latest Go to latest

The highest tagged major version is .

Published: Jul 2, 2020 | Licenses: Apache-2.0 , BSD-2-Clause | Module: github.com/Thoralf-M/hive.go

Index

Constants

const (
	ViperKeyLevel             = "logger.level"
	ViperKeyDisableCaller     = "logger.disableCaller"
	ViperKeyDisableStacktrace = "logger.disableStacktrace"
	ViperKeyEncoding          = "logger.encoding"
	ViperKeyOutputPaths       = "logger.outputPaths"
	ViperKeyDisableEvents     = "logger.disableEvents"
)
const (
	// LevelDebug logs are typically voluminous, and are usually disabled in production.
	LevelDebug = zapcore.DebugLevel
	// LevelInfo is the default logging priority.
	LevelInfo = zapcore.InfoLevel
	// LevelWarn logs are more important than Info, but don't need individual human review.
	LevelWarn = zapcore.WarnLevel
	// LevelError logs are high-priority.
	// If an application is running as expected, there shouldn't be any error-level logs.
	LevelError = zapcore.ErrorLevel
	// LevelPanic logs a message, then panics.
	LevelPanic = zapcore.PanicLevel
	// LevelFatal logs a message, then calls os.Exit(1).
	LevelFatal = zapcore.FatalLevel
)

Variables

var ErrGlobalLoggerAlreadyInitialized = errors.New("global logger already initialized")

ErrGlobalLoggerAlreadyInitialized is returned when InitGlobalLogger is called more than once.

var Events = struct {
	DebugMsg   *events.Event
	InfoMsg    *events.Event
	WarningMsg *events.Event
	ErrorMsg   *events.Event
	PanicMsg   *events.Event
	AnyMsg     *events.Event
}{
	DebugMsg:   events.NewEvent(logCaller),
	InfoMsg:    events.NewEvent(logCaller),
	WarningMsg: events.NewEvent(logCaller),
	ErrorMsg:   events.NewEvent(logCaller),
	PanicMsg:   events.NewEvent(logCaller),
	AnyMsg:     events.NewEvent(logCaller),
}

Events contains all the events that are triggered by the logger.

func InitGlobalLogger

func InitGlobalLogger(config *viper.Viper) error

InitGlobalLogger initializes the global logger from the provided viper config.

func NewEventCore

func NewEventCore(enabler zapcore.LevelEnabler) zapcore.Core

NewEventCore creates a core that publishes log messages as events.

func SetLevel

func SetLevel(l Level)

SetLevel alters the logging level of the global logger.

type Config

type Config struct {
	// Level is the minimum enabled logging level.
	// The default is "info".
	Level string `mapstructure:"level"`
	// DisableCaller stops annotating logs with the calling function's file name and line number.
	// By default, all logs are annotated.
	DisableCaller bool `mapstructure:"disableCaller"`
	// DisableStacktrace disables automatic stacktrace capturing.
	// By default, stacktraces are captured for LevelError and above in production.
	DisableStacktrace bool `mapstructure:"disableStacktrace"`
	// Encoding sets the logger's encoding. Valid values are "json" and "console".
	// The default is "console".
	Encoding string `mapstructure:"encoding"`
	// OutputPaths is a list of URLs, file paths or stdout/stderr to write logging output to.
	// The default is ["stdout"].
	OutputPaths []string `mapstructure:"outputPaths"`
	// DisableEvents prevents log messages from being raced as events.
	// By default, the corresponding events are triggered.
	DisableEvents bool `mapstructure:"disableEvents"`
}

Config holds the settings to configure a root logger instance.

type Level

type Level = zapcore.Level

A Level is a logging priority. Higher levels are more important.

type Logger

type Logger = zap.SugaredLogger

The Logger uses the sugared logger.

func NewExampleLogger

func NewExampleLogger(name string) *Logger

NewExampleLogger builds a Logger that's designed to be only used in tests or examples. It writes debug and above logs to standard out as JSON, but omits the timestamp and calling function to keep example output short and deterministic.

func NewLogger

func NewLogger(name string) *Logger

NewLogger returns a new named child of the global root logger.

func NewNopLogger

func NewNopLogger() *Logger

NewNopLogger returns a no-op Logger. It never writes out logs or internal errors

func NewRootLogger

func NewRootLogger(cfg Config, levelOverride ...zap.AtomicLevel) (*Logger, error)

NewRootLogger creates a new root logger from the provided configuration.

func NewRootLoggerFromViper

func NewRootLoggerFromViper(config *viper.Viper, levelOverride ...zap.AtomicLevel) (*Logger, error)

NewRootLoggerFromViper creates a new root logger from the provided viper configuration.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier