Printer
Output styled data directly without a log level, key, or message:
clog.Print().RawJSON([]byte(`{"status":"ok","count":42,"active":true}`))
// {
// "status": "ok",
// "count": 42,
// "active": true
// }
The Printer writes directly to the logger’s output, bypassing any custom Handler. It uses the logger’s style configurations for token colors.
JSON
JSON marshals any Go value; RawJSON accepts pre-serialized bytes:
clog.Print().JSON(userStruct)
clog.Print().RawJSON(responseBody)
Print Mode
The default mode is JSONPretty, which pretty-prints with indentation. Set the global default with SetJSONPrintMode, or override per-call with Mode:
// Global default: flatten to single line
clog.SetJSONPrintMode(clog.JSONFlat)
// Per-call override
clog.Print().Mode(clog.JSONPretty).RawJSON(data)
clog.Print().Mode(clog.JSONFlat).RawJSON(data)
| Mode | Description |
|---|---|
JSONPretty | Pretty-print with normalized indentation (default) |
JSONFlat | Flatten to a single line (matches inline log fields) |
JSONPreserve | Keep original whitespace, only add syntax highlighting |
Styling
Printer JSON inherits token colors (keys, strings, numbers, etc.) from the logger’s JSON styles. Field-specific rendering modes (JSONModeHuman, JSONModeFlat) are not applied – the Printer always uses standard JSON rendering.
custom := style.DefaultJSON()
custom.Key = new(lipgloss.NewStyle().Foreground(lipgloss.Color("#50fa7b")))
clog.SetStyles(&style.Config{JSON: custom})
YAML
YAML marshals any Go value; RawYAML accepts pre-serialized bytes:
clog.Print().YAML(configStruct)
clog.Print().RawYAML(responseBody)
See YAML for styling options.
TOML
TOML marshals any Go value; RawTOML accepts pre-serialized bytes:
clog.Print().TOML(configStruct)
clog.Print().RawTOML(configBytes)
See TOML for styling options.
HCL
RawHCL accepts pre-serialized HCL bytes (there is no marshal method since HCL has no standard Go marshal API):
clog.Print().RawHCL(terraformConfig)
See HCL for styling options.
Themes
Printer styles default to the Dracula color theme. Switch all four format styles at once with SetPrintTheme:
clog.SetPrintTheme(theme.Monokai())
Per-token overrides still work after setting a theme:
clog.SetPrintTheme(theme.Monokai())
s := clog.DefaultStyles()
s.JSON.Key = new(lipgloss.NewStyle().Foreground(lipgloss.Color("#ff0000")))
clog.SetStyles(s)
To build styles from a theme directly:
custom := style.NewJSON(theme.Monokai())
Available themes:
theme.CatppuccinFrappe()theme.CatppuccinLatte()theme.CatppuccinMacchiato()theme.CatppuccinMocha()theme.Dracula()theme.Monokai()
Indentation
The default indent is two spaces. SetPrintIndent sets the baseline for all formats; SetJSONIndent and SetYAMLIndent override it for a specific format:
clog.SetPrintIndent("\t") // tabs for both JSON and YAML
clog.SetJSONIndent(" ") // 4 spaces for JSON only
clog.SetYAMLIndent(" ") // 2 spaces for YAML only
YAML sequences are indented under their parent key by default. Disable with SetYAMLIndentSequence(false).
Sub-loggers
Each logger has its own Printer, so sub-loggers with different styles produce different output:
logger := clog.NewWriter(os.Stdout)
logger.SetStyles(&style.Config{
JSON: style.DefaultJSON().WithSpacing(style.JSONSpacingAll),
})
logger.Print().RawJSON(data)