JFLib

plat/log.rs#

Source: lib/plat/log.rs

log -- the process's log: levels, a ring of the newest lines for crash reports, stderr
and a rotating file

  LOG_ERROR 1, LOG_WARN 2, LOG_INFO 3, LOG_DEBUG 4, LOG_TRACE 5 (LOG_OFF 0)
  log!(LOG_INFO, "net", "{} bytes from {}", n, host)   formats only when the level is on
  log_line(level, target, msg)         one line; log_error / log_warn / log_info /
                                       log_debug(target, msg) are short forms
  log_quiet(level, target, msg)        ring and file only (the text went to stderr already)
  log_enabled(level) -> bool           any sink wants this level
  log_levels(stderr, file)             the levels of the sinks (default WARN / INFO; the
                                       ring keeps everything up to DEBUG); jfgui_LOG=error |
                                       warn | info | debug | trace sets both
  log_file(Some(path), max_bytes, keep) -> bool   append the lines to path (a vfs name like
                                       logs://app.log or an OS path); when it grows
                                       beyond max_bytes it moves to path.1 (path.1 to path.2,
                                       ... up to keep files) and a new one starts; None stops.
                                       false: it cannot be opened, or it is a file of a
                                       provider without streams or OS files (its bytes would
                                       reach the provider only when the log stops)
  log_recent(max_bytes) -> String      the newest whole lines of the ring (a crash report,
                                       a "copy log" button)

Lines: "2026-10-17 19:58:07.123 WARN  net: text" (Windows local time, elsewhere UTC with a
Z); line breaks inside the text become " | ".  The ring holds 64 KiB.  A crash or panic
writes the ring to stderr and a crash line to the log file before the app's crash hook runs
(rt::crash pre-hook, installed with the first line); it takes the locks only if they are
free, so a thread that crashed while logging cannot stop the report, and it neither
allocates nor waits: a stuck stderr is given up, the line goes to an OS file only (not a
mount's stream) and does not rotate it.
LOG_OFF: u32 = 0
LOG_ERROR: u32 = 1
LOG_WARN: u32 = 2
LOG_INFO: u32 = 3
LOG_DEBUG: u32 = 4
LOG_TRACE: u32 = 5
  • fn log_levels(stderr: u32, file: u32) set the levels of stderr and the file (jfgui_LOG wins over both)

  • fn log_enabled(level: u32) -> bool any sink wants lines of this level

  • fn log_line(level: u32, target: &str, msg: &str) one line to every sink that wants its level

  • fn log_quiet(level: u32, target: &str, msg: &str) one line to the ring and the file only (its text went to stderr already)

  • fn log_error(target: &str, msg: &str) a LOG_ERROR line

  • fn log_warn(target: &str, msg: &str) a LOG_WARN line

  • fn log_info(target: &str, msg: &str) a LOG_INFO line

  • fn log_debug(target: &str, msg: &str) a LOG_DEBUG line

  • fn log_fmt(level: u32, target: &str, args: core::fmt::Arguments) (log!) a formatted line

  • log!(...) log!(LOG_INFO, "target", "format", args...): a line, formatted only when its level is on

  • fn log_recent(max_bytes: usize) -> String the newest whole lines of the ring, at most max_bytes

  • fn log_file(path: Option<&str>, max_bytes: u64, keep: u32) -> bool write the lines to path (rotated at max_bytes, keep older files path.1 .. path.keep); None stops -> false when the file cannot be opened, or when its bytes would reach the provider only at the end (a mount without streams or OS files: nothing of the last segment or a crash line would arrive before the log stops)

Source: docs/API.md in the JFLib repository.