Skip to main content

Crate log

Crate log 

Source
Expand description

Xila’s log subsystem.

Code logs through the log crate’s front end, re-exported here as error!, warning!, information!, debug! and trace!; one LoggerTrait installed with initialize receives every message whose level its LoggerTrait::enabled accepts, including those of third-party crates that use log directly. The macros evaluate their arguments before that check, so keep expensive work out of messages that are often filtered out. Outside Core, use the re-export xila::log.

§Levels

Level has five levels, from the most to the least severe: error, warning, information, debug and trace. LevelFilter adds off and selects a level and every more severe one. Both print and parse as those lowercase names (parsing ignores ASCII case), for options such as --log-level warning.

  • error: an operation failed, and something the person or the system expected did not happen.
  • warning: something unexpected happened, and the system recovered or carried on in a degraded way.
  • information: rare, notable events, such as a subsystem starting. Not per request, per packet or per click.
  • debug: details that help diagnose a problem.
  • trace: very frequent details, such as every call of a hot path.

§Message style

  • Write in English. Messages are for developers and are not localised, so never pass them through translation.
  • Use sentence case: start with a capital letter, and keep the rest lowercase except names and acronyms (Failed to mount the root file system).
  • Do not end a message with a period, an exclamation mark or a colon.
  • Do not start a message with Xila: or with the subsystem name (UDP:, WASI:): the target, the module path by default, already says where it comes from.
  • Show errors with their Display text ({error}), not with {:?}.
  • Put values after the text that names them (Failed to open {path}: {error}), with no space before a colon.
  • Never log secrets or personal data: typed or pasted characters, passwords, keys, random generator output, user names or full response bodies. Log a count or a result instead.

Macros§

debug
Logs a message at the debug level.
error
Logs a message at the error level.
information
Logs a message at the info level.
trace
Logs a message at the trace level.
warning
Logs a message at the warn level.

Structs§

ParseLevelError
The text given to Level::from_str or LevelFilter::from_str is not a level name.
Record

Enums§

Level
The severity of a log message, from the most severe (Level::Error) to the least (Level::Trace).
LevelFilter
The most verbose level that passes a filter, or LevelFilter::Off to let nothing pass.

Traits§

LoggerTrait

Functions§

initialize
is_initialized
snapshot_tail
Copy the most recent complete log lines into the caller’s buffer without blocking. Returns zero when no ring buffer is installed or a write is in progress.