Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var LoggerConfig = Config{}
LoggerConfig holds the global logging configuration instance. This can be modified to set the desired logging settings across the application.
Functions ¶
func SetDefaultContext ¶
SetDefaultContext sets a default context that may include logging configurations.
func SetDefaultLogger ¶
func SetDefaultLogger(l Logger)
SetDefaultLogger sets a global Logger instance.
func ToContext ¶
ToContext attaches a Logger to a given context for retrieval in other parts of the app.
func TraceLevelEncoder ¶
func TraceLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)
TraceLevelEncoder formats trace-level messages distinctly for higher visibility.
Types ¶
type Config ¶
type Config struct { Level string // Level defines the logging severity (e.g., "info", "debug"). IsJson bool // IsJson determines if the log output should be in JSON format. }
Config defines the logging configuration structure. Level sets the logging level (e.g., "info", "debug", "error"). IsJson toggles between JSON format (true) or plain text format (false) for log output.
type LogLevel ¶
type LogLevel uint8
LogLevel defines the severity of logs, from Panic (highest) to Trace (lowest).
const ( // PanicLevel is the highest severity; logs and then panics. PanicLevel LogLevel = iota // FatalLevel logs and then exits the application. FatalLevel // ErrorLevel is for errors that require attention. ErrorLevel // WarnLevel is for non-critical issues that need monitoring. WarnLevel // InfoLevel is for general operational information. InfoLevel // DebugLevel is for detailed debugging information. DebugLevel // TraceLevel is for the most granular level of information. TraceLevel )
func Text2Level ¶
Text2Level converts a string log level to a LogLevel enum for structured logging.
type Logger ¶
type Logger interface { // Info writes an informational message. Info(...interface{}) // Infof writes a formatted informational message. Infof(string, ...interface{}) // Infow writes an informational message with key-value pairs for context. Infow(string, ...interface{}) // Warn writes a warning message. Warn(...interface{}) // Warnf writes a formatted warning message. Warnf(string, ...interface{}) // Warnw writes a warning message with key-value pairs for context. Warnw(string, ...interface{}) // Error writes an error message. Error(...interface{}) // Errorf writes a formatted error message. Errorf(string, ...interface{}) // Errorw writes an error message with key-value pairs for context. Errorw(string, ...interface{}) // Debug writes a debug message. Debug(...interface{}) // Debugf writes a formatted debug message. Debugf(string, ...interface{}) // Debugw writes a debug message with key-value pairs for context. Debugw(string, ...interface{}) // Fatal writes a fatal message and typically triggers application exit. Fatal(...interface{}) // Fatalf writes a formatted fatal message. Fatalf(string, ...interface{}) // With adds fields for structured logging to all subsequent logs. With(f ...interface{}) Logger // Check returns true if the log level is enabled for the logger instance. Check(level LogLevel) bool // Print logs a general message without a specific severity. Print(v ...interface{}) // WithField adds a single key-value pair to the Logger instance. WithField(key string, value interface{}) Logger // WithError attaches an error to the Logger instance for context. WithError(err error) Logger // SkipCallers skips a specified number of call stack frames for cleaner logs. SkipCallers(count int) Logger }
Logger is an interface that defines logging methods with various log levels and formats.
func FromContext ¶
FromContext retrieves a Logger from the provided context or falls back to a default logger.
func FromDefaultContext ¶
func FromDefaultContext() Logger
FromDefaultContext returns a Logger instance based on defaultContext settings.
func GetDefaultLogger ¶
func GetDefaultLogger() Logger
GetDefaultLogger returns the global Logger instance or initializes it based on LoggerConfig.