Next: , Previous: , Up: API  


1.5 (scriba scriba)

This is the fundamental engine core for the Scriba logging framework. It manages internal logger records, logging level severities, dynamic execution context (MDC), optimization shortcuts, and global configuration parameters.

To minimize execution overhead from muted logs in high-throughput loops, Scriba uses a level filtering system at instantiation time (‘make-filtered-logger‘). If a severity level falls below the configured threshold, its logging procedure is bound directly to a zero-overhead no-op function (‘log-unit‘). This avoids unnecessary runtime level checks during iterative logging calls.

Thread/fiber-safe contextual tracing data can be appended dynamically using the ‘with-log-context‘ and ‘with-log-tags‘ macros.

1.5.1 Macros

Macro: memoize-logger x

Wraps a logger FACTORY-PROC with a caching layer.

Returns a new variadic procedure that accepts arbitrary keyword arguments (KWARGS). When called, it checks a private hash table to see if a logger has already been instantiated with the exact same KWARGS. If so, it returns the cached instance. If not, it calls FACTORY-PROC with the KWARGS, caches the resulting new logger, and returns it.

This ensures that multiple requests for identically configured loggers (e.g., the same name, level, and format) resolve instantly to the exact same object in memory, preventing redundant instantiations and reducing overhead.

Macro: with-log-context x

Dynamically append CTX (an alist) to the current log context for the duration of BODY.

Macro: with-log-tags x

Dynamically append TAGS (a list) to the current log tags for the duration of BODY.

1.5.2 Parameters

Parameter: current-log-context

Default value:

()
Parameter: current-log-tags

Default value:

()
Parameter: default-context-filter

Default value:

()
Parameter: default-flush-port?

Default value:

#t
Parameter: default-log-layout

Default value:

(level tags time name message context)
Parameter: default-log-level

Default value:

info
Parameter: default-logger

Default value:

console
Parameter: default-out-port

Default value:

#<output: file 1>
Parameter: default-tag-filter

Default value:

()
Parameter: default-time-format

Default value:

"%F %T %Z"

1.5.3 Procedures

Procedure: is-in-log-level? a b

Is log level A allowed in a B context?

Procedure: log-critical logger message . args

Emits a CRITICAL level log.

Use this for severe, unrecoverable failures that usually require immediate attention, cause data loss, or force the application to abort. MESSAGE is a format string applied to the optional ARGS.

Procedure: log-debug logger message . args

Emits a DEBUG level log.

Use this for diagnostic information helpful to developers when troubleshooting, but generally too noisy to be left enabled in production environments. MESSAGE is a format string applied to the optional ARGS.

Procedure: log-error logger message . args

Emits an ERROR level log.

Use this to record failed operations or exceptions that prevent a specific task from completing, even if the application as a whole can continue running. MESSAGE is a format string applied to the optional ARGS.

Procedure: log-info logger message . args

Emits an INFO level log.

Use this to highlight the normal, high-level progression of the application, such as service startups, configuration loads, or periodic heartbeat events. MESSAGE is a format string applied to the optional ARGS.

Procedure: log-message logger message . args

Emits a log.

Procedure: log-success logger message . args

Emits a SUCCESS level log.

Use this to explicitly indicate the successful completion of a significant operation, task, or transaction. MESSAGE is a format string applied to the optional ARGS.

Procedure: log-trace logger message . args

Emits a TRACE level log.

Use this for the most fine-grained, verbose informational events, such as step-by-step execution traces, loops, or variable dumps. MESSAGE is a format string applied to the optional ARGS.

Procedure: log-warning logger message . args

Emits a WARNING level log.

Use this to flag unexpected or potentially harmful situations that the application can gracefully recover from, such as deprecated API usage or temporary network retries. MESSAGE is a format string applied to the optional ARGS.

Procedure: make-filtered-logger KEY: #:name #:level #:context-filter #:tag-filter #:log-message-proc #:log-trace-proc #:log-debug-proc #:log-info-proc #:log-success-proc #:log-warning-proc #:log-error-proc #:log-critical-proc

Creates a logger, mapping excluded log levels and non-matching tags to log-unit.

Procedure: maybe-log-proc KEY: #:level #:target-level #:context-filter #:tag-filter #:proc

Conditionally evaluate and compile a logging procedure based on severity, tags, and context.

Compares TARGET-LEVEL against the logger’s configured LEVEL. If the level is explicitly disabled or falls below the required threshold, this returns the ‘log-unit‘ no-op procedure directly, avoiding downstream runtime overhead.

If the severity level is active, it returns a higher-order wrapper closure. When invoked, this closure inspects fluid parameters via ‘(current-log-tags)‘ and ‘(current-log-context)‘. If both constraints match their filters, it delegates formatting to PROC; otherwise, it safely routes execution to the no-op ‘log-unit‘.

Procedure: tag-match? filter-tags current-tags

Determine if the current execution context satisfies the logger’s tag filter. Returns #t if FILTER-TAGS is empty (acting as a wildcard), or if there is a lenient intersection (cross-comparing strings, symbols, and numbers) of at least one element between FILTER-TAGS and CURRENT-TAGS.

1.5.4 Variables

Variable: human-time-format
"%F %T %Z"
Variable: iso-8601-time-format
"%Y-%m-%dT%H:%M:%S%z"
Variable: log-friendly-time-format
"%F %T %z"
Variable: log-levels
(trace debug info success warning error critical)

Next: (scriba syslog), Previous: (scriba json), Up: API