Documentation
¶
Index ¶
- func Field(key string, value any) gsr.LoggerField
- type Config
- type Level
- type Logger
- func (l *Logger) Debug(format string, args ...gsr.LoggerField)
- func (l *Logger) Error(format string, args ...gsr.LoggerField)
- func (l *Logger) Fatal(format string, args ...gsr.LoggerField)
- func (l *Logger) GetZapLogger() *zap.Logger
- func (l *Logger) Info(format string, args ...gsr.LoggerField)
- func (l *Logger) Notice(format string, args ...gsr.LoggerField)
- func (l *Logger) Panic(format string, args ...gsr.LoggerField)
- func (l *Logger) Sync() error
- func (l *Logger) Warn(format string, args ...gsr.LoggerField)
- func (l *Logger) With(args ...gsr.LoggerField) *Logger
- func (l *Logger) WithZapFields(fields ...zap.Field) *Logger
- type LoggerField
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Level sets the minimum enabled logging level
Level Level
// Development puts the logger in development mode
Development bool
// Encoding sets the logger's encoding (json or console)
Encoding string
// OutputPaths is a list of URLs or file paths to write logging output to
OutputPaths []string
// ErrorOutputPaths is a list of URLs to write internal logger errors to
ErrorOutputPaths []string
// CallerSkip increases the number of callers skipped by caller annotation
// Default is 0, which will be automatically set to 1 (skip golog wrapper).
// Set to 1+ if you wrap golog in your own logger (1 = single wrap, 2 = double wrap, etc.).
CallerSkip uint
}
Config holds the configuration for creating a new logger
type Level ¶ added in v1.1.0
type Level int8
Level represents the logging level
const ( // DebugLevel logs are typically voluminous, and are usually disabled in production. DebugLevel Level = iota - 1 // InfoLevel is the default logging priority. InfoLevel // WarnLevel logs are more important than Info, but don't need individual human review. WarnLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. ErrorLevel // FatalLevel logs a message, then calls os.Exit(1). FatalLevel // PanicLevel logs a message, then panics. PanicLevel )
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger wraps zap.Logger and implements the gsr.Logger interface
func NewDevelopmentLogger ¶
NewDevelopmentLogger creates a logger suitable for development with human-readable console output and debug-level logging
func NewLogger ¶
func NewLogger() *Logger
NewLogger creates a new logger with example configuration (for testing only)
func NewLoggerWithConfig ¶
NewLoggerWithConfig creates a new logger with custom configuration
func NewLoggerWithZap ¶
NewLoggerWithZap creates a logger from an existing zap.Logger Note: If you need caller skip, pass a logger with AddCallerSkip already configured
func NewProductionLogger ¶
NewProductionLogger creates a logger suitable for production with JSON output and info-level logging
func (*Logger) Debug ¶
func (l *Logger) Debug(format string, args ...gsr.LoggerField)
Debug logs a message at DebugLevel
func (*Logger) Error ¶
func (l *Logger) Error(format string, args ...gsr.LoggerField)
Error logs a message at ErrorLevel
func (*Logger) Fatal ¶
func (l *Logger) Fatal(format string, args ...gsr.LoggerField)
Fatal logs a message at FatalLevel and then calls os.Exit(1)
func (*Logger) GetZapLogger ¶
GetZapLogger returns the underlying zap.Logger This is useful when you need direct access to zap features
func (*Logger) Info ¶
func (l *Logger) Info(format string, args ...gsr.LoggerField)
Info logs a message at InfoLevel
func (*Logger) Notice ¶
func (l *Logger) Notice(format string, args ...gsr.LoggerField)
Notice logs a message at InfoLevel (alias for Info) Notice level is mapped to Info as zap doesn't have a separate Notice level
func (*Logger) Panic ¶
func (l *Logger) Panic(format string, args ...gsr.LoggerField)
Panic logs a message at PanicLevel and then panics
func (*Logger) Sync ¶
Sync flushes any buffered log entries Applications should call Sync before exiting Note: Sync errors on stdout/stderr are ignored as they cannot be synced on some systems
func (*Logger) Warn ¶
func (l *Logger) Warn(format string, args ...gsr.LoggerField)
Warn logs a message at WarnLevel
type LoggerField ¶
LoggerField represents a key-value pair for structured logging
func (*LoggerField) GetValue ¶
func (f *LoggerField) GetValue() any
GetValue returns the field's value
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
caller_test
command
|
|
|
custom
command
|
|
|
webserver
command
|
|
|
wrapped_logger
command
|