Overview
The v2 formatted functions providefmt.Sprintf-style string formatting for logging. These functions internally format the message and then call the corresponding basic logging function.
The v2 API is legacy and maintained for backward compatibility. For new code, consider using the v3 Logger API with structured fields instead of string formatting.
Functions
Infof
Logs an informational message with formatting.format- The format string (followsfmt.Sprintfsyntax)args- Arguments for the format string
- Formats the message using
fmt.Sprintf(format, args...) - Calls
InfoLog(message)internally - Displays in yellow color
- Saves to file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_INFO_LOG=1
api.go:11-32
Errorf
Logs an error message with formatting.format- The format string (followsfmt.Sprintfsyntax)args- Arguments for the format string
- Formats the message using
fmt.Sprintf(format, args...) - Calls
ErrorLog(message)internally - Displays in red color
- Saves to file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_ERROR_LOG=1
api.go:34-54
Warningf
Logs a warning message with formatting.format- The format string (followsfmt.Sprintfsyntax)args- Arguments for the format string
- Formats the message using
fmt.Sprintf(format, args...) - Calls
WarningLog(message)internally - Displays in yellow color
- Saves to file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_WARNING_LOG=1
api.go:56-76
Successf
Logs a success message with formatting.format- The format string (followsfmt.Sprintfsyntax)args- Arguments for the format string
- Formats the message using
fmt.Sprintf(format, args...) - Calls
SuccessLog(message)internally - Displays in green color
- Saves to file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_SUCCESS_LOG=1
api.go:78-98
Fatalf
Logs a fatal message with formatting and terminates the program.format- The format string (followsfmt.Sprintfsyntax)args- Arguments for the format string
- Formats the message using
fmt.Sprintf(format, args...) - Calls
FatalLog(message)internally - Displays in red color with bomb emoji (💣)
- Saves to file if
SAVE_LOG_FILE=1 - Sends to Slack if
NOTIFICATION_FATAL_LOG=1 - Terminates the program with
os.Exit(1)
api.go:100-121
Usage Examples
Dynamic Messages
Error Reporting
Statistics Logging
Configuration Validation
Format String Syntax
These functions use Go’s standardfmt.Sprintf format verbs:
| Verb | Type | Example |
|---|---|---|
%s | String | "user-%s" → "user-john" |
%d | Integer | "port %d" → "port 8080" |
%f | Float | "rate %f" → "rate 3.14" |
%.2f | Float (2 decimals) | "%.2f%%" → "98.50%" |
%v | Any value | "error: %v" → "error: EOF" |
%+v | Struct with fields | "%+v" → "{Name:John Age:30}" |
%t | Boolean | "enabled=%t" → "enabled=true" |
%x | Hex | "0x%x" → "0x1a2b" |
Performance Considerations
V2 Formatted (allocates):Migration to V3
V2 Formatted:- Zero allocations for fields
- Better queryability in log aggregators
- Type safety
- Automatic JSON formatting
Related API
- V2 Global Functions - Basic logging without formatting
- V2 Context Functions - Context-aware formatted logging