log

package
v0.0.0-...-892e02c Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package log wraps Uber's Zap logging library to make it easy to use across the project.

Initialize() MUST be called before the first logging statement, if it is not called the command will panic and exit.

See the Zap docs for more details: https://pkg.go.dev/go.uber.org/zap

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithAttrs

func ContextWithAttrs(ctx context.Context, attr ...slog.Attr) context.Context

ContextWithAttrs is used to add attrs to the context so they are included when logs are output.

func Debug deprecated

func Debug(msg string, keysAndValues ...interface{})

Debug is a convenience wrapper for calling Debugw on the default zap.SugaredLogger instance.

Deprecated: Call slog.DebugContext instead.

func Error deprecated

func Error(msg string, keysAndValues ...interface{})

Error is a convenience wrapper for calling Errorw on the default zap.SugaredLogger instance.

Deprecated: Call slog.ErrorContext instead.

func Fatal deprecated

func Fatal(msg string, keysAndValues ...interface{})

Fatal is a convenience wrapper for calling Fatalw on the default zap.SugaredLogger instance.

Deprecated: Call slog.ErrorContext, followed by os.Exit instead.

func GetDefaultLogger deprecated

func GetDefaultLogger() *zap.SugaredLogger

Deprecated: do not use global logger

func Info deprecated

func Info(msg string, keysAndValues ...interface{})

Info is a convenience wrapper for calling Infow on the default zap.SugaredLogger instance.

Deprecated: Call slog.InfoContext instead.

func Initialize

func Initialize(env string) *zap.SugaredLogger

Initialize the logger for logging.

Passing in "true" will use Zap's default production configuration, while "false" will use the default development configuration.

Note: this method MUST be called before any other method in this package.

func Label deprecated

func Label(key, value string) zap.Field

Label is a convenience wrapper for zapdriver.Label if the LoggingEnv used is LoggingEnvProd. Otherwise it will wrap zap.String.

Deprecated: Call LabelAttr instead.

func LabelAttr

func LabelAttr(key, value string) slog.Attr

LabelAttr causes attributes written by zapdriver to be marked as labels inside StackDriver when LoggingEnv is LoggingEnvProd. Otherwise it wraps slog.String.

func NewContextLogHandler

func NewContextLogHandler(handler slog.Handler) slog.Handler

NewContextLogHandler returns a new slog.Handler that will pass the attrs set using ContextWithAttrs to handler when Handle is called.

func NewWriter

func NewWriter(logger *zap.Logger, level zapcore.Level) io.WriteCloser

NewWriter returns an io.WriteCloser that logs each line written as a single log entry at the given level with the supplied keysAndValues.

Close() must be called to free up the resources used and flush any unwritten log entries to the logger.

func Warn deprecated

func Warn(msg string, keysAndValues ...interface{})

Warn is a convenience wrapper for calling Warnw on the default zap.SugaredLogger instance.

Deprecated: Call slog.WarnContext instead.

func Writer deprecated

func Writer(level Level, keysAndValues ...interface{}) io.WriteCloser

Writer returns an io.WriteCloser that logs each line written as a single log entry at the given level with the supplied keysAndValues.

Close() must be called to free up the resources used and flush any unwritten log entries to the logger.

Deprecated: use NewWriter with zap.Logger and zapcore.Level directly.

Types

type Level deprecated

type Level zapcore.Level

Level represents a specific logging level. It wraps zapcore.Level.

Deprecated: use zapcore.Level directly.

const (
	DebugLevel Level = Level(zapcore.DebugLevel)
	InfoLevel  Level = Level(zapcore.InfoLevel)
	WarnLevel  Level = Level(zapcore.WarnLevel)
	ErrorLevel Level = Level(zapcore.ErrorLevel)
	FatalLevel Level = Level(zapcore.FatalLevel)
)

type LoggingEnv

type LoggingEnv string

LoggingEnv is used to represent a specific configuration used by a given environment.

const (
	LoggingEnvDev  LoggingEnv = "dev"
	LoggingEnvProd LoggingEnv = "prod"
)

func (LoggingEnv) String

func (e LoggingEnv) String() string

String implements the Stringer interface.

Jump to

Keyboard shortcuts

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