Skip to content

Commit 28ac83d

Browse files
author
Jonathan Woollett-Light
committed
feat: Re-configurable logger
Updates tracing to the latest version from GitHub adding support for re-configuring the logger at run-time and removing the old logger format. Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
1 parent 5140892 commit 28ac83d

File tree

23 files changed

+243
-1146
lines changed

23 files changed

+243
-1146
lines changed

Cargo.lock

Lines changed: 11 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api_server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mmds = { path = "../mmds" }
2121
seccompiler = { path = "../seccompiler" }
2222
utils = { path = "../utils" }
2323
vmm = { path = "../vmm" }
24-
tracing = { version = "0.1.37", features = ["attributes"] }
24+
tracing = { git = "https://github.com/tokio-rs/tracing", rev = "27f688efb72316a26f3ec1f952c82626692c08ff", features = ["attributes"] }
2525

2626
[dev-dependencies]
2727
libc = "0.2.117"

src/api_server/src/request/logger.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ mod tests {
3737
}"#;
3838

3939
let mut expected_cfg = LoggerConfig {
40-
log_path: PathBuf::from("log"),
40+
log_path: Some(PathBuf::from("log")),
4141
level: Some(Level::Warn),
4242
show_level: Some(false),
4343
show_log_origin: Some(false),
44-
new_format: None,
4544
};
4645
match vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()) {
4746
VmmAction::ConfigureLogger(cfg) => assert_eq!(cfg, expected_cfg),
@@ -56,11 +55,10 @@ mod tests {
5655
}"#;
5756

5857
expected_cfg = LoggerConfig {
59-
log_path: PathBuf::from("log"),
58+
log_path: Some(PathBuf::from("log")),
6059
level: Some(Level::Debug),
6160
show_level: Some(false),
6261
show_log_origin: Some(false),
63-
new_format: None,
6462
};
6563
match vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()) {
6664
VmmAction::ConfigureLogger(cfg) => assert_eq!(cfg, expected_cfg),

src/cpu-template-helper/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ libc = "0.2.147"
1717
serde = { version = "1.0.171", features = ["derive"] }
1818
serde_json = "1.0.100"
1919
thiserror = "1.0.43"
20-
tracing = { version = "0.1.37", features = ["attributes"] }
20+
tracing = { git = "https://github.com/tokio-rs/tracing", rev = "27f688efb72316a26f3ec1f952c82626692c08ff", features = ["attributes"] }
2121

2222
vmm = { path = "../vmm" }
2323

src/dumbo/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ bench = false
1111
[dependencies]
1212
bitflags = "1.3.2"
1313
derive_more = { version = "0.99.17", default-features = false, features = ["from"] }
14-
tracing = { version = "0.1.37", features = ["attributes"] }
14+
tracing = { git = "https://github.com/tokio-rs/tracing", rev = "27f688efb72316a26f3ec1f952c82626692c08ff", features = ["attributes"] }
1515

1616
logger = { path = "../logger" }
1717
micro_http = { git = "https://github.com/firecracker-microvm/micro-http", rev = "4b18a04" }

src/firecracker/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ log = "0.4.19"
1919
serde_json = "1.0.100"
2020
thiserror = "1.0.43"
2121
timerfd = "1.5.0"
22-
tracing = { version = "0.1.37", features = ["attributes"] }
23-
tracing-subscriber = "0.3.17"
22+
tracing = { git = "https://github.com/tokio-rs/tracing", rev = "27f688efb72316a26f3ec1f952c82626692c08ff", features = ["attributes"] }
23+
tracing-subscriber = { git = "https://github.com/tokio-rs/tracing", rev = "27f688efb72316a26f3ec1f952c82626692c08ff" }
2424

2525
api_server = { path = "../api_server" }
2626
logger = { path = "../logger" }

src/firecracker/src/api_server_adapter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub(crate) fn run_with_api(
129129
api_payload_limit: usize,
130130
mmds_size_limit: usize,
131131
metadata_json: Option<&str>,
132+
logger_handles: vmm::vmm_config::LoggerHandles,
132133
) -> FcExitCode {
133134
// FD to notify of API events. This is a blocking eventfd by design.
134135
// It is used in the config/pre-boot loop which is a simple blocking loop
@@ -210,6 +211,7 @@ pub(crate) fn run_with_api(
210211
boot_timer_enabled,
211212
mmds_size_limit,
212213
metadata_json,
214+
logger_handles,
213215
),
214216
};
215217

src/firecracker/src/main.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn main_exitable() -> FcExitCode {
119119
.arg(
120120
Argument::new("id")
121121
.takes_value(true)
122-
.default_value(logger::DEFAULT_INSTANCE_ID)
122+
.default_value("anonymous-instance")
123123
.help("MicroVM unique identifier."),
124124
)
125125
.arg(
@@ -198,11 +198,6 @@ fn main_exitable() -> FcExitCode {
198198
"Whether or not to include the file path and line number of the log's origin.",
199199
),
200200
)
201-
.arg(
202-
Argument::new("new-format")
203-
.takes_value(false)
204-
.help("Whether to use the new logging output format."),
205-
)
206201
.arg(
207202
Argument::new("metrics-path")
208203
.takes_value(true)
@@ -279,9 +274,8 @@ fn main_exitable() -> FcExitCode {
279274
app_name: "Firecracker".to_string(),
280275
};
281276

282-
logger::INSTANCE_ID.set(String::from(instance_id)).unwrap();
283-
284-
if let Some(log_path) = arguments.single_value("log-path") {
277+
// Configure logger, the logger handles can be used to re-configure the logger with the API.
278+
let logger_handles = {
285279
let level_res = arguments
286280
.single_value("level")
287281
.map(|s| Level::from_str(s))
@@ -297,18 +291,19 @@ fn main_exitable() -> FcExitCode {
297291
}
298292
};
299293

300-
let logger_config = vmm::vmm_config::LoggerConfig {
301-
log_path: PathBuf::from(log_path),
294+
let config = vmm::vmm_config::LoggerConfig {
295+
log_path: arguments.single_value("log-path").map(PathBuf::from),
302296
level,
303297
show_level: Some(arguments.flag_present("show-level")),
304298
show_log_origin: Some(arguments.flag_present("show-log-origin")),
305-
new_format: Some(arguments.flag_present("new-format")),
306-
};
307-
308-
if let Err(err) = logger_config.init() {
309-
return generic_error_exit(&format!("Could not initialize logger: {}", err));
310299
};
311-
}
300+
match config.init() {
301+
Ok(h) => h,
302+
Err(err) => {
303+
return generic_error_exit(&format!("Could not initialize logger: {}", err));
304+
}
305+
}
306+
};
312307

313308
if let Some(metrics_path) = arguments.single_value("metrics-path") {
314309
let metrics_config = MetricsConfig {
@@ -398,6 +393,7 @@ fn main_exitable() -> FcExitCode {
398393
api_payload_limit,
399394
mmds_size_limit,
400395
metadata_json.as_deref(),
396+
logger_handles,
401397
)
402398
} else {
403399
let seccomp_filters: BpfThreadMap = seccomp_filters

src/jailer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ libc = "0.2.147"
1717
nix = { version = "0.26.2", default-features = false, features = ["dir"] }
1818
regex = { version = "1.9.1", default-features = false, features = ["std"] }
1919
thiserror = "1.0.43"
20-
tracing = { version = "0.1.37", features = ["attributes"] }
20+
tracing = { git = "https://github.com/tokio-rs/tracing", rev = "27f688efb72316a26f3ec1f952c82626692c08ff", features = ["attributes"] }
2121

2222
utils = { path = "../utils" }

src/logger/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ serde = { version = "1.0.136", features = ["derive", "rc"] }
1616
serde_json = "1.0.78"
1717
thiserror = "1.0.32"
1818
vm-superio = "0.7.0"
19-
tracing = { version = "0.1.37", features = ["attributes"] }
19+
tracing = { git = "https://github.com/tokio-rs/tracing", rev = "27f688efb72316a26f3ec1f952c82626692c08ff", features = ["attributes"] }
2020
utils = { path = "../utils" }

0 commit comments

Comments
 (0)