Documentation
¶
Overview ¶
Package logger provides structured logging with different log levels.
Index ¶
- type Config
- type Fields
- type Level
- type Logger
- func (l *Logger) Debug(msg string, metadata ...Fields)
- func (l *Logger) Error(msg string, metadata ...Fields)
- func (l *Logger) Fatal(msg string, metadata ...Fields)
- func (l *Logger) GetLevel() Level
- func (l *Logger) Info(msg string, metadata ...Fields)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Warn(msg string, metadata ...Fields)
- func (l *Logger) WithMetadata(_ Fields) *Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MinLevel is the minimum log level to output
MinLevel Level
// EnableJSON controls whether to output logs in JSON format
EnableJSON bool
// Output is where logs are written to
Output io.Writer
// IncludeTimestamp controls whether to include a timestamp in logs
IncludeTimestamp bool
// IncludeFileLine controls whether to include the file and line number in logs
IncludeFileLine bool
}
Config holds the logger configuration.
type Level ¶
type Level int
Level represents the severity level of a log message
const ( // DebugLevel is the most verbose logging level, used for debugging. DebugLevel Level = iota // InfoLevel is the standard logging level, used for general information. InfoLevel // WarnLevel is for logging warnings that don't cause application failure. WarnLevel // ErrorLevel is for logging errors that affect application function. ErrorLevel // FatalLevel is for logging fatal errors that require application termination. FatalLevel )
func ParseLevel ¶
ParseLevel parses a string level into a Level.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a structured logger that supports different log levels
func DefaultLogger ¶
func DefaultLogger() *Logger
DefaultLogger returns a logger with sensible defaults
func (*Logger) Fatal ¶
Fatal logs a fatal message with optional metadata and then exits the application.
func (*Logger) WithMetadata ¶
WithMetadata returns a function that logs with the provided metadata.
Click to show internal directories.
Click to hide internal directories.