Skip to content

elcritch/chroniclers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Select the backend with:

nim c -d:chroniclersLogBackend=chronicles app.nim
nim c -d:chroniclersLogBackend=std app.nim
nim c -d:chroniclersLogBackend=none app.nim

If chroniclersLogBackend is not set, Chroniclers uses Chronicles when feature.chroniclers.chronicles is enabled and compiles logging calls away otherwise.

Custom backends can be selected with chroniclersBackendModule:

nim c -d:chroniclersBackendModule=myapp/log_backend app.nim

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

About

Compile-time selectable structured logging facade for Nim

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages