Overview
Formatting options enhance log entries with additional context such as caller information (file, line, function) and stack traces for debugging.WithCaller
Enables or disables caller information in log entries.Signature
Parameters
enabled(bool): Whether to include caller information in log entries
Returns
Option: A configuration option that enables/disables caller capture
Type Definition
Description
When enabled, each log entry includes file name, line number, and function name of the code that generated the log message. This is invaluable for debugging but adds a small performance overhead (~100-200ns per log call).Output Example
Examples
Performance Note
Enabling caller adds approximately 100-200ns per log call due to runtime stack inspection. For high-performance applications, consider usingWithCallerLevel to enable caller only for errors.
WithCallerLevel
Sets the minimum level for automatic caller info capture.Signature
Parameters
level(Level): The minimum log level for capturing caller information
Returns
Option: A configuration option that sets the caller level threshold
Type Definition
Description
Caller information (file:line function) is captured only for log entries at or above the specified level. This allows you to balance debugging information with performance. Default:ErrorLevel (caller info for Error and Fatal only)
Common Values
WarnLevel: Capture for Warn, Error, FatalErrorLevel: Capture for Error, Fatal (default)FatalLevel: Capture only for FatalSilentLevel: Disable automatic caller capture
Examples
Note
WithCaller(true) overrides this setting and enables caller for ALL levels.
WithCallerSkip
Sets the number of stack frames to skip when capturing caller info.Signature
Parameters
skip(int): Number of stack frames to skip (must be >= 0)
Returns
Option: A configuration option that sets the caller skip level
Type Definition
Description
Useful when wrapping the logger with additional helper functions. By default, the logger skips 2 frames (the GetCaller and Log methods). Increase this value if you have wrapper functions. Default: 2 (skips GetCaller and Log methods)Examples
Use Cases
- Creating custom logging wrappers
- Integrating with existing logging abstractions
- Building domain-specific loggers
WithStackTrace
Enables or disables stack trace capture in log entries.Signature
Parameters
enabled(bool): Whether to capture stack traces
Returns
Option: A configuration option that enables/disables stack trace capture
Type Definition
Description
When enabled, captures full stack traces for log entries. Stack traces are captured for Error level and above by default. UseWithStackTraceLevel to customize the minimum level.
Examples
Performance Impact
Stack trace capture is expensive. Only enable for error scenarios where detailed debugging is needed.WithStackTraceLevel
Sets the minimum level for automatic stack trace capture.Signature
Parameters
level(Level): The minimum log level for capturing stack traces
Returns
Option: A configuration option that sets the stack trace level threshold
Type Definition
Description
Stack traces are captured only for log entries at or above this level. This allows you to limit the performance impact of stack trace capture. Default:ErrorLevel (stack traces for Error and Fatal)
Common Values
WarnLevel: Capture for Warn, Error, FatalErrorLevel: Capture for Error, Fatal (default)FatalLevel: Capture only for Fatal
Examples
Combined Usage
Performance Considerations
| Feature | Overhead | Recommendation |
|---|---|---|
| Caller (all levels) | ~100-200ns/call | Development only |
| Caller (error+) | Minimal | Safe for production |
| Stack trace | High (µs) | Errors/fatal only |
Related
- Core Options - Basic logger configuration
- Entry Reference - Log entry structure
- CallerInfo Reference - Caller information details