Logy|Docs
Formatting

JSON logging

Emit structured records for log collectors.

Enable JSON output when logs are consumed by a collector, platform, or search system.

JSON output is usually the better production format because every record keeps a stable shape. Console pattern output is usually easier to scan locally.

main.go
err := logy.LoadConfig(&logy.Config{
	Console: &logy.ConsoleConfig{
		Enabled: true,
		Json: &logy.JsonConfig{
			Enabled: true,
		},
	},
})

JSON configuration can also override keys and add fields that should appear on every record.

main.go
err := logy.LoadConfig(&logy.Config{
	Console: &logy.ConsoleConfig{
		Enabled: true,
		Json: &logy.JsonConfig{
			Enabled: true,
			KeyOverrides: logy.KeyOverrides{
				"timestamp": "@timestamp",
				"logger":    "logger_name",
			},
			AdditionalFields: logy.JsonAdditionalFields{
				"service": "billing-api",
				"env":     "production",
			},
		},
	},
})
if err != nil {
	panic(err)
}

Use key overrides when your log collector expects specific field names. Use additional fields for stable application metadata that should appear on every record.

Output shape

With JSON enabled, each log call becomes a structured record. Context values and additional fields are emitted next to the message so collectors can index them without parsing text.

Output
{
  "@timestamp": "2026-08-21T14:35:10.421Z",
  "level": "INFO",
  "logger_name": "billing",
  "message": "payment completed",
  "service": "billing-api",
  "env": "production",
  "traceId": "trace-123"
}

Enabled switches JSON formatting on for that handler. KeyOverrides changes field names in the emitted record. AdditionalFields adds stable metadata to every record produced by that handler.

On this page