Documentation
¶
Index ¶
- func DPanicf(msg string, args ...any)
- func Debug(msg string, fields ...zap.Field)
- func Debugf(msg string, args ...any)
- func Error(msg string, fields ...zap.Field)
- func Errorf(msg string, args ...any)
- func Fatal(msg string, fields ...zap.Field)
- func Fatalf(msg string, args ...any)
- func GetLoggerWithoutCaller(cfg Config) (*zap.Logger, error)
- func Info(msg string, fields ...zap.Field)
- func Infof(msg string, args ...any)
- func InitGlobalLogger(cfg Config, callerSkip int) (*zap.Logger, error)
- func IsLevelEnabled(level zapcore.Level) bool
- func New(cfg Config, callerSkip int) (*zap.Logger, error)
- func Panic(msg string, fields ...zap.Field)
- func Panicf(msg string, args ...any)
- func Sugar() *zap.SugaredLogger
- func Warn(msg string, fields ...zap.Field)
- func Warnf(msg string, args ...any)
- type Config
- type LogLevel
- type Mode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DPanicf ¶
DPanicLevel logs are particularly important errors. In development the logger panics after writing the message.
func Fatal ¶
Fatal logs a message at Fatal level with structured fields. The application will terminate immediately.
func Fatalf ¶
Fatalf logs a message at Fatal level using fmt.Sprintf-style formatting. The application will terminate immediately.
func InitGlobalLogger ¶
InitGlobalLogger initializes the global zap logger with the provided configuration and caller skip.
func IsLevelEnabled ¶
IsLevelEnabled checks if a given level is enabled for the main application logger. Ensure mainAppLogger is initialized before calling.
func New ¶
New initializes a zap logger instance with the provided configuration and caller skip. This function is safe to call multiple times but the core logger setup happens only once. It returns the configured logger instance.
Parameters: - cfg: Config structure. - callerSkip: The number of stack frames to skip to find the original caller.
Returns: - *zap.Logger: the configured zap logger instance. - error: any error encountered during logger setup.
Note: This function does NOT automatically set this logger as the global zap logger. You must call zap.ReplaceGlobals() externally if needed.
func Panicf ¶
Panicf logs a message at Panic level using fmt.Sprintf-style formatting. It then panics.
func Sugar ¶
func Sugar() *zap.SugaredLogger
Sugar wraps the Logger to provide a more ergonomic, but slightly slower, API. Sugaring a Logger is quite inexpensive, so it's reasonable for a single application to use both Loggers and SugaredLoggers, converting between them on the boundaries of performance-sensitive code.
Types ¶
type Config ¶
type Config struct {
// Mode sets the environment mode for the logger.
// Accepted values are "development" or "production".
// Defaults to "development" if unspecified.
Mode string
// LogFilePath is the path to the log file used for file logging with rotation.
//
// If provided, logs will be written both to this file and stdout.
// If empty, only stdout will be used.
LogFilePath string
// LogLevel sets the verbosity level of the logger.
//
// Valid values are: "debug", "info", "warn", "error", "fatal" "panic",
// and "dpanic".
// Defaults to "info" if not set.
LogLevel *LogLevel
}
Config defines the configuration for the logger.
It controls the logger’s operating mode, output destinations, and log verbosity. When no file path is specified, logs are printed to stdout only.
func DefaultConfig ¶
func DefaultConfig() Config
type LogLevel ¶
type LogLevel int
A Level is a logging priority. Higher levels are more important.
const ( // DebugLevel logs are typically voluminous, and are usually disabled in // production. LogLevel_Debug LogLevel = -1 // InfoLevel logs are the default logging level. LogLevel_Info LogLevel = 0 // WarnLevel logs are more important than Info, but don't need individual // human review. LogLevel_Warn LogLevel = 1 // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. LogLevel_Error LogLevel = 2 // DPanicLevel logs are particularly important errors. In development the // logger panics after writing the message. LogLevel_DPanic LogLevel = 3 // PanicLevel logs a message, then panics. LogLevel_Panic LogLevel = 4 // FatalLevel logs a message, then calls os.Exit(1). LogLevel_Fatal LogLevel = 5 )
func LogLevelOptions ¶
func LogLevelOptions() []LogLevel
func ParseLogLevelString ¶
func (LogLevel) ToZapLevel ¶
type Mode ¶
type Mode string
Mode can be either "development" or "production"
func ModeOptions ¶
func ModeOptions() []Mode