Overview
The v2 API provides simple global logging functions for backward compatibility. These functions offer a quick way to log messages without creating a logger instance.The v2 API is legacy and maintained for backward compatibility. For new code, consider using the v3 Logger API which provides structured logging, multiple formatters, and better performance.
Functions
InfoLog
Logs an informational message.message- The informational message to log
- Displays message in yellow color to terminal
- Saves to log file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_INFO_LOG=1
SAVE_LOG_FILE- Enable file logging (0 or 1)NOTIFICATION_INFO_LOG- Enable Slack notifications (0 or 1)
logs.go:54-74
ErrorLog
Logs an error message.message- The error message to log
- Displays message in red color to terminal
- Saves to log file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_ERROR_LOG=1
SAVE_LOG_FILE- Enable file logging (0 or 1)NOTIFICATION_ERROR_LOG- Enable Slack notifications (0 or 1)
logs.go:32-52
WarningLog
Logs a warning message.message- The warning message to log
- Displays message in yellow color to terminal
- Saves to log file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_WARNING_LOG=1
SAVE_LOG_FILE- Enable file logging (0 or 1)NOTIFICATION_WARNING_LOG- Enable Slack notifications (0 or 1)
api.go:267-291
This function was previously missing from the API, even though the
notificationLogWarning configuration variable was loaded. It has been added to provide complete logging level support.SuccessLog
Logs a success message.message- The success message to log
- Displays message in green color to terminal
- Saves to log file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_SUCCESS_LOG=1
SAVE_LOG_FILE- Enable file logging (0 or 1)NOTIFICATION_SUCCESS_LOG- Enable Slack notifications (0 or 1)
logs.go:76-96
FatalLog
Logs a fatal message and terminates the program.message- The fatal message to log
- Displays message in red color with bomb emoji (💣) to terminal
- Saves to log file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_FATAL_LOG=1 - Terminates the program by calling
log.Fatal()
SAVE_LOG_FILE- Enable file logging (0 or 1)NOTIFICATION_FATAL_LOG- Enable Slack notifications (0 or 1)
logs.go:8-30
Usage Examples
Basic Logging
Error Handling
Fatal Errors
Color Output
The v2 API uses thefatih/color package to provide colored terminal output:
| Function | Color | Emoji |
|---|---|---|
InfoLog | Yellow | - |
ErrorLog | Red | - |
WarningLog | Yellow | - |
SuccessLog | Green | - |
FatalLog | Red | 💣 |
File Logging
WhenSAVE_LOG_FILE=1, all log messages are written to a file:
Slack Notifications
Enable Slack notifications for specific log levels:Migration to V3
The v2 API is simple but lacks structured logging. Consider migrating to v3: V2 (Legacy):Related API
- V2 Formatted Functions -
Infof,Errorf, etc. - V2 Context Functions -
InfoLogCtx,ErrorLogCtx, etc.