1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// SPDX-License-Identifier: MPL-2.0
//! Kernel logging API.
//!
//! This module provides the logging facade for OSTD and all OSTD-based crates.
//! It uses eight log levels matching the severity levels described in `syslog(2)`.
//!
//! # Setup: defining `__log_prefix`
//!
//! Every crate that uses the logging macros
//! must define a `__log_prefix` macro at its crate root (`lib.rs`),
//! before any `mod` declarations.
//! This prefix is prepended to every log message from the crate.
//!
//! ```rust,ignore
//! // Set this crate's log prefix for `ostd::log`.
//! macro_rules! __log_prefix {
//! () => {
//! "virtio: "
//! };
//! }
//!
//! mod device; // all modules inherit the "virtio: " prefix
//! ```
//!
//! It is recommended is to follow Linux's convention for log prefixes,
//! which uses the lowercase module name, followed by `: `.
//! For example: `"virtio: "`, `"pci: "`, `"uart: "`.
//!
//! # Quick start
//!
//! After defining `__log_prefix`, import the macros and use them:
//!
//! ```rust,ignore
//! use ostd::prelude::*;
//!
//! info!("boot complete");
//! warn!("feature X is not supported");
//! ```
//!
//! # Log levels
//!
//! Eight severity levels are provided, matching `syslog(2)`:
//!
//! | Level | Value | Meaning |
//! |---------|-------|------------------------------|
//! | Emerg | 0 | System is unusable |
//! | Alert | 1 | Action must be taken |
//! | Crit | 2 | Critical conditions |
//! | Error | 3 | Error conditions |
//! | Warning | 4 | Warning conditions |
//! | Notice | 5 | Normal but significant |
//! | Info | 6 | Informational |
//! | Debug | 7 | Debug-level messages |
//!
//! ```rust,ignore
//! use ostd::prelude::*;
//!
//! emerg!("system is going down");
//! alert!("action required immediately");
//! crit!("critical failure in subsystem");
//! error!("operation failed: {}", err);
//! warn!("deprecated feature used");
//! notice!("configuration change applied");
//! info!("boot complete");
//! debug!("variable x = {:?}", x);
//! ```
//!
//! # `log` crate bridge
//!
//! A bridge forwards messages from third-party crates
//! that use the [`log`](https://docs.rs/log) crate (e.g., `smoltcp`)
//! to the OSTD logger.
//! First-party code should use OSTD's macros directly.
//!
//! # Per-module prefix overrides
//!
//! A subsystem module can override the crate-level prefix
//! by defining its own `__log_prefix` at the top of its `mod.rs`,
//! before any `mod child;` declarations.
//! Child modules inherit the override via textual scoping:
//!
//! ```rust,ignore
//! // Set this module's log prefix for `ostd::log`.
//! macro_rules! __log_prefix {
//! () => {
//! "iommu: "
//! };
//! }
//!
//! mod fault; // inherits "iommu: " prefix
//! mod registers; // inherits "iommu: " prefix
//! ```
//!
//! # Limitations
//!
//! ## No attributes on `__log_prefix` definitions
//!
//! Do not put `#[rustfmt::skip]` or any other attribute
//! on `__log_prefix` definitions.
//! Rust treats attributed `macro_rules!` items as "macro-expanded,"
//! which triggers E0659 ambiguity with definitions at other scopes.
//! See the design doc in `log/macros.rs` for the full explanation.
//!
//! # Backend
//!
//! An OSTD-based kernel can register a custom [`Log`] implementation via [`inject_logger`].
//! Before a backend is registered, messages are printed through the early-boot console.
use LogCrateBridge;
pub use ;
/// Initializes the OSTD logging subsystem.
///
/// Parses the `ostd.log_level` kernel command line parameter, sets the
/// runtime max level, and registers the `log` crate bridge.
pub
/// Parses a log level string into a [`LevelFilter`].
///
/// Accepts: `"off"`, `"emerg"`, `"alert"`, `"crit"`, `"error"`,
/// `"warn"` / `"warning"`, `"notice"`, `"info"`, `"debug"`.
/// Returns `None` for unrecognized strings.