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 ¶
- func ClearContextAttrs(ctx context.Context) context.Context
- func ContextWithAttrs(ctx context.Context, attr ...slog.Attr) context.Context
- func Initialize(env string)
- func Label(key, value string) slog.Attr
- func LoggerWithContext(logger *slog.Logger, ctx context.Context) *slog.Logger
- func NewContextLogHandler(handler slog.Handler) slog.Handler
- func NewWriter(ctx context.Context, logger *slog.Logger, level slog.Level) io.WriteCloser
- type LoggingEnv
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithAttrs ¶
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 ¶
Label causes attributes written by zapdriver to be marked as labels inside StackDriver when LoggingEnv is LoggingEnvProd. Otherwise it wraps slog.String.
func LoggerWithContext ¶
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.
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.