io.randomseed.utils.log
added in 1.0.0
Random utils, opinionated logging support functions.
*already-logged*
dynamic
When true, indicates the current exception has already been logged and should not be logged again by outer handlers.
debug
macro
(debug msg-or-throwable)(debug mdc-or-throwable msg)(debug mdc throwable msg)Logs a message at DEBUG level.
default-config
Default logging configuration map: INFO level with console output enabled.
err-with-val
macro
(err-with-val msg & more)Logs msg (and optional extra parts) at ERROR level. When extra arguments are present, the last one is returned as the expression value.
error
macro
(error msg-or-throwable)(error mdc-or-throwable msg)(error mdc throwable msg)Logs a message at ERROR level.
fatal
macro
(fatal msg-or-throwable)(fatal mdc-or-throwable msg)(fatal mdc throwable msg)Logs a message at FATAL level.
info
macro
(info msg-or-throwable)(info mdc-or-throwable msg)(info mdc throwable msg)Logs a message at INFO level.
init!
(init! config)Initialises the logging subsystem. Snapshots the current Logback state, detaches previously installed appenders, configures the JSON decoder and the context transformer, then starts unilog. Returns a map with :config, :previous-ctx-transformer, :previous-logback, and :unilog keys suitable for passing to stop! to restore the prior state.
initialize-context-transformer!
(initialize-context-transformer! transform-map)Installs a cambium context transformer derived from transform-map. Returns the previous transformer (or nil if nothing changed).
initialize-json-decoder!
(initialize-json-decoder!)Configures the JSON decoder for structured logging: enables big-decimal parsing, installs the cambium destringify codec and sets the global FlatJsonLayout decoder.
log
macro
(log level msg-or-throwable)(log level mdc throwable msg)(log logger level msg-or-throwable)(log logger level mdc-or-throwable throwable msg)Logs a message at the given level. Delegates to cambium.core/log.
log-context
macro
(log-context context & body)Evaluates body with additional MDC logging context (a map).
log-exceptions
macro
(log-exceptions & body)Wraps body in a try/catch that logs any Throwable at ERROR level (with the exception stringified in the MDC context) and re-throws it with *already-logged* bound to true so outer handlers can avoid duplicate logging.
msg-with-val
macro
(msg-with-val msg & more)Logs msg (and optional extra parts) at INFO level. When extra arguments are present, the last one is returned as the expression value.
preprocess-config
(preprocess-config config)Pre-processes logging config by expanding Java property placeholders in :file paths of each appender entry. Marks the config as :preprocessed to avoid repeated processing. Returns config unchanged when no :appenders key is present or the config has already been preprocessed.
start!
(start! config)Starts the logging subsystem by delegating to unilog/start-logging! with the given config map.
stop!
(stop! {:keys [previous-ctx-transformer previous-logback]})Tears down the logging subsystem and restores the state captured by init!. Detaches appenders prefixed with "io.randomseed.utils.log.", restores the previous context transformer and the previous Logback snapshot. Returns nil.
trace
macro
(trace msg-or-throwable)(trace mdc-or-throwable msg)(trace mdc throwable msg)Logs a message at TRACE level.
warn
macro
(warn msg-or-throwable)(warn mdc-or-throwable msg)(warn mdc throwable msg)Logs a message at WARN level.
warning
macro
(warning msg-or-throwable)(warning mdc-or-throwable msg)(warning mdc throwable msg)Alias for warn. Logs a message at WARN level.
with-ctx
macro
(with-ctx context & body)Alias for log-context. Evaluates body with additional MDC logging context.