GoLog adds level-based logging to logger(s) from the standard library and offers means to integrate with other logging libraries. Its API is designed to be expressive with sensible configuration defaults and easy to use.
- Leveled Logging: Provides
Debug
,Info
,Warning
, andError
levels for categorized logging. - Customizable Print Level: Default
log.Print
logs toDebug
but can be customized withWithPrintLevel
. - Syslog Support: Includes a
NewSyslog
constructor for syslog-based logging. - Standard Logger Integration: Handles logging via the standard library logger with customizable behavior.
- Sublogger Customizations: Supports creating subloggers with
WithLevel
,WithPrefix
, andWithRateLimit
for fine-grained control. - Options and Configuration: Supports environment-based configuration like
WithLevelFromEnv
andWithSourceLocationFromEnv
. - Resource Management: Ensures proper cleanup with
Close
methods.
See the documentation for examples of how to use the library.
This library ensures compatibility with the standard Go logger by providing log.Print
and log.Printf
methods that replicate the standard logger's behavior.
While log.Print
and log.Printf
log at the PrintLevel
, their use is discouraged as they lack the control and clarity of leveled logging methods. For better categorization and maintainability, use specific leveled logging methods. If needed, adjust their logging level using WithPrintLevel
. Refer to examples here for detailed usage.
The library automatically processes log lines from the standard Go logger, making it ideal for scenarios where standard library logging is unavoidable, such as third-party libraries or specific functionalities. By default, these logs are assigned the Info
level, but you can customize this behavior using WithStdlogSorter
.
Explore example usage for WithStdlogSorter
.
This project is licensed under the MIT License. See the LICENSE file for details.