logger

package
v0.0.0-...-dbd4bda Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZeriLogger *zap.SugaredLogger

ZeriLogger is a global instance of a SugaredLogger for convenient logging throughout the application.

Functions

func InitLogger

func InitLogger(cfg *Config, opts ...zap.Option) (*zap.SugaredLogger, func())

InitLogger initializes the global ZeriLogger instance based on the provided configuration. It sets up a new zap.Logger according to the specified settings and options. If the logger initialization fails, it logs a fatal error and terminates the application.

Parameters: - cfg: A pointer to a Config struct containing the configuration settings for the logger. - opts: Optional zap options for customizing the logger further.

Returns: - A pointer to the initialized SugaredLogger instance. - A function that can be called to undo the global logger replacement.

Usage example:

cfg := &Config{EnableDevMode: true}
zeriLogger, undo := InitLogger(cfg)
defer undo() // Revert the global logger replacement when done

zeriLogger.Info("Logger initialized successfully")

func NewLoggerWithAttributes

func NewLoggerWithAttributes(attributes Attributes) *zap.SugaredLogger

NewLoggerWithAttributes creates a new SugaredLogger with additional attributes added from the provided map. If the global ZeriLogger is not initialized, it will initialize it with default settings.

Parameters: - attributes: A map of key-value pairs representing additional attributes to include in the logger.

Returns: - A pointer to the SugaredLogger instance with the specified attributes.

Types

type Attributes

type Attributes map[string]any

type Config

type Config struct {
	// DisableCaller specifies whether to omit the caller's file and line number in log messages.
	DisableCaller bool

	// DisableStacktrace specifies whether to disable stacktrace logging on errors.
	DisableStacktrace bool

	// EnableDevMode indicates whether the logger should operate in development mode with more verbose output.
	EnableDevMode bool

	// Level defines the logging level (e.g., debug, info, warn, error).
	Level LevelType

	// Encoding specifies the format for log output (e.g., json, console).
	Encoding EncodingType
}

type EncodingType

type EncodingType string
const (
	EncodingJSON    EncodingType = "json"
	EncodingConsole EncodingType = "console"
)

Log encoding

type LevelType

type LevelType string
const (
	LevelInfo  LevelType = "info"
	LevelWarn  LevelType = "warn"
	LevelDebug LevelType = "debug"
	LevelError LevelType = "error"
)

Log level

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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