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 ContextWithAttrs(ctx context.Context, attr ...slog.Attr) context.Context
- func Debug(msg string, keysAndValues ...interface{})deprecated
- func Error(msg string, keysAndValues ...interface{})deprecated
- func Fatal(msg string, keysAndValues ...interface{})deprecated
- func GetDefaultLogger() *zap.SugaredLoggerdeprecated
- func Info(msg string, keysAndValues ...interface{})deprecated
- func Initialize(env string) *zap.SugaredLogger
- func Label(key, value string) zap.Fielddeprecated
- func LabelAttr(key, value string) slog.Attr
- func NewContextLogHandler(handler slog.Handler) slog.Handler
- func NewWriter(logger *zap.Logger, level zapcore.Level) io.WriteCloser
- func Warn(msg string, keysAndValues ...interface{})deprecated
- func Writer(level Level, keysAndValues ...interface{}) io.WriteCloserdeprecated
- type Leveldeprecated
- 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 GetDefaultLogger
deprecated
func GetDefaultLogger() *zap.SugaredLogger
Deprecated: do not use global logger
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 LabelAttr ¶
LabelAttr causes attributes written by zapdriver to be marked as labels inside StackDriver when LoggingEnv is LoggingEnvProd. Otherwise it wraps slog.String.
func NewContextLogHandler ¶
NewContextLogHandler returns a new slog.Handler that will pass the attrs set using ContextWithAttrs to handler when Handle is called.
func NewWriter ¶
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 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
Level represents a specific logging level. It wraps zapcore.Level.
Deprecated: use zapcore.Level directly.
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.