Overview
Core options provide fundamental configuration for the logger instance, including level filtering, output destination, and formatting.WithLevel
Sets the minimum log level threshold for filtering.Signature
Parameters
level(Level): The minimum log level threshold
Returns
Option: A configuration option that sets the logger’s level threshold
Type Definition
Description
Messages below the specified level will be filtered out and not logged. Uses syslog-style filtering where higher numeric values indicate higher severity.Level Values
| Level | Value | Description |
|---|---|---|
TraceLevel | 10 | Extremely detailed, high-volume logging |
DebugLevel | 20 | Detailed diagnostic information |
InfoLevel | 30 | General informational messages (default) |
WarnLevel | 40 | Warning messages |
ErrorLevel | 50 | Error events |
FatalLevel | 60 | Critical errors that terminate the app |
SilentLevel | 0 | Disables all logging |
Examples
WithOutput
Sets the output destination for log entries.Signature
Parameters
w(io.Writer): The output destination for log messages
Returns
Option: A configuration option that sets the logger’s output writer
Type Definition
Description
Configures where log messages will be written. Accepts anyio.Writer implementation, including files, stdout, stderr, or custom writers.
Examples
WithFormatter
Sets the formatter for log entries.Signature
Parameters
f(Formatter): The formatter implementation to use
Returns
Option: A configuration option that sets the logger’s formatter
Type Definition
Formatter Interface
Description
Controls how log entries are formatted before being written to the output. go_logs provides two built-in formatters:- TextFormatter: Human-readable format with optional ANSI colors (ideal for development)
- JSONFormatter: Structured JSON format (ideal for production and log aggregators)
Examples
Custom Formatter
Combined Usage
Related
- Level Reference - Detailed information about log levels
- Formatter Reference - Formatter implementations
- Output Options - Advanced output configuration