chroniclers
Compile-time selectable structured logging facade for Nim
Summary
| Latest Version | 0.7.1 |
|---|---|
| License | BSD-2-Clause |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-11-21 14:04 |
Tags
Authors
- Jaremy Creechley
Installation
nimble install chroniclers
choosenim install chroniclers
git clone https://github.com/elcritch/chroniclers
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| chroniclers | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Dependencies
| Package | Version | Optional |
|---|---|---|
| nim >= | 2.0.0 | No |
| chronicles | - | No |
Source
| Repository | https://github.com/elcritch/chroniclers |
|---|---|
| Homepage | https://github.com/elcritch/chroniclers |
| Registry Source | nimble_official |
README
Chroniclers
Chroniclers is a tiny structured logging facade for Nim. It keeps a Chronicles-style call shape while letting applications choose the implementation at compile time.
import chroniclers
info "request complete", route = "/items/42", status = 200, elapsedMs = 12.5
warn "request slow", route = "/items/42", elapsedMs = 450
Installtion
The normal Atlas/Nimble setup:
atlas use chroniclers
For applications it's handy to use the feature pattern to select your logger:
requires "chroniclers[chronicles] >= 0.7.0"
Using Install Features
For "middleware" type projects you can pass on the logging option like:
requires "chroniclers"
feature "chronicles":
requires "chroniclers[chronicles] >= 0.7.0"
Then users can use your project like:
requires "myawesomelib[chronicles]"
Backends
Chroniclers ships with support for Chronicles and Nim's std/logging. It defaults to an empty none backend.
Select a backend with a compile-time flag:
nim c -d:chroniclers.logBackendChronicles app.nim
nim c -d:chroniclers.logBackendStd app.nim
nim c -d:chroniclers.logBackendNone app.nim
nim c -d:chroniclers.logBackendCustom app.nim
Set only one backend flag. Backend flags take precedence over package features, so
-d:chroniclers.logBackendNone disables logging even when Chronicles is
enabled. Without a backend flag, features.chroniclers.chronicles takes
precedence over features.chroniclers.std.
The old string selectors -d:chroniclers.logBackend=std and
-d:chroniclersLogBackend=std now produce compile errors. With no selection,
logging uses the empty none backend. The exported chroniclersLogBackend
constant reports the selected backend.
Custom Backends
Select custom and replace Chroniclers' empty custom_backend module with
your implementation. Add this to your application's config.nims:
patchFile("chroniclers", "custom_backend", "myapp/log_backend")
The replacement path is relative to the config.nims file. Then compile with
-d:chroniclers.logBackendCustom. The unpatched module reports an error
with the setup instructions.
The backend module must export templates for each supported level:
template trace*(eventName: static[string], props: varargs[untyped])
template debug*(eventName: static[string], props: varargs[untyped])
template info*(eventName: static[string], props: varargs[untyped])
template notice*(eventName: static[string], props: varargs[untyped])
template warn*(eventName: static[string], props: varargs[untyped])
template error*(eventName: static[string], props: varargs[untyped])
template fatal*(eventName: static[string], props: varargs[untyped])
For non-structured backends, import chroniclers/backend_helpers and use
flattenLogMessage(eventName, props) to format fields the same way as the
built-in std/logging adapter.
Structured fields are passed through to Chronicles. Non-structured backends receive a flattened message such as:
request complete route=/items/42 status=200 elapsedMs=12.5
Development
Install dependencies with Atlas:
atlas install --feature:chronicles
Run tests:
nim test