Documentation
¶
Overview ¶
Package log provides a lightweight thread-safe logging facility using structured logging (slog) with JSON output format. It offers a singleton logger instance with configurable log levels through environment variables and convenience methods for fatal error logging.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fatal ¶
Fatal logs a message at Fatal level. The fName parameter indicates the function name from which the call is made. The details parameter contains the error message or details to log. This function panics before exiting.
func FatalF ¶
FatalF logs a formatted message at Fatal level. The fName parameter indicates the function name from which the call is made. The format parameter is a printf-style format string. The args parameter contains values to be formatted according to the format string. It follows the printf formatting rules. This function panics before exiting.
func FatalLn ¶
FatalLn logs a message at Fatal level with a line feed. The fName parameter indicates the function name from which the call is made. The args parameter contains the values to be logged, which will be formatted and joined. This function panics before exiting.
func Level ¶
Level returns the logging level for the SPIKE components.
It reads from the SPIKE_SYSTEM_LOG_LEVEL environment variable and converts it to the corresponding slog.Level value. Valid values (case-insensitive) are:
- "DEBUG": returns slog.LevelDebug
- "INFO": returns slog.LevelInfo
- "WARN": returns slog.LevelWarn
- "ERROR": returns slog.LevelError
If the environment variable is not set or contains an invalid value, it returns the default level slog.LevelWarn.
func Log ¶
Log returns a thread-safe singleton instance of slog.Logger configured for JSON output. If the logger hasn't been initialized, it creates a new instance with the log level specified by the environment. Further calls return the same logger instance.
By convention, when using the returned logger, the first argument (msg) should be the function name (fName) from which the logging call is made.
Types ¶
This section is empty.