aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / log / README.md
| 1 | log |
| 2 | === |
| 3 | |
| 4 | A Rust library providing a lightweight logging *facade*. |
| 5 | |
| 6 | [](https://github.com/rust-lang/log/actions) |
| 7 | [](https://crates.io/crates/log) |
| 8 | [](https://docs.rs/log) |
| 9 |  |
| 10 | |
| 11 | * [`log` documentation](https://docs.rs/log) |
| 12 | |
| 13 | A logging facade provides a single logging API that abstracts over the actual |
| 14 | logging implementation. Libraries can use the logging API provided by this |
| 15 | crate, and the consumer of those libraries can choose the logging |
| 16 | implementation that is most suitable for its use case. |
| 17 | |
| 18 | |
| 19 | ## Minimum supported `rustc` |
| 20 | |
| 21 | See the `rust-version` field in `Cargo.toml` for the current minimum Rust toolchain version. |
| 22 | |
| 23 | This version is explicitly tested in CI and may be bumped in any release as needed. Maintaining compatibility with older compilers is a priority though, so the bar for bumping the minimum supported version is set very high. Any changes to the supported minimum version will be called out in the release notes. |
| 24 | |
| 25 | ## Usage |
| 26 | |
| 27 | ### In libraries |
| 28 | |
| 29 | Libraries should link only to the `log` crate, and use the provided macros to |
| 30 | log whatever information will be useful to downstream consumers: |
| 31 | |
| 32 | ```toml |
| 33 | [dependencies] |
| 34 | log = "0.4" |
| 35 | ``` |
| 36 | |
| 37 | ```rust |
| 38 | use log::{info, trace, warn}; |
| 39 | |
| 40 | pub fn shave_the_yak(yak: &mut Yak) { |
| 41 | trace!("Commencing yak shaving"); |
| 42 | |
| 43 | loop { |
| 44 | match find_a_razor() { |
| 45 | Ok(razor) => { |
| 46 | info!("Razor located: {razor}"); |
| 47 | yak.shave(razor); |
| 48 | break; |
| 49 | } |
| 50 | Err(err) => { |
| 51 | warn!("Unable to locate a razor: {err}, retrying"); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | ``` |
| 57 | |
| 58 | ### In executables |
| 59 | |
| 60 | In order to produce log output, executables have to use a logger implementation compatible with the facade. |
| 61 | There are many available implementations to choose from, here are some options: |
| 62 | |
| 63 | * Simple minimal loggers: |
| 64 | * [`env_logger`](https://docs.rs/env_logger/*/env_logger/) |
| 65 | * [`colog`](https://docs.rs/colog/*/colog/) |
| 66 | * [`simple_logger`](https://docs.rs/simple_logger/*/simple_logger/) |
| 67 | * [`simplelog`](https://docs.rs/simplelog/*/simplelog/) |
| 68 | * [`pretty_env_logger`](https://docs.rs/pretty_env_logger/*/pretty_env_logger/) |
| 69 | * [`stderrlog`](https://docs.rs/stderrlog/*/stderrlog/) |
| 70 | * [`flexi_logger`](https://docs.rs/flexi_logger/*/flexi_logger/) |
| 71 | * [`call_logger`](https://docs.rs/call_logger/*/call_logger/) |
| 72 | * [`std-logger`](https://docs.rs/std-logger/*/std_logger/) |
| 73 | * [`structured-logger`](https://docs.rs/structured-logger/latest/structured_logger/) |
| 74 | * [`clang_log`](https://docs.rs/clang_log/latest/clang_log) |
| 75 | * [`ftail`](https://docs.rs/ftail/latest/ftail/) |
| 76 | * Complex configurable frameworks: |
| 77 | * [`log4rs`](https://docs.rs/log4rs/*/log4rs/) |
| 78 | * [`logforth`](https://docs.rs/logforth/*/logforth/) |
| 79 | * [`fern`](https://docs.rs/fern/*/fern/) |
| 80 | * [`spdlog-rs`](https://docs.rs/spdlog-rs/*/spdlog/) |
| 81 | * Adaptors for other facilities: |
| 82 | * [`syslog`](https://docs.rs/syslog/*/syslog/) |
| 83 | * [`systemd-journal-logger`](https://docs.rs/systemd-journal-logger/*/systemd_journal_logger/) |
| 84 | * [`slog-stdlog`](https://docs.rs/slog-stdlog/*/slog_stdlog/) |
| 85 | * [`android_log`](https://docs.rs/android_log/*/android_log/) |
| 86 | * [`win_dbg_logger`](https://docs.rs/win_dbg_logger/*/win_dbg_logger/) |
| 87 | * [`db_logger`](https://docs.rs/db_logger/*/db_logger/) |
| 88 | * [`log-to-defmt`](https://docs.rs/log-to-defmt/*/log_to_defmt/) |
| 89 | * [`logcontrol-log`](https://docs.rs/logcontrol-log/*/logcontrol_log/) |
| 90 | * For WebAssembly binaries: |
| 91 | * [`console_log`](https://docs.rs/console_log/*/console_log/) |
| 92 | * For dynamic libraries: |
| 93 | * You may need to construct [an FFI-safe wrapper over `log`](https://github.com/rust-lang/log/issues/421) to initialize in your libraries. |
| 94 | * Utilities: |
| 95 | * [`log_err`](https://docs.rs/log_err/*/log_err/) |
| 96 | * [`log-reload`](https://docs.rs/log-reload/*/log_reload/) |
| 97 | * [`alterable_logger`](https://docs.rs/alterable_logger/*/alterable_logger) |
| 98 | * [`context-logger`](https://docs.rs/context-logger/*/context_logger) |
| 99 | |
| 100 | Executables should choose a logger implementation and initialize it early in the |
| 101 | runtime of the program. Logger implementations will typically include a |
| 102 | function to do this. Any log messages generated before the logger is |
| 103 | initialized will be ignored. |
| 104 | |
| 105 | The executable itself may use the `log` crate to log as well. |
| 106 | |
| 107 | ## Structured logging |
| 108 | |
| 109 | If you enable the `kv` feature, you can associate structured data with your log records: |
| 110 | |
| 111 | ```rust |
| 112 | use log::{info, trace, warn}; |
| 113 | |
| 114 | pub fn shave_the_yak(yak: &mut Yak) { |
| 115 | // `yak:serde` will capture `yak` using its `serde::Serialize` impl |
| 116 | // |
| 117 | // You could also use `:?` for `Debug`, or `:%` for `Display`. For a |
| 118 | // full list, see the `log` crate documentation |
| 119 | trace!(target = "yak_events", yak:serde; "Commencing yak shaving"); |
| 120 | |
| 121 | loop { |
| 122 | match find_a_razor() { |
| 123 | Ok(razor) => { |
| 124 | info!(razor; "Razor located"); |
| 125 | yak.shave(razor); |
| 126 | break; |
| 127 | } |
| 128 | Err(e) => { |
| 129 | // `e:err` will capture `e` using its `std::error::Error` impl |
| 130 | warn!(e:err; "Unable to locate a razor, retrying"); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | ``` |