-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description:
Consider making JSON the default output format when using the @ capturing operator to align with modern Serilog behavior and structured logging expectations.
Background:
Currently, the @ operator produces Go's default struct format (%+v), which outputs:
&{AsepritePath:/path/to/aseprite TempDir:/tmp Timeout:30s LogLevel:debug}
To get JSON output, users must explicitly specify the :j format:
logger.Debug("Config: {@Config:j}", cfg)
// Output: {"aseprite_path":"/path/to/aseprite","temp_dir":"/tmp","timeout":30000000000,"log_level":"debug"}Proposed Change:
Make @ produce JSON by default, with an option to get Go format:
logger.Debug("Config: {@Config}", cfg) // JSON output (new default)
logger.Debug("Config: {@Config:go}", cfg) // Go struct format (opt-in)Rationale:
- Serilog Alignment: Modern Serilog outputs structured/JSON representation when using
@with structured sinks - Structured Logging: JSON is the de facto standard for structured logging, making logs more parseable
- Consistency: The
@operator's purpose is to create structured representations suitable for serialization - User Expectations: Users coming from Serilog expect
@to produce structured output, not language-specific formatting
Current Workarounds:
- Users must remember to add
:jto every@usage for structured output - Or accept Go's struct format which includes pointer notation (
&{...})
Migration Path:
Since we're pre-v1.0, this change can be made directly. Users who prefer the Go format could:
- Use a new
:goformat specifier - Use
$for scalar rendering - Configure behavior globally via
mtlog.WithGoCapturing()(optional)
Comparison with Other Libraries:
- Serilog (.NET):
@produces structured output (JSON in structured sinks) - Zap (Go): Uses JSON by default for structured fields
- Zerolog (Go): JSON-first design
- slog (Go stdlib): JSON handler outputs JSON for structured data
Implementation Notes:
- The change would be in the capturing/rendering logic
- Would need to handle circular references in JSON serialization
- Consider performance impact of JSON encoding vs
fmt.Sprintf("%+v") - May want to pretty-print for console sinks vs compact for file/network sinks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request