Skip to main content

Module logging

Module logging 

Source
Expand description

The logger of the desktop release runners (nsh-macos-app, nsh-windows-app, nsh-linux-app): one filter, one rolling file in the app’s data directory, and the platform’s own place for each line.

  • What is logged: RUST_LOG when it is set, in env_logger‘s syntax (info, my_app=debug,js=info, warn,nsh_engine::updates=info); else the runners’ rule, warnings, errors and the app’s js lines (console.*), and every line from info up when run by nsh run.
  • Where: a rolling file, app.log in the directory nsh.json "logDir" names, else logs in the app’s data directory (log_directory, log_dir), whose path apps read (nsh_core::element::log_file, TS process.logFile), and the platform’s output the runner hands LogOptions::output (the unified log, the debugger’s output, stderr).
  • The file: one line per record, <UTC time> <LEVEL> <target>: <message>. Past MAX_FILE_BYTES it becomes app.1.log (the one before that app.2.log, …) and a new app.log starts; KEPT_FILES older files are kept. A file that cannot be made or written is left alone, tried again after RETRY_AFTER: the app and the platform’s output carry on without it.
  • Panics: written to the file whatever the filter, as ERROR panic: lines in the words Rust prints them in (with a backtrace when RUST_BACKTRACE asks for one), and then handed to the hook the process had, which prints them to stderr as before. A packaged app’s stderr is often nowhere (a Windows GUI program, a Mac app opened from Finder), so the file is where a crash can be read.

Structs§

LogOptions
What install sets up.

Constants§

KEPT_FILES
How many rolled-over files are kept beside app.log (app.1.log up to app.<KEPT_FILES>.log).
MAX_FILE_BYTES
The size past which the log file rolls over to app.1.log.
RETRY_AFTER
How long the logger waits before it tries again to open a log file it could not open or write.

Functions§

install
Makes the runners’ logger the process’s logger, filtered by RUST_LOG when it is set, and records its file for nsh_core::element::log_file. Returns whether it did: false when the process has a logger already.
log_dir
The directory of the log files of app app_id when it names no data directory of its own: logs in the one under the system’s directory for apps’ data (<support dir>/<app id>/logs). None where the system has none.
log_directory
The directory the desktop runners write the log files of app app_id in: log_dir (nsh.json "logDir", already resolved) when the app names one, else logs in data_dir ("dataDir"), else log_dir’s default.

Type Aliases§

LogOutput
The platform’s own place for each line the filter lets through.