Documentation
¶
Overview ¶
Package logging provides a logging system for the application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
func Debug(args ...any)
Debug emits a "DEBUG" level log message using the default logger. If more than one argument is provided, the first argument is used as a string format template and the remaining arguments are used as string formatting parameters.
func Error ¶
func Error(args ...any)
Error emits an "ERROR" level log message using the default logger. If more than one argument is provided, the first argument is used as a string format template and the remaining arguments are used as string formatting parameters.
func Fatal ¶
func Fatal(args ...any)
Fatal emits a "FATAL" level log message using the default logger. If more than one argument is provided, the first argument is used as a string format template and the remaining arguments are used as string formatting parameters.
func Info ¶
func Info(args ...any)
Info emits an "INFO" level log message using the default logger. If more than one argument is provided, the first argument is used as a string format template and the remaining arguments are used as string formatting parameters.
func NewContext ¶
NewContext returns a new Context carrying logger.
func Panic ¶
func Panic(args ...any)
Panic emits a "PANIC" level log message using the default and then panics. If more than one argument is provided, the first argument is used as a string format template and the remaining arguments are used as string formatting parameters.
func SetDefaultConfig ¶
func SetDefaultConfig(config Config)
SetDefaultConfig sets the package's default logging configuration.
Parameters:
- config: The configuration to set as the default.
Types ¶
type Config ¶
type Config struct {
// Level is the lowest level of log message that should be emitted. Any log
// messages logged at the specified level or any level more severe will be
// emitted. The default level is DEBUG.
Level Level
// Output is the destination for log messages. By default, it is os.Stderr.
Output io.Writer
}
Config is a logging configuration.
type Level ¶
type Level uint8
A Level is a level of severity for a log message.
const ( // DebugLevel causes a logger to emit messages logged at "DEBUG" level or more // severe. It is typically only enabled when debugging or during development, // and usually results in very verbose logging output. DebugLevel Level = iota // InfoLevel causes a logger to emit messages logged at "INFO" level or more // severe. It is typically used for general operational entries about what's // going on inside an application. InfoLevel // WarnLevel causes a logger to emit messages logged at "WARN" level or more // severe. It is typically used for non-critical entries that deserve attention. WarnLevel // ErrorLevel causes a logger to emit messages logged at "ERROR" level or more // severe. It is typically used for errors that should definitely be noted, and // is commonly used for hooks to send errors to an error tracking service. ErrorLevel // FatalLevel causes a logger to emit messages logged at "FATAL" level or more // severe. Messages logged at this level cause a logger to log the message and // then call os.Exit(1). It will exit even if the logging level is set to PanicLevel. FatalLevel // PanicLevel causes a logger to only emit messages logged at "PANIC" level. // It is the highest level of severity. PanicLevel )
type Logger ¶
type Logger interface {
// Debug emits a "DEBUG" level log message. If more than one argument is provided,
// the first argument is used as a string format template and the remaining arguments
// are used as string formatting parameters.
Debug(args ...any)
// Info emits an "INFO" level log message. If more than one argument is provided,
// the first argument is used as a string format template and the remaining arguments
// are used as string formatting parameters.
Info(args ...any)
// Warn emits a "WARN" level log message. If more than one argument is provided,
// the first argument is used as a string format template and the remaining arguments
// are used as string formatting parameters.
Warn(args ...any)
// Error emits an "ERROR" level log message. If more than one argument is provided,
// the first argument is used as a string format template and the remaining arguments
// are used as string formatting parameters.
Error(args ...any)
// Fatal emits a "FATAL" level log message. If more than one argument is provided,
// the first argument is used as a string format template and the remaining arguments
// are used as string formatting parameters.
Fatal(args ...any)
// Panic emits a "PANIC" level log message and then panics. If more than one argument
// is provided, the first argument is used as a string format template and the remaining
// arguments are used as string formatting parameters.
Panic(args ...any)
// WithField adds a field to the logger and returns a new Logger.
WithField(key string, value any) Logger
// WithFields adds multiple fields to the logger and returns a new Logger.
WithFields(fields Fields) Logger
// WithError adds a field called "error" to the logger and returns a new Logger.
WithError(err error) Logger
// Copy returns a copy of the logger. The copy will have the same fields as the
// original logger.
Copy() Logger
}
Logger provides methods for logging messages.
func FromContext ¶
FromContext extracts the Logger from ctx, if present. If no Logger is present within the context, a new default Logger is created.
func NewDefaultLogger ¶
func NewDefaultLogger() Logger
NewDefaultLogger returns a new logger that uses the package's default configuration.
Returns:
- Logger: A new Logger configured with the default configuration.
func NewLogger ¶
NewLogger returns a new Logger.
Parameters:
- config: The configuration for the logger.
Returns:
- Logger: A new Logger configured with the given configuration.
func WithError ¶
WithError adds a field called "error" to the default logger and returns a new Logger.
func WithFields ¶
WithFields adds multiple fields to the default logger and returns a new Logger.