log

package
v0.0.0-...-a73b073 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 10 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 ClearContextAttrs

func ClearContextAttrs(ctx context.Context) context.Context

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 Initialize

func Initialize(env string)

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

func Label(key, value string) slog.Attr

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

func LoggerWithContext

func LoggerWithContext(logger *slog.Logger, ctx context.Context) *slog.Logger

LoggerWithContext returns a logger with any attrs in the context passed to the logger.

Note: duplicate attributes may be logged if ctx, or a descendent, is used later in a call to (Debug|Info|Warn|Error)Context on the returned slog.Logger.

If the same context is needed, call ClearContextAttrs on the context to avoid logging the attrs again.

func NewContextLogHandler

func NewContextLogHandler(handler slog.Handler) slog.Handler

func NewWriter

func NewWriter(ctx context.Context, logger *slog.Logger, level slog.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.

Types

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"

	// StraceDebugLogDir is a hardcoded directory that can be used to store
	// the strace debug log, if the strace debug logging feature is enabled
	StraceDebugLogDir = "/straceLogs"
)

func DefaultLoggingEnv

func DefaultLoggingEnv() LoggingEnv

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