Next: , Previous: , Up: API  


1.4 (scriba file)

This module implements a plaintext file logging backend with size based rotation. Log lines keep the same bracketed layout as the console backend, so a file written by Scriba can be tailed, grepped and shipped by log aggregators without any transformation.

Rotation happens when the next line would push the file past ‘#:max-size’ bytes. The current file is renamed to ‘<path>.1’, older backups are shifted up, and the oldest backup beyond ‘#:max-backups’ is removed. As a result a file never grows past ‘#:max-size’ unless a single line is larger than it. Setting ‘#:max-size’ to #f disables rotation entirely, and ‘#:max-backups’ to 0 keeps no history (the file is simply truncated). ‘rotate-file!’ rotates on demand, for example from a SIGHUP handler or a cron job.

One sink, meaning one open port and one rotation policy, is kept per path. Loggers created for the same path share it, which keeps independent loggers (say one for ‘app’ and one for ‘db’) from fighting over rotation and from reopening the file on every message. Rotation is a property of the file rather than of a logger, so when a later logger asks for a different policy on the same path, that policy takes over for everyone.

1.4.1 Parameters

Parameter: default-file-max-backups

Default value:

5
Parameter: default-file-max-size

Default value:

10485760
Parameter: default-file-path

Default value:

#f

1.4.2 Procedures

Procedure: %make-scriba-file-logger KEY: #:path #:name #:level #:context-filter #:tag-filter #:timestamp-format #:flush-port? #:layout #:line-ending #:max-size #:max-backups

Creates a logger appending lines to the file at PATH.

PATH is required (there is no sensible default file) and its parent directory must already exist. MAX-SIZE and MAX-BACKUPS control rotation, see the module commentary.

Procedure: file-sink-open? path

Is a Scriba file sink currently open for PATH?

Procedure: rotate-file! path

Rotates PATH right now, returning #t.

PATH must be a path that a Scriba file logger has already opened; that is what makes the open port and the rotated files agree on which file is current.

Procedure: scriba-file-logger . kwargs

Undocumented procedure.


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