Documentation ¶
Overview ¶
logger provides basic logging support for your application. Supported log destinations are the console and a log file
Index ¶
- func CloseFile()
- func Debug(message string, parameters ...any)
- func Error(message string, parameters ...any)
- func Fatal(message string, parameters ...any)
- func Info(message string, parameters ...any)
- func SetGlobalLogger(l *Logger)
- func Trace(message string, parameters ...any)
- func Warning(message string, parameters ...any)
- type FileLogger
- type Level
- type Logger
- func (l *Logger) Debug(message string, parameters ...any)
- func (l *Logger) Error(message string, parameters ...any)
- func (l *Logger) Fatal(message string, parameters ...any)
- func (l *Logger) Info(message string, parameters ...any)
- func (l *Logger) Log(level Level, message string, parameters ...any)
- func (l *Logger) Trace(message string, parameters ...any)
- func (l *Logger) Warning(message string, parameters ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseFile ¶
func CloseFile()
CloseFile closes the underlaying file to which the logger messages are written.
func SetGlobalLogger ¶
func SetGlobalLogger(l *Logger)
SetGlobalLogger updates the global default logger with a custom one. You can create one via the Logger struct.
Types ¶
type FileLogger ¶ added in v1.3.0
type FileLogger struct { // Minimum log level for logging into a file Level Level // Absolute or relative path to log files to Path string // With this option the path of the log file will be appended with the current date // so that an own log file for each day is used. The format of the date is 'YYYYMMDD' AppendDate bool // contains filtered or unexported fields }
FileLogger contains configuration options specific to logging into a file. It is enabled if the FilePath != ""
func (*FileLogger) CloseFile ¶ added in v1.3.0
func (l *FileLogger) CloseFile()
CloseFile closes the file that is currently used for logging messages to a file
type Level ¶
type Level uint8
Level of the log message
func GetLevelByName ¶
GetLevelByName tries to convert the given level name to the represented level code. Allowed values are: 'trace', 'debug', 'info', 'warn', 'warning', 'error', 'panic' and 'fatal' If an incorrect level name was given a warning is logged and info will be returned
type Logger ¶
type Logger struct { // Minimum log level for printing to the console (stdout and stderr) Level Level // Colorizes the log messages for the console. // Even if you set this to true the user is able to overwrite this behaviour by // setting the environment variables "TERMINAL_DISABLE_COLORS" and // "TERMINAL_ENABLE_COLORS" (to force coloring for "unsupported" terminals) ColoredOutput bool // Whether to print the file and line number of the invoking (calling line) PrintSource bool // Only print the log message without any additional info. This property will ignore other options linke // PrintSource or FuncCallIncrement OnlyPrintMessage bool // While logging, the file and line number of the // invoking (calling) line can be printed out. // This defines an offset that is applied to the call stack. // If you are using an own wrapper function, you // have to set this value to one FuncCallIncrement int // Prefix is applied as a prefix for all log messages. // It's positioned after all other information: // [INFO ] 2024-04-10 19:00:00 (file:1)PREFIX - Message Prefix string // Configuration options for logging into a file File *FileLogger // contains filtered or unexported fields }
func CloneLogger ¶ added in v1.3.3
CloneLogger creates a copy of the provided logger with it's file reference. All configuration options are cloned from "logger" to the new one
func GetGlobalLogger ¶
func GetGlobalLogger() *Logger
func GetLoggerFromEnv ¶ added in v1.2.0
GetLoggerFromEnv returns a logging instance configured from the available environment variables.
The environment variables have to be named like the struct fields in upper case with the prefix "LOGGER_". Sub structs are divided also by an underscore. Example: "LOGGER_SUBCONFIG_DISABLED"
If no env variable was found the default value of the given logger struct will be used.
Note that only generic options can be set like: - Print and Log Level - Log path - ColoredOutput - Tracing disabled
func NewLoggerWithFile ¶
NewLoggerWithFile creates a new instance with the given logger configuration. Instead of opening a new file to write the log messages to, the old file reference of the other logger will be used internal. This enables you to write to the same file with different log configurations.