Options struct configures the behavior of a new Logger. Pass it to NewWithOptions to customize logging behavior, including asynchronous writing, formatting, and field extraction.
Options struct
Configuration fields
Level
Sets the minimum logging priority. The Logger discards entries below this level.InfoLevel
Example
Output
Specifies the destination for log data.BufferSize
Defines the capacity of the internal ring buffer for asynchronous loggers. Must be a power of 2.8192
Example
OverflowStrategy
Dictates behavior when the asynchronous buffer fills up.OverflowSync- Forces synchronous writes when buffer is full (default)OverflowDrop- Discards new log entries until space is availableOverflowBlock- Pauses calling goroutine until space is available
OverflowSync
Example
ReportTimestamp
Includes a timestamp in every log entry.false
Example
TimeFormat
Specifies the layout string for timestamps."2006/01/02 15:04:05" (DefaultTimeFormat)
Example
TimeFunction
Provides a custom hook for generating timestamps.func(time.Time) time.Time
Default: time.Now
Example
ReportCaller
Includes the calling file and line number in every log entry.false
Performance Note: Enabling this incurs a significant performance penalty.
Example
CallerOffset
Adjusts the stack frame depth when identifying the caller. Use this if you wrap the Logger in custom helper functions.0
Example
CallerFormatter
Provides a custom hook for formatting caller information.func(file string, line int, funcName string) string
Default: ShortCallerFormatter
Built-in formatters:
ShortCallerFormatter- Returns “filename.go:42”LongCallerFormatter- Returns “/full/path/to/filename.go:42”
ReportStacktrace
Includes a full stack trace for entries at ErrorLevel or higher.false
Performance Note: Enabling this incurs a significant performance penalty on errors.
Example
Prefix
Prepends a static string to every log message.""
Example
Fields
Attaches default, loosely typed key-value pairs to every log entry.nil
Example
Formatter
Dictates how the Logger serializes entries.TextFormatter- Human readable, colorized text (default)JSONFormatter- Structured JSON output
TextFormatter
Example
ContextExtractor
Provides a custom hook to pull fields from a context.Context.func(context.Context) []Field
Default: nil
Example
Async
Enables the background worker, routing logs through a lock-free ring buffer.false
Example
Related types
Formatter
Defines the serialization format for log entries.TextFormatter- Human readable, colorized textJSONFormatter- Structured JSON
OverflowStrategy
Dictates how an asynchronous Logger behaves when its internal ring buffer fills up.OverflowSync- Forces synchronous writes, guarantees no log lossOverflowDrop- Discards new entries, prioritizes performanceOverflowBlock- Pauses calling goroutine, guarantees no log loss