Documentation
¶
Index ¶
- Constants
- func LevelFromString(str string) (int, error)
- func LevelToString(level int) string
- func StandardLogFunction(level int, message string)
- type Logger
- func (logger *Logger) CreateChildLogger(prefix string) *Logger
- func (logger *Logger) Debug(message string)
- func (logger *Logger) Debugf(format string, a ...any)
- func (logger *Logger) Error(message string)
- func (logger *Logger) Errorf(format string, a ...any)
- func (logger *Logger) Info(message string)
- func (logger *Logger) Infof(format string, a ...any)
- func (logger *Logger) Log(level int, message string)
- func (logger *Logger) Trace(message string)
- func (logger *Logger) Tracef(format string, a ...any)
- func (logger *Logger) Warning(message string)
- func (logger *Logger) Warningf(format string, a ...any)
- type LoggerConfiguration
Constants ¶
const DEBUG int = 4
Debug level
const ERROR int = 1
Error level
const INFO int = 3
Info level
const SILENT int = 0
Silent level (no logs)
const TRACE int = 5
Trace level
const WARNING int = 2
Warning level
Variables ¶
This section is empty.
Functions ¶
func LevelFromString ¶
Parses level from string (case insensitive)
Parameters: - str: The string to parse
Returns the parsed level, or an error if the value has an invalid format
func LevelToString ¶
Turns level from int to string
Parameters: - level: The level
Returns the level as string
func StandardLogFunction ¶
Standard log function to log messages using the "log" package
Parameters: - level: The log level - message: The log message
Types ¶
type Logger ¶
type Logger struct {
// Logger configuration
Config LoggerConfiguration
// Prefix for logs
Prefix string
// Log function
LogFunc func(level int, message string)
}
Logger
func CreateRootLogger ¶
func CreateRootLogger(config LoggerConfiguration, logFunc func(level int, message string)) *Logger
Creates a root logger
Parameters: - config: The logger configuration - logFunc: The function to log the messages. By default, use glog.StandardLogFunction
Returns a Logger instance
func (*Logger) CreateChildLogger ¶
Creates child logger, adding a prefix to the logs of the parent logger
Parameters: - prefix: The prefix for the logs
Returns a Logger instance
func (*Logger) Debugf ¶
Logs an DEBUG message (with format)
Parameters: - format: The message format - a: The parameters to be used in the format
Example:
logger.Debugf("The value of the intermediate value is: %v", value)
func (*Logger) Errorf ¶
Logs an ERROR message (with format)
Parameters: - format: The message format - a: The parameters to be used in the format
Example:
logger.Errorf("An error happened in the request to %v | %v", url, error.Error())
func (*Logger) Infof ¶
Logs an INFO message (with format)
Parameters: - format: The message format - a: The parameters to be used in the format
Example:
logger.Infof("Received request from: %v", ip)
func (*Logger) Tracef ¶
Logs an TRACE message (with format)
Parameters: - format: The message format - a: The parameters to be used in the format
Example:
logger.Tracef("DB Query: %v", query)
type LoggerConfiguration ¶
type LoggerConfiguration struct {
// True to enable ERROR messages
ErrorEnabled bool
// True to enable WARNING messages
WarningEnabled bool
// True to enable INFO messages
InfoEnabled bool
// True to enable DEBUG messages
DebugEnabled bool
// True to enable TRACE messages
TraceEnabled bool
}
Logger configuration
func CreateLoggerConfigurationFromLevel ¶
func CreateLoggerConfigurationFromLevel(level int) LoggerConfiguration
Creates a configuration from a level
Parameters: - level: The lowest level to log
Returns a configuration with all the levels lower then the specified disabled