- Scheme 95.5%
- Nix 1.8%
- Shell 1.2%
- Makefile 0.8%
- Dockerfile 0.7%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .woodpecker | ||
| assets | ||
| packaging | ||
| src/scriba | ||
| test/veritas | ||
| .dockerignore | ||
| .gitattributes | ||
| .gitignore | ||
| AGENTS.md | ||
| CHANGELOG.org | ||
| channels.scm | ||
| COPYING | ||
| default.nix | ||
| Dockerfile | ||
| flake.lock | ||
| flake.nix | ||
| guix.scm | ||
| logo.svg | ||
| maak.scm | ||
| manifest.scm | ||
| README.org | ||
scriba
A structured logging framework for GNU Guile Scheme.
⚠️ THIS REPOSITORY WAS ARCHIVED HERE AND MOVED TO GITHUB, GO TO: https://github.com/jjba23/scriba ⚠️
Scriba turns scattered display calls into real log lines: levelled, taggable,
carrying structured context, and routable to a console, a rotating file, syslog
or JSON — without touching your application code when you move from your laptop
to production.
"Scriba is a structured logging library for GNU Guile that prioritizes flexibility and observability. It provides modular log routing, formatting, and filtering, allowing developers to generate human-readable console logs during development, machine-readable JSON logs for production environments, and rotating plaintext logs on disk.
Key features include an auto-logger configured via environment variables, dynamically scoped log contexts using Scheme parameters, ahead-of-time log level filtering, and minimal runtime overhead achieved through memoization and compile-time macros."
Links: Source & issues ·
API reference ·
Backlog & kanban ·
Changelog ·
Guix package: guile-scriba
At a glance
| You want to… | Scriba gives you… |
|---|---|
| Understand what your program is doing | log-info, log-warning, log-error and friends, with a level hierarchy |
| Correlate lines with a request | with-log-context — dynamically scoped key/value pairs |
| Turn categories of logs on and off | with-log-tags plus tag filters, with or without levels |
| Ship structured logs to Loki or Elasticsearch | A JSON backend that emits one object per line |
| Keep logs in a file that does not grow forever | A rotating file backend with size limits and backups |
| Change behaviour per environment | The scriba-auto-logger, configured by SCRIBA_* variables |
| Pay almost nothing for muted log statements | Ahead-of-time level filtering: a muted call is a no-op |
Find the complete technical API documentation here.
Available loggers: console, color-console, json, syslog and file.
Features
- Five backends, one API. Plain console, colour console, JSON, syslog (RFC 5424-shaped) and rotating files. Every backend accepts the same log calls, so switching is a configuration decision, not a refactor.
- Zero-cost muted levels. Level filtering happens once, at logger construction: a level below the threshold is bound to a no-op, skipping formatting, flushing and I/O entirely.
- Environment-driven configuration. The auto-logger reads
SCRIBA_*variables, so development and production differ only in their environment. - Logger memoization. Asking twice for the same logger configuration returns the same instance; creating loggers deep in a call stack is cheap.
- Structured context, no plumbing.
with-log-contextattaches key/value pairs to everything logged inside its body, using Guile'sparameterizerather than global mutable state or locks. - Tags and property-based filtering. Log with tags instead of levels, or alongside levels, and keep only the lines you care about.
- Layouts per backend. Choose which fields are rendered and in which order; a mistyped field name is an error, never a silently blank line.
- Any port is a destination.
stdout,stderr, a file port, a socket port, or a string port in your tests — all of Guile's I/O is available. - Files that stay manageable. Size-based rotation with a configurable number
of backups, UTF-8-correct byte accounting, and an on-demand
rotate-file!. - Tiny dependency footprint. Guile itself plus guile-json at runtime. No threads, no fibers, no daemons.
- Hackable by design. Logger construction is a handful of records, keyword arguments and macros — writing your own backend is a page of code (see below).
Ways to install
Four routes to the same 0.4.5, from the most automated to the most manual. They all build the tag this README documents.
From the Guix channel
GNU Guix is the functional package manager this project is developed with: a build is a pure function of its inputs, so the same recipe gives the same result everywhere, and an upgrade that goes wrong can be rolled back.
The jointhefreeworld channel carries guile-scriba at 0.4.5, so a checkout of the channel is enough — no package definition to write:
git clone https://codeberg.org/jjba23/guix-jointhefreeworld.git
guix install -L ./guix-jointhefreeworld guile-scriba
Add the channel to $HOME/.config/guix/channels.scm (the channel's README has the four lines) and a plain guix install guile-scriba keeps working on every later guix pull.
From the Nix flake
Nix offers the same declarative, reproducible model with its own language, its own store and a binary cache, and it is a natural fit if the rest of your machine is already described in Nix.
The jointhefreeworld flake builds this project with this repository's own expression, so the package cannot drift from the source:
nix build github:jjba23/nix-jointhefreeworld#guile-scriba
The same attribute is available as an overlay, so pkgs.jointhefreeworld.guile-scriba works inside a NixOS or home-manager configuration too.
As a container image
Podman or Docker is the route that puts nothing on the host: the Dockerfile in this repository builds the project in a builder stage and copies only what it installed into a runtime stage, so the image is small and the host keeps its own toolchain untouched.
podman build -t scriba . # docker build -t scriba . also works
podman run --rm -it scriba
The image's entry point is Guile, with scriba on its load path, which makes it useful for a quick try and for reproducing a bug on a clean system.
As a distribution package
Debian, openSUSE and Arch each get the project through their own package manager. Packaging lives in this repository under packaging/ and is pinned to the same release tag, so the recipes and the sources they build are versioned together.
None of the three archives ships scriba yet, so these are recipes to build rather than packages to install from a mirror:
| Distribution | Package | How to build it |
|---|---|---|
| Debian, Ubuntu | scriba |
copy packaging/debian to the repository root, then dpkg-buildpackage -us -uc -b |
| openSUSE | scriba |
osc build with packaging/opensuse |
| Arch | scriba |
makepkg -si in packaging/arch |
Each recipe carries its own dependency list, so a missing library fails the build with its name rather than producing a package that cannot load.
Which one?
- Guix if you want the toolchain the project is tested with, and the ability to roll back a bad upgrade.
- Nix if the rest of your machine is already declarative; the flake pins nixpkgs and gives you a binary cache.
- Container if you only want to try the release, or reproduce a report on a machine that has nothing installed.
- Distribution package if you want the project managed by the same tool as the rest of your system, with its licence, manual page and launcher in the usual places.
Quick Start
1. Install it
With Guix, one command:
guix install guile-scriba
Prefer a throwaway environment? guix shell guile-scriba guile -- guile your-script.scm
works too, without installing anything permanently.
2. Write your first log line
Save this as hello-log.scm:
(use-modules (scriba auto)
(scriba scriba))
(define log (scriba-auto-logger))
(log-info log "Hello Scriba, 2 + 2 = ~a" (+ 2 2))
(with-log-context '((request-id . "req-1234"))
(log-warning log "Disk almost full"))
3. Run it
guile hello-log.scm
[INFO] [2026-10-18 17:49:47 CEST] Hello Scriba, 2 + 2 = 4 [WARNING] [2026-10-18 17:49:47 CEST] Disk almost full [request-id=req-1234]
That is the whole setup: two imports, one call to scriba-auto-logger, and
log statements as you need them. No configuration files, no init rituals ✨
4. Change everything with one environment variable
The same program, unchanged, becomes structured JSON for your log shipper:
SCRIBA_LOGGER=json SCRIBA_LOG_LAYOUT=level,message,context guile hello-log.scm
{"level":"INFO","message":"Hello Scriba, 2 + 2 = 4"}
{"level":"WARNING","message":"Disk almost full","request-id":"req-1234"}
Swap json for file (with SCRIBA_FILE_PATH=/var/log/app.log), syslog or
color-console as needed. That is the everyday Scriba workflow.
Installing
With Guix (recommended)
guile-scriba is packaged in Guix proper:
guix install guile-scriba
Or, better, declare it in your project's manifest.scm next to Guile:
(specifications->manifest
(list "guile" "guile-json" "guile-scriba"))
and let guix shell provide it:
guix shell -m manifest.scm -- guile my-program.scm
Version note: this tree is release v0.4.5, a maintenance release. Since v0.4.0 – the release that added the rotating file backend, the shared
(scriba layout)module and the new test and benchmark suites – the only source change is the log-level suite in the tests, which had stopped compiling and runs again here. No API, behaviour or documentation of the library changed; see CHANGELOG.org for what each release contains.
From this repository (latest code)
Clone and use the pinned development environment, which includes Guile, Guile JSON, Veritas and the documentation tooling:
git clone https://codeberg.org/jjba23/scriba.git
cd scriba
guix shell -m manifest.scm -- guile -L ./src -c '(display "ready\n")'
guix.scm packages the working tree itself (version dev), which is handy for
building a local package or a guix shell -f guix.scm:
guix shell -f guix.scm -- guile -L ./src -c '(use-modules (scriba console))'
Manually, without Guix
Scriba is plain Scheme source; nothing needs compiling. Clone the repository, make sure guile-json is available, and point Guile at the source tree:
git clone https://codeberg.org/jjba23/scriba.git
export GUILE_LOAD_PATH="$PWD/scriba/src:$GUILE_LOAD_PATH"
guile -c '(use-modules (scriba console)) (display "scriba loaded\n")'
If you prefer a package definition of your own, adapt the one in guix.scm:
(define-public guile-scriba
(package
(name "guile-scriba")
(version "x.x.x")
(source
(origin
(method git-fetch)
(uri (git-reference
(url "https://codeberg.org/jjba23/scriba.git")
(commit (string-append "v" version))))
(file-name (git-file-name name version))
(sha256
(base32 "<dependent on version>"))))
(build-system guile-build-system)
(arguments
(list
#:source-directory "src"))
(propagated-inputs (list guile-json-4))
(inputs (list guile-3.0))
(synopsis "Structured logging framework for Guile Scheme")
(description
"Scriba is a structured logging library for GNU Guile that prioritizes
flexibility and observability.")
(home-page "https://codeberg.org/jjba23/scriba")
(license license:lgpl3+)))
Requirements
| Requirement | Version | Notes |
|---|---|---|
| GNU Guile | 3.0 or newer | Tested with guile-3.0 and guile-next |
| guile-json | 4.x | Required only by the JSON backend and the auto-logger |
| POSIX system | — | Uses gethostname, stat, localtime, file rotation |
Development and testing additionally use Veritas (the test framework),
maak (task runner) and Documenta (API docs) — all provided by
manifest.scm.
Usage
The Auto-Configured Logger
While you can instantiate specific loggers manually, the simplest way to get started is with the auto-logger. It reads environment variables (and, in the future, Scheme configuration files) to automatically determine at runtime which logger to use and how to configure it.
This is especially useful for maintaining different logging behaviours between development and production environments. A common use-case is to use a pretty and colourful console logger in local development, and structured JSON logging in production, for logs to be parsed and aggregated by tools like Loki.
(use-modules (scriba auto)
(scriba scriba))
(define log (scriba-auto-logger))
(log-info log "Hello Scriba!")
(with-log-context '((key-1 . value-1))
(log-info log "Message with context"))
Note: logger creation is memoized. Subsequent calls to create the same logger (even elsewhere in your codebase) are instant, because the result is only computed once.
Because the get-env-* functions act as defaults for the #:key arguments of
%make-scriba-auto-logger, you can override the environment programmatically
too: (scriba-auto-logger #:level 'trace).
Choosing a Backend
Each logger supports a shared set of options, with defaults that may differ per backend. See src/scriba for the full definitions, and the unit tests (log-spec.scm, auto-log-spec.scm) for more elaborate configurations.
Loggers are optionally named entities responsible for emitting logs. They are the primary interface between your application and Scriba; instantiate them directly when you want full control and do not need the auto-logger.
Console logger
Bracketed plaintext — ideal for terminals, sidecars and log files.
(use-modules (scriba scriba)
(scriba console))
(define log (scriba-console-logger #:name 'app
#:level 'info
#:layout '(level time name message context)))
(log-info log "1 + 1 = ~a" (+ 1 1))
(log-debug log "never printed: below the level")
(log-message log "This message is always logged, no level involved")
(log-error log "A critical error occurred")
[INFO] [2026-10-18 17:49:47 CEST] [app] 1 + 1 = 2 [2026-10-18 17:49:47 CEST] [app] This message is always logged, no level involved [ERROR] [2026-10-18 17:49:47 CEST] [app] A critical error occurred
Colour console logger
The same layout, with ANSI colours per level:
(use-modules (scriba scriba)
(scriba color-console))
(define log (scriba-color-console-logger #:level 'info))
(log-info log "1 + 1 = ~a" (+ 1 1))
(log-error log "A critical error occurred")
Levels map to grey (trace), cyan (debug), blue (info), green (success), yellow (warning), red (error) and bold red (critical). Emit raw ANSI escapes only when the destination is a terminal; for files and pipes prefer the plain console or JSON backend.
JSON logger
One JSON object per line, ready for Loki, Elasticsearch, Datadog, or jq.
(use-modules (scriba scriba)
(scriba json))
(define log (scriba-json-logger #:level 'info
#:layout '(level time host message context)))
(with-log-context '((request-id . "req-1234"))
(log-info log "Hello Scriba!"))
{"level":"INFO","time":"2026-10-18 17:49:47 CEST","host":"thinkpad","message":"Hello Scriba!","request-id":"req-1234"}
Context entries are inlined as top-level keys, tags become an array
("tags":["db"]), and #:pretty? #t switches to indented output for humans:
{
"level": "WARNING",
"message": "Something suspicious happened"
}
Syslog logger
RFC 5424-shaped framing:
<PRI>VERSION TIMESTAMP HOST APP-NAME PROCID MSGID STRUCTURED-DATA MSG
The facility is user (1) and the version is 2, so the priority is
8 + severity — 14 for info, 12 for warning.
(use-modules (scriba scriba)
(scriba syslog))
(define log (scriba-syslog-logger #:level 'info))
(log-info log "2 + 2 = ~a" (+ 2 2))
(with-log-context '((tenant . "acme"))
(log-warning log "Something suspicious happened"))
<14>2 2026-10-18T17:49:47+0200 thinkpad 49817 - 2 + 2 = 4 <12>2 2026-10-18T17:49:47+0200 thinkpad 49817 - [tenant="acme"] Something suspicious happened
The syslog backend also understands the extra process-id and message-id
layout fields.
File logger
The file logger appends the same bracketed plaintext layout as the console
logger, and rotates the file when it grows past #:max-size.
(use-modules (scriba scriba)
(scriba file))
(define log (scriba-file-logger #:name 'app
#:path "/var/log/my-app.log"
#:level 'info
#:max-size (* 10 1024 1024) ; 10 MiB per file
#:max-backups 5))
(log-info log "2 + 2 = ~a" (+ 2 2))
How rotation behaves:
- The current file is renamed to
<path>.1, older backups shift up, and the backup beyond#:max-backupsis removed. A file therefore never grows past#:max-sizeunless a single line is longer than it. #:max-size #fdisables rotation;#:max-backups 0truncates the file when it fills up instead of keeping history.- Rotation happens before the line that would overflow is written, and the size is measured in UTF-8 bytes, so accented text is counted correctly.
- The parent directory must exist; the log file itself is created on demand.
(rotate-file! path)rotates on demand (say from aSIGHUPhandler), and(file-sink-open? path)reports whether a sink is currently open.- Rotation is a property of the file, not of a logger: loggers that share a path share one open port, and the most recently requested policy applies. Several processes appending to the same file is safe, but only one of them should own rotation.
# rotate by hand, then keep logging (rotate-file! "/var/log/my-app.log") ; => #t (file-sink-open? "/var/log/my-app.log") ; => #t
Set #:flush-port? #f (or SCRIBA_FLUSH_PORT=false) to let the port buffer
lines instead of flushing every message; this trades durability for speed.
Example log lines, side by side
Console:
[INFO] [2026-05-24 11:23:06 CEST] Hello Scriba, 2 + 2 = 4! [INFO] [2026-05-24 11:23:06 CEST] [sample-1=value-1] Some log with context [2026-06-03 11:56:35 CEST] [#hello #world] Yes! Log with tags! [planet=earth]
JSON:
{"level":"INFO","time":"2026-05-24 11:23:06 CEST","message":"Some log with context","sample-2":"value-2"}
{"level":"WARNING","time":"2026-05-24 11:23:06 CEST","message":"some kind of warning"}
{"tags":["performance"],"time":"2026-06-03 11:56:35 CEST","host":"thinkpad","message":"Slept 0 seconds"}
Syslog:
<14>2 2026-05-29T10:56:49+0200 thinkpad 37222 - Hello Scriba! <14>2 2026-05-29T10:56:49+0200 thinkpad 37222 - [sample-1="value-1"] Some log with context <12>2 2026-05-29T10:56:49+0200 thinkpad 37222 - some kind of warning <14>2 2026-06-03T11:59:18+0200 thinkpad 80672 - Not gonna sleep! [#performance #benchmark]
Log Levels
For Scriba, log level is an opt-in concept. Not every system benefits from the same kind of log filtering. Other approaches, like tag-based or property-based logging, are powerful as well.
So you can call log-info, or just call log-message if you always want to log.
Inside Scriba, log level #t means always log, and #f means never log.
A logging action is executed only if its designated level is at or above the effective level of the configured logger:
A log action of level L issued to a logger having an effective level Q is enabled if L ≥ Q.
The standard hierarchy is:
trace < debug < info < success < warning < error < critical
Logger construction validates the level, so a typo such as #:level 'verbose
raises an error instead of silently muting every log statement:
raised scriba-invalid-log-level: Invalid log level verbose; expected #t, #f or one of (trace debug info success warning error critical)
#:level #f mutes everything, including log-message; #:level #t lets
everything through.
Log Context
For better observability, it is often useful to attach dynamic metadata to your log lines. Scriba handles this seamlessly via contexts:
(with-log-context '((request-id . "req-1234") (user . "alice"))
(log-info log "Fetching database records...")
;; Any deeper function calls that log will automatically include this context!
(do-some-work a b c))
Contexts nest: each with-log-context appends to the current one for the
duration of its body, and unwinds automatically — no cleanup, no global state.
You can also filter logs by context, with the #:context-filter constructor
argument, which accepts an alist. Filtering is lenient (it compares symbols,
numbers and strings loosely).
(define log (scriba-console-logger #:name 'app
#:level 'info
;; only log when this context is present
#:context-filter '((some-key . "some-value"))))
(with-log-context '((some-key . "some-value"))
(log-info log "2 + 2 = ~a" (+ 2 2)))
Log Routing
In general, the most common use-case for programs is to emit log lines to standard output. From there you can capture the output and redirect as needed.
Some applications and users may require more advanced functionality, like logging to files, sockets, or network destinations. Scriba offers an easily configurable interface to log destinations, thanks to Scheme's excellent input/output port system.
By default:
(scriba-console-logger #:out-port (current-output-port)) ; stdout, generally
Logging to a file is a backend of its own, with rotation handled for you (see File logger):
(use-modules (scriba scriba)
(scriba file))
(define log (scriba-file-logger #:path "test.log"
#:max-size (* 5 1024 1024)
#:max-backups 3))
(log-info log "Hello Scriba!")
Any other port still works too, for example when a POSIX daemon hands you a file descriptor:
(let* ((file-port (open-output-file "test.log"))
(log (scriba-console-logger #:out-port file-port)))
(log-info log "Hello Scriba!")
(close-output-port file-port)) ; don't forget to close file ports!
Capturing Logs in Tests
A string port is the easiest way to assert on what your program logs:
(let* ((port (open-output-string))
(log (scriba-console-logger #:out-port port
#:layout '(level message))))
(log-info log "Hello Scriba!")
(get-output-string port))
;; => "[INFO] Hello Scriba!\n"
Line Endings
Log lines are terminated with a trailing newline by default. If your program writes prompts or partial lines to the same port, you can prepend the newline instead (the historical Scriba behaviour):
(scriba-console-logger #:out-port (current-output-port)
#:line-ending 'leading)
This is also configurable globally via the default-line-ending parameter, or
through SCRIBA_LINE_ENDING with the auto-logger.
Log Format
Customise the log format and disable fields you do not need with #:layout:
(define log (scriba-console-logger #:name 'app
#:level 'info
#:layout '(level tags time host name
context message)))
(log-info log "2 + 2 = ~a" (+ 2 2))
The fields a text backend understands are level, tags, time, host,
name, context and message; the syslog backend adds process-id and
message-id. Only the fields in the layout are rendered, in that order, and an
unknown field name is an error rather than a silently empty line. The same
field lists are available programmatically as text-layout-fields,
json-layout-fields and syslog-layout-fields.
raised scriba-invalid-layout: Unknown log layout field tyme; expected one of (level tags time host name context message)
With the auto-logger, SCRIBA_LOG_LAYOUT is comma separated:
SCRIBA_LOG_LAYOUT=level,time,name,message,context my-app
Bring your own backend
Every backend is just a formatter plus a port. Reuse the shared pieces — level filtering, tag/context filters, argument formatting — and only supply the line you want to produce. Here is a complete tab-separated logger:
(use-modules (scriba scriba)
(scriba layout))
(define* (make-tsv-logger #:key (level (default-log-level))
(out-port (default-out-port)))
(define (printer lvl)
(lambda (message . args)
(format out-port "~a\t~a\t~a~%"
(if (symbol? lvl) (symbol->string lvl) "-")
(format-plain-time "%Y-%m-%dT%H:%M:%S%z")
(format-log-message message args))))
(make-filtered-logger #:name 'tsv
#:level level
#:context-filter '()
#:tag-filter '()
#:log-message-proc (printer #t)
#:log-trace-proc (printer 'trace)
#:log-debug-proc (printer 'debug)
#:log-info-proc (printer 'info)
#:log-success-proc (printer 'success)
#:log-warning-proc (printer 'warning)
#:log-error-proc (printer 'error)
#:log-critical-proc (printer 'critical)))
(define log (make-tsv-logger #:level 'info))
(log-info log "started")
(log-error log "failed after ~a attempts" 3)
info 2026-10-18T17:49:47+0200 started error 2026-10-18T17:49:47+0200 failed after 3 attempts
Useful building blocks from (scriba layout): format-plain-time,
format-context, format-tags, format-name, make-text-printer. From
(scriba scriba): make-filtered-logger, format-log-message,
write-log-line, memoize-logger.
Configuration
Scriba resolves a setting in three layers, each overriding the one below it:
- a keyword at the call site:
(scriba-auto-logger #:level 'debug); - an environment variable:
SCRIBA_LOG_LEVEL=debug; - the Guile parameter default:
(default-log-level).
Because the parameter layer is consulted on every lookup, parameterize is a
per-thread, per-scope override that also works for memoized loggers — a
different port or level yields a different cache entry, never a stale logger.
The two tables below cover the environment layer and the parameter layer; the auto-logger is the only backend factory that reads the environment, so direct constructor calls are configured with keywords and parameters.
Environment Variables
The auto-logger checks for SCRIBA_ prefixed environment variables.
| Variable | Meaning | Default |
|---|---|---|
SCRIBA_LOGGER |
Backend: console, color-console, json, syslog or file |
console |
SCRIBA_LOG_LEVEL |
Minimum severity: trace, debug, info, success, warning, error, critical |
info |
SCRIBA_LOG_LAYOUT |
Comma-separated fields to render, e.g. level,time,message,context |
level,tags,time,name,message,context |
SCRIBA_TAG_FILTER |
Comma-separated tags; only lines carrying one of them are logged | empty (no filtering) |
SCRIBA_CONTEXT_FILTER |
Comma-separated key;value pairs, e.g. tenant;acme |
empty (no filtering) |
SCRIBA_TIMESTAMP_FORMAT |
strftime format string |
"%F %T %Z" (ISO-8601 for syslog) |
SCRIBA_OUT_PORT |
stdout or stderr |
(current-output-port) |
SCRIBA_FLUSH_PORT |
true or 1 to flush after every line |
#t |
SCRIBA_LINE_ENDING |
trailing or leading — where the newline goes |
trailing |
SCRIBA_JSON_PRETTY |
true or 1 to pretty-print JSON |
#f |
SCRIBA_FILE_PATH |
Destination file when SCRIBA_LOGGER=file (required by that backend) |
unset |
SCRIBA_FILE_MAX_SIZE |
Rotate after this many bytes, or off to never rotate |
10485760 (10 MiB) |
SCRIBA_FILE_MAX_BACKUPS |
How many rotated backups to keep (0 truncates instead) |
5 |
A few details that save you a debugging session:
- Unknown
SCRIBA_LOGGERvalues fall back to the plain console logger, so a typo never leaves you without logs. SCRIBA_LINE_ENDING,SCRIBA_FILE_MAX_SIZEandSCRIBA_FILE_MAX_BACKUPSare validated: a malformed value raises an error instead of being ignored.- A space-separated
SCRIBA_LOG_LAYOUTis one unknown field, and therefore an error. Use commas; blank entries around commas are ignored.
Defaults and Parameters
All defaults are Guile parameters, which means parameterize gives you
per-thread, per-scope overrides without touching global state:
(parameterize ((default-log-level 'warning)
(default-out-port (current-error-port)))
(define log (scriba-console-logger #:layout '(level message)))
(log-info log "muted by the parameterized default")
(log-warning log "shown"))
[WARNING] shown
| Parameter | Default | Purpose |
|---|---|---|
default-log-level |
'info |
Effective level for new loggers |
default-logger |
'console |
Backend the auto-logger picks |
default-out-port |
(current-output-port) |
Default destination port |
default-flush-port? |
#t |
Flush after every line |
default-time-format |
"%F %T %Z" |
strftime format for timestamps |
default-log-layout |
'(level tags time name message context) |
Fields rendered by text backends |
default-line-ending |
'trailing |
Where the newline goes |
default-tag-filter |
'() |
Tags a logger keeps |
default-context-filter |
'() |
Context pairs a logger requires |
default-json-pretty? |
#f |
Indented JSON output |
default-syslog-time-format |
ISO-8601 | Syslog timestamps |
default-file-path |
#f |
File backend destination |
default-file-max-size |
10485760 |
Rotation threshold in bytes |
default-file-max-backups |
5 |
Rotated files kept |
Logger construction also accepts #:name, #:level, #:layout,
#:out-port, #:flush-port?, #:line-ending, #:tag-filter,
#:context-filter, #:timestamp-format, and — for the JSON and file
backends — #:pretty?, #:path, #:max-size and #:max-backups.
Why Scriba?
A primary advantage of Scriba over standard display, write, or println
procedures is fine-grained control over log routing, formatting and filtering,
with the addition of structured context in logs.
By separating formatting, severity levels, and output destinations, Scriba offers modularity that makes extending the library — or writing your own custom logger — trivial. Scriba is built around the core abstraction of a logger, and it achieves high performance by memoizing computations and leveraging compile-time macro expansions (see scriba.scm).
Because every backend speaks the same small logger protocol, you can develop against a pretty colourised console and ship the very same code with JSON logs, or into a rotating file, or to syslog. Nothing in your application changes.
Observability and Structured Logging
In modern software development, simply writing (display "\nError happened")
is no longer enough. As applications grow in complexity, understanding their
internal state in production (observability) becomes critical.
In practice, we see that traditional unstructured logs are nice and easy for humans to read, but notoriously difficult for machines to parse, search, and alert on.
That's why structured logging is important. In that mindset, we treat logs not as strings of text, but as structured data (typically JSON).
By attaching key-value pairs (context) to your logs, you allow log aggregators (think Grafana Loki, Elasticsearch, or Datadog) to instantly filter and visualize system behavior.
This also makes your life easier when debugging or trying to gain insights into your system.
Scriba gives you the tooling and provides an expressive logger API that can produce beautiful, human-readable logs in development, and robust, machine-readable structured logs in production, without changing a single line of your application code.
Log level is optional in Scriba, as log context can also provide log control.
Performance Under the Hood
Logging is a global cross-cutting concern, and it should never become the bottleneck in your application's execution.
Scriba achieves high throughput by front-loading as much computation as possible, using the macro system, and leveraging Guile's native optimizations.
Constructor Memoization
Creating and configuring loggers can involve reading environments, parsing strings, and allocating records.
Scriba exposes a memoize-logger macro that wraps logger factories with a
hash-table cache. If you request a logger with the exact same configuration
parameters anywhere in your codebase, Scriba instantly returns the cached
instance instead of rebuilding it.
Defaults derived from dynamically scoped parameters are evaluated and folded
into the cache key on every lookup, so
(parameterize ((default-out-port port)) (scriba-console-logger)) produces a
distinct logger per port instead of reusing a stale one. Environment-driven
auto-loggers work the same way: changing a SCRIBA_* variable yields a freshly
configured logger. If you need a brand new instance regardless of caching, call
the raw factory (e.g. %make-scriba-console-logger) directly.
Ahead-of-Time Level Filtering
Instead of checking the log severity level on every single log-* invocation,
Scriba evaluates the hierarchy exactly once when the logger is instantiated.
- Scriba permanently binds that logger's irrelevant functions to a lightning-fast no-op when they are below the level threshold.
- This means calling a disabled log level entirely bypasses string formatting, port flushing, and I/O routing ✨
#:level #f is the "never log" setting: it mutes every statement, including
log-message. #:level #t is the opposite, "always log": every severity
passes the threshold.
Cheap Lines When a Line Is Emitted
Profiling the enabled path paid off too, and the benchmark below is what keeps those gains honest:
- Timestamps are formatted once per second per format string, because
localtimeandstrftimeconsult the timezone database and dominate the cost of a short log line. - A message with no arguments is not passed through the formatter at all; the
string is emitted as is. A lone message containing
~is therefore literal rather than a (likely invalid) format directive. - Lines are written with
displayandnewlinerather thanformat, and field building usesstring-appendinstead of format directives.
Benchmarks
The benchmarks live where the tests live, in test/veritas/bench/logging-bench-spec.scm, and are driven by the same Veritas runner, so the project has one harness and one report format instead of two.
maak bench # or:
VERITAS_TEST_TYPE=bench guile -L ./src -L ./test \
-c '((@ (veritas runner) run-tests))'
Each benchmark form runs its thunk #:runs 3 times under Guile's statprof,
so the report is a profile per run: it says where the time went, not just how
much. Every workload repeats its operation a fixed number of times, and that
count is part of the benchmark name, so dividing the reported total by it gives
the cost per call. Every destination is /dev/null. The first benchmark is an
empty loop at the same call count, which is the baseline the muted figures are
measured against.
Typical output on an ordinary laptop, with the median of the three runs and the share of that total spent in the garbage collector:
workload calls total GC ns/call vs no-op
no-op thunk 4000000 0.0146s 0.0% 3.6 1.00x
muted log-debug (level info) 4000000 0.4629s 80.0% 115.7 31.75x
muted log-info (level #f) 4000000 0.4683s 79.3% 117.1 32.12x
tag filter miss (log-info) 2000000 0.5767s 75.9% 288.4 79.10x
context filter miss (log-info) 2000000 0.8209s 74.7% 410.5 112.59x
console INFO (literal message) 100000 0.3162s 55.6% 3162.5 867.50x
console INFO (2 format args) 20000 0.5999s 85.5% 29996.8 8228.42x
console INFO, flush disabled 20000 0.5971s 88.0% 29854.7 8189.44x
JSON INFO -> /dev/null 12000 0.6675s 68.3% 55624.8 15258.42x
file INFO -> /dev/null 20000 0.6071s 85.1% 30354.6 8326.56x
console INFO with tags + context 12000 0.8130s 89.1% 67749.7 18584.39x
memoized logger lookup 150000 0.6901s 84.4% 4601.0 1262.09x
raw logger construction 8000 1.1454s 91.1% 143177.2 39274.90x
Muted statements cost a little over a hundred nanoseconds, of which the call itself is a small part: an empty loop at the same count takes 3.6 ns a turn. Disabled backends never format, and an emitted literal line costs about three microseconds. The formatter dominates any line that carries arguments, which is why a literal message skips it.
Measured as an A/B inside one process with a plain CPU timer, a timestamped
literal line went from 27 µs with the old format-based path to ~2.6 µs with the
current one; the totals above read a bit higher than that because ~statprof
samples the run and its GC time is part of the total. The exact figures depend
on your hardware and its load, so treat them as orders of magnitude rather than
contracts.
Compile-Time Macros
A great deal of effort is taken to keep runtime overhead strictly minimal, and Scriba avoids doing much dynamic dispatch or runtime reflection.
Some boilerplate operations, such as generating keyword-based record
constructors (define-record-with-kw) and generating the domain logging
functions (define-logger-method), are handled by Scheme macros that expand
natively at compile-time.
Efficient Context Management
Attaching metadata via with-log-context and with-log-tags does not mutate
global state or require expensive thread-locking or mutexes or anything like
that.
It relies on Guile's native parameterize, which securely and efficiently
handles dynamically scoped, thread-local variables.
Log tags can be filtered on at runtime, so you can log exclusively lines that contain a tag — not even needing log levels — allowing more fine-grained control.
My Excuses & Good Logging from Day One
I'm sure you've felt this: when starting a new project, setting up a proper logging framework feels like an unnecessary chore.
We reach for (display "\ngot here") or format because it is frictionless.
But as the codebase grows, those scattered print statements become a noisy, unsearchable liability.
With Scriba, you have fewer excuses to procrastinate:
- "It is too much boilerplate to set up."
With
scriba-auto-logger, it takes exactly two lines of code to get a fully functioning, formatted logger. No complex configuration files or initialization rituals required. - "Structured JSON is terrible to read during local development."
You do not have to look at JSON while developing. Scriba's auto-logger
separates your code from your deployment environment. You get beautiful,
human-readable, even colourful console logs on your machine, and robust,
machine-parsable JSON logs in production — just by changing the
SCRIBA_LOGGERenvironment variable. - "I don't want to pass metadata through 20 function layers."
Scriba's
with-log-contextdynamically scopes your data. Attach arequest-idoruser-idat the top level of your application, and every log statement nested deep within your call stack will automatically include it, thanks to Scheme's parameters andparameterize. - "A logging library will slow down my high-performance prototype." Thanks to the attention put into performance, Scriba's overhead is minimal (and worth it). When a log level is disabled (e.g. debug logs in a production environment), the internal I/O and string formatting operations are entirely bypassed.
Start with Scriba on day one ✨
Development
Repository layout
scriba/ ├── src/scriba/ the library │ ├── scriba.scm core: records, levels, filters, context, memoization │ ├── layout.scm shared text formatting (timestamps, tags, context) │ ├── console.scm plaintext console backend │ ├── color-console.scm ANSI-coloured console backend │ ├── json.scm JSON backend │ ├── syslog.scm RFC 5424-shaped syslog backend │ ├── file.scm rotating file backend │ └── auto.scm environment-driven auto-logger ├── test/veritas/unit/ unit specs (Veritas) ├── test/veritas/bench/ benchmarks (Veritas) ├── CHANGELOG.org release notes ├── channels.scm pinned Guix revision ├── manifest.scm development environment ├── guix.scm package definition for the working tree └── maak.scm developer tasks
Tasks
Everything developer-facing goes through maak (and therefore through the
pinned Guix environment in channels.scm + manifest.scm):
| Task | What it does |
|---|---|
maak test |
Run every unit spec with Veritas |
maak bench |
Run the benchmarks under statprof |
maak fmt |
Format every .scm file with guix style |
maak docs |
Generate HTML API documentation into doc/ |
maak deploy |
Build the docs and publish them to the web directory |
maak repl |
Start an nREPL server (with src/ on the load path) for editors |
maak dev |
Watch the tree and re-run the tests on change |
maak |
List all tasks |
Tests
The suite is written with Veritas: nine spec files, 91 tests and 144 assertions, covering the severity matrix, tag and context filters, layout rendering and validation, JSON structure, syslog priorities, ANSI escapes, file rotation, UTF-8 byte accounting, environment configuration, auto-logger routing and line framing.
maak test
Prefer to run Guile directly? The equivalent is:
guile -L ./src -L ./test -c '((@ (veritas runner) run-tests))'
Failures are rerun-friendly: Veritas writes the failing tasks to
reports/last-failed.scm, and the process exits non-zero when anything fails.
Benchmarks
maak bench
See Benchmarks above for what the numbers mean and how to read the report.
API documentation
maak docs # writes doc/api/
Documentation generation uses Documenta and Texinfo; the published copy lives at jointhefreeworld.org/api-docs/scriba.
Continuous integration
Pushes are built by a Woodpecker pipeline (.woodpecker/byggsteg.yaml) that
hands the job to Byggsteg, which runs maak test and maak deploy inside
the same pinned Guix environment you use locally. Reproducibility is the point:
CI and your machine agree because they resolve the same channel commit.
Contributing
Contributing to free software is a uniquely beautiful act, because it embodies principles of generosity, collaboration, and empowerment.
We welcome everyone to the Scriba project and encourage active contribution in all forms: improving it, suggesting improvements, brainstorming, making it more modular or flexible. Feel free to contact me at <jjbigorra@gmail.com> to chat, discuss, or report feedback.
Ways to help
- Report a bug. Open an issue on Codeberg. A minimal reproduction, your
Guile version (
guile --version), and any relevantSCRIBA_*variables make a fix much faster. - Suggest a feature. Describe the problem you are trying to solve before the solution you have in mind — that is where the interesting discussion happens.
- Improve the docs. The README, the docstrings and the API docs are all fair game, and typos are still bugs.
- Write a backend. A backend is a few dozen lines (see Bring your own backend); if it is generally useful, we would love to ship it.
- Triage. Reproducing other people's reports is genuinely helpful work.
Sending a patch
- Fork the repository and create a branch.
- Add or update tests next to the change — test/veritas/unit is the place for behaviour, test/veritas/bench for performance.
- Run
maak testandmaak fmtbefore opening the change request — CI runs the same checks, so a green run locally means a green pipeline. - Describe why the change is needed in the commit message. Recent history
uses conventional prefixes, e.g.
feat: ✨ ...,fix: 🔧 ...,docs: 📝 .... - If the change is user-visible, update this README or the docstrings.
Not sure where to start? The backlog and kanban boards live at lucidplan.jointhefreeworld.org/tickets/scriba. Say hello first if you like — there is no such thing as a silly question.
Code of Conduct
This project adheres to the jointhefreeworld code of conduct. Find it here:
In summary, we foster an inclusive, respectful, and cooperative environment for all contributors and users of this free software project. Inspired by the ideals of the GNU Project, we strive to uphold freedom, equality, and community as guiding principles. We believe that collaboration in a community of mutual respect is essential to creating excellent free software.
AI Policy
This project adheres to the jointhefreeworld AI (Artificial Intelligence) policy.
Our core principle is simple: AI should assist human creativity and problem-solving, never replace human reasoning.
While tools like Large Language Models (LLMs) and interactive chatbots can be beneficial for reviewing, refactoring small functions, or acting as a sounding board, they should be used with moderation.
We require a human in the loop for all contributions.
Licensing
Scriba and all of its source code are free software, licensed under the GNU Lesser General Public License v3 (or newer, at your convenience).
https://www.gnu.org/licenses/lgpl-3.0.html
The documentation and examples provided with Scriba, including this document, are licensed under the GNU Free Documentation License v1.3 (or newer, at your convenience).
https://www.gnu.org/licenses/fdl-1.3.html
On Reproducibility: Why GNU Guix?
A build should never fail because "it worked on my machine". Reliable software development requires explicit, bit-for-bit reproducibility and a functional approach to package management and system deployment.
- Declarative Build Graphs: packages are pure functions of their inputs, with no implicit system state.
- Programmable with Guile: full system and package configurations written in Guile Scheme rather than rigid DSLs or static files.
- Time Travel: rebuild the exact system state from any point in git history
using
guix time-machine. - Atomic Operations: instantly upgrade or roll back environments without leaving orphaned dependencies or broken states.
- Unified Tooling: one tool manages development shells, isolated containers, package builds, and full system configurations.
Support the project
If you like my work, please support me by buying me a cup of coffee ☕ so I can continue with a lot of motivation.
Credits
Scriba stands on the shoulders of excellent free software:
- GNU Guile — the language and its parameter/port/macro machinery.
- guile-json — JSON serialisation for the JSON backend.
- Veritas — the test and benchmark runner used by this project.
- GNU Guix — reproducible development environments and packaging.
