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 Field
- func Any(key string, val any) Field
- func Binary(key string, val []byte) Field
- func Bool(key string, val bool) Field
- func Boolp(key string, val *bool) Field
- func Bools(key string, val []bool) Field
- func ByteString(key string, val []byte) Field
- func ByteStrings(key string, val [][]byte) Field
- func Complex64(key string, val complex64) Field
- func Complex128(key string, val complex128) Field
- func Dict(key string, val ...Field) Field
- func Duration(key string, val time.Duration) Field
- func Durationp(key string, val *time.Duration) Field
- func Durations(key string, val []time.Duration) Field
- func Err(err error) Field
- func Errors(key string, errs []error) Field
- func Float32(key string, val float32) Field
- func Float32p(key string, val *float32) Field
- func Float64(key string, val float64) Field
- func Float64p(key string, val *float64) Field
- func Float64s(key string, val []float64) Field
- func Inline(val zapcore.ObjectMarshaler) Field
- func Int(key string, val int) Field
- func Int8(key string, val int8) Field
- func Int8p(key string, val *int8) Field
- func Int16(key string, val int16) Field
- func Int16p(key string, val *int16) Field
- func Int32(key string, val int32) Field
- func Int32p(key string, val *int32) Field
- func Int64(key string, val int64) Field
- func Int64p(key string, val *int64) Field
- func Int64s(key string, val []int64) Field
- func Ints(key string, val []int) Field
- func Namespace(key string) Field
- func Object(key string, val zapcore.ObjectMarshaler) Field
- func Reflect(key string, val any) Field
- func Skip() Field
- func Stack(key string) Field
- func StackSkip(key string, skip int) Field
- func String(key string, val string) Field
- func Stringer(key string, val fmt.Stringer) Field
- func Stringp(key string, val *string) Field
- func Strings(key string, val []string) Field
- func Time(key string, val time.Time) Field
- func Timep(key string, val *time.Time) Field
- func Times(key string, val []time.Time) Field
- func Uint(key string, val uint) Field
- func Uint8(key string, val uint8) Field
- func Uint8p(key string, val *uint8) Field
- func Uint16(key string, val uint16) Field
- func Uint16p(key string, val *uint16) Field
- func Uint32(key string, val uint32) Field
- func Uint32p(key string, val *uint32) Field
- func Uint64(key string, val uint64) Field
- func Uint64p(key string, val *uint64) Field
- func Uintptr(key string, val uintptr) Field
- func Uintptrp(key string, val *uintptr) Field
- 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 Field ¶ added in v2.0.3
'Field' is an alias for zap.Field or zapcore.Field
func ByteString ¶ added in v2.0.4
func ByteStrings ¶ added in v2.0.4
func Complex128 ¶ added in v2.0.4
func Complex128(key string, val complex128) Field
func Inline ¶ added in v2.0.4
func Inline(val zapcore.ObjectMarshaler) Field
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