logger

package
v0.0.0-...-5068cfe Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package logger provides a global logging interface for structured logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlobalLogger

func SetGlobalLogger(l Logger)

SetGlobalLogger sets the global logger instance to the provided Logger.

Types

type Logger

type Logger interface {
	// Debug logs a message at the debug level.
	Debug(format string, args ...interface{})
	// Info logs a message at the info level.
	Info(format string, args ...interface{})
	// Warn logs a message at the warn level.
	Warn(format string, args ...interface{})
	// Error logs a message at the error level.
	Error(format string, args ...interface{})
	// Fatal logs a message at the fatal level. The application will terminate after logging the message.
	Fatal(format string, args ...interface{})
	// Panic logs a message at the panic level. The application will panic after logging the message.
	Panic(format string, args ...interface{})
}

Logger is the interface for structured logging. It provides methods for logging at various levels of severity.

func GetZapDevelopmentLogger

func GetZapDevelopmentLogger(level zap.AtomicLevel) (Logger, error)

GetZapDevelopmentLogger creates and returns a new zap.Logger configured for development use. The development logger is more verbose and is intended for use during development. It uses a console encoder with colored level output and logs at the specified log level.

Parameters:

  • level: The minimum logging level at which logs should be written, e.g., zapcore.DebugLevel, zapcore.InfoLevel.

Returns:

  • Logger: The configured zap.Logger for development use.
  • error: An error if the logger could not be created.

func GetZapLogger

func GetZapLogger(env string, level string) (Logger, error)

GetZapLogger creates and returns a new zap.Logger based on the environment and log level. It supports "development" and "production" environments.

Parameters:

  • env: The environment for the logger, e.g., "development", "production".
  • level: The logging level, e.g., "debug", "info".

Returns:

  • Logger: The configured zap.Logger based on the environment and log level.
  • error: An error if the logger could not be created.

func GetZapProductionLogger

func GetZapProductionLogger(level zap.AtomicLevel) (Logger, error)

GetZapProductionLogger creates and returns a new zap.Logger configured for production use. The production logger is optimized for performance. It uses a JSON encoder, logs to standard error, and writes at InfoLevel and above.

Parameters:

  • level: The minimum logging level at which logs should be written, e.g., zapcore.DebugLevel, zapcore.InfoLevel.

Returns:

  • Logger: The configured zap.Logger for production use.
  • error: An error if the logger could not be created.

func L

func L() Logger

L returns the global logger instance.

type ZapLogger

type ZapLogger struct {
	*zap.Logger
}

ZapLogger is an implementation of the Logger interface using the zap logging library.

func (ZapLogger) Debug

func (z ZapLogger) Debug(msg string, fields ...interface{})

Debug logs a message at the debug level.

func (ZapLogger) Error

func (z ZapLogger) Error(msg string, fields ...interface{})

Error logs a message at the error level.

func (ZapLogger) Fatal

func (z ZapLogger) Fatal(msg string, fields ...interface{})

Fatal logs a message at the fatal level and then calls os.Exit(1).

func (ZapLogger) Info

func (z ZapLogger) Info(msg string, fields ...interface{})

Info logs a message at the info level.

func (ZapLogger) Panic

func (z ZapLogger) Panic(msg string, fields ...interface{})

Panic logs a message at the panic level and then panics.

func (ZapLogger) Warn

func (z ZapLogger) Warn(msg string, fields ...interface{})

Warn logs a message at the warn level.

Jump to

Keyboard shortcuts

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