logger

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package logger is a helper package for logging

Index

Constants

View Source
const (
	// BinaryDebugLogging is the environment variable that can be used to enable debug logging in a binary
	BinaryDebugLogging environment.Name = "PACKAGED__DEBUG_LOG"
)

Variables

This section is empty.

Functions

func DPanic

func DPanic(config *zap.Config)

DPanic sets the log level to dpanic

func Debug

func Debug(config *zap.Config)

Debug sets the log level to debug

func DisableCaller

func DisableCaller(config *zap.Config)

DisableCaller disables the caller in the log output

func DisableStacktrace

func DisableStacktrace(config *zap.Config)

DisableStacktrace disabled stack traces in the log output

func Error

func Error(config *zap.Config)

Error sets the log level to error

func Fatal

func Fatal(config *zap.Config)

Fatal sets the log level to fatal

func Info

func Info(config *zap.Config)

Info sets the log level to info

func ObserverForTest

func ObserverForTest() *observer.ObservedLogs

ObserverForTest returns an observer for the global logger instance if it exists

func Panic

func Panic(config *zap.Config)

Panic sets the log level to panic

func Replace

func Replace(logger *Logger)

Replace replaces the global logger instance

func Setup

func Setup(env environment.Environment) error

Setup the global logger instance

func Warn

func Warn(config *zap.Config)

Warn sets the log level to warn

func WithConsoleEncoding

func WithConsoleEncoding(config *zap.Config)

WithConsoleEncoding sets the encoding to console

func WithGoogleEncoding

func WithGoogleEncoding(cfg *zap.Config)

WithGoogleEncoding sets the encoding to google cloud logging format

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a wrapper around zap.Logger

func I

func I() *Logger

I global logger instance

func InstanceWithConfig

func InstanceWithConfig(env environment.Environment, cfg zap.Config, options ...Option) (*Logger, error)

InstanceWithConfig creates a new logger instance with the provided config & options applied

func (*Logger) AddCommon

func (l *Logger) AddCommon(fields ...zap.Field)

AddCommon adds common fields to the logger

func (*Logger) Clone

func (l *Logger) Clone() *Logger

Clone clones the logger instance

func (*Logger) DPanic

func (l *Logger) DPanic(msg string, fields ...zap.Field)

DPanic logs a message at DPanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

If the logger is in development mode, it then panics (DPanic means "development panic"). This is useful for catching errors that are recoverable, but shouldn't ever happen.

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zap.Field)

Debug logs a message at DebugLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...zap.Field)

Error logs a message at ErrorLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func (*Logger) ErrorIf

func (l *Logger) ErrorIf(err error, msg string, fields ...zap.Field)

ErrorIf logs a message at ErrorLevel if the error is not nil

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...zap.Field)

Fatal logs a message at FatalLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then calls os.Exit(1), even if logging at FatalLevel is disabled.

func (*Logger) FatalIf

func (l *Logger) FatalIf(err error, msg string, fields ...zap.Field)

FatalIf logs a fatal message if the error is not nil

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zap.Field)

Info logs a message at InfoLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...zap.Field)

Panic logs a message at PanicLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

The logger then panics, even if logging at PanicLevel is disabled.

func (*Logger) Sync

func (l *Logger) Sync()

Sync calls the underlying Core's Sync method, flushing any buffered log entries. Applications should take care to call Sync before exiting.

func (*Logger) TimedLog added in v3.1.0

func (l *Logger) TimedLog(tl *TimedLog)

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zap.Field)

Warn logs a message at WarnLevel. The message includes any fields passed at the log site, as well as any fields accumulated on the logger.

type Option

type Option func(config *zap.Config)

Option is a function that can be used to configure a zap.Config

type TimedLog added in v3.1.0

type TimedLog struct {
	// contains filtered or unexported fields
}

func NewTimedLog added in v3.1.0

func NewTimedLog(cnf *TimedLogConfig, message string, fields ...zap.Field) *TimedLog

func (*TimedLog) Complete added in v3.1.0

func (tl *TimedLog) Complete()

type TimedLogConfig added in v3.1.0

type TimedLogConfig struct {
	ErrorDuration time.Duration
	WarnDuration  time.Duration
	InfoDuration  time.Duration
	DebugDuration time.Duration
}

func DefaultTimedLogConfig added in v3.1.0

func DefaultTimedLogConfig() *TimedLogConfig

func (*TimedLogConfig) NewLog added in v3.1.0

func (c *TimedLogConfig) NewLog(message string, fields ...zap.Field) *TimedLog

Jump to

Keyboard shortcuts

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