-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Problem
Currently, when -Zbuild-analysis is enabled, Cargo writes log files, to ~/.cargo/log directly. This is good enough for a prototype but not ideal for stabilization.
We would like to have a way to configure the location of log files, and perhaps also have a way to write to stdout. Here are some use cases:
- feat(log): emit build-started JSON message with run_id #16632 (comment) — read-only file system that can't write to
CARGO_HOME. For example, crater runs Rust crates in a Docker container whereCARGO_HOMEis mounted as read-only. - Allow to specify the output file for --timings #12898 — Some build orchestrators are opinionated and restricted in where to store and find (log) files, as they want to avoid host side effect. Customizing log directory gives the flexibility. (this is related to Associate
--message-format=jsonwith session ID from-Zbuild-analysis#16576) - IDE tools may want to have a dedicated log directory under their control, rather than overriding
CARGO_HOMEentirely.
Proposed Solution
The easiest way to implement it is adding a config file to specify log directory location to the [build.analysis] table. For example,
[build.analysis]
enabled = true
log-dir = "<directory-path>"However, we have discussed that the structured logging might be more general that build analysis, and might be renamed to the [log] table. The field name log-path feels redundant when under log table. (Another issue of using [log] table is that it might conflict with CARGO_LOG env var, though that is a bit out of scope here).
We also need to consider if we want to support streaming to stdout, for example, a special - to stream to stdout.
Notes
No response