Skip to content

Commit 6d6f8eb

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. Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
1 parent df9260e commit 6d6f8eb

File tree

22 files changed

+198
-1089
lines changed

22 files changed

+198
-1089
lines changed

Cargo.lock

Lines changed: 11 additions & 24 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ 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),
@@ -56,7 +56,7 @@ mod tests {
5656
}"#;
5757

5858
expected_cfg = LoggerConfig {
59-
log_path: PathBuf::from("log"),
59+
log_path: Some(PathBuf::from("log")),
6060
level: Some(Level::Debug),
6161
show_level: Some(false),
6262
show_log_origin: Some(false),

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
@@ -127,6 +127,7 @@ pub(crate) fn run_with_api(
127127
api_payload_limit: usize,
128128
mmds_size_limit: usize,
129129
metadata_json: Option<&str>,
130+
logger_handles: vmm::vmm_config::LoggerHandles,
130131
) -> FcExitCode {
131132
// FD to notify of API events. This is a blocking eventfd by design.
132133
// It is used in the config/pre-boot loop which is a simple blocking loop
@@ -223,6 +224,7 @@ pub(crate) fn run_with_api(
223224
boot_timer_enabled,
224225
mmds_size_limit,
225226
metadata_json,
227+
logger_handles,
226228
),
227229
};
228230

src/firecracker/src/main.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ fn main_exitable() -> FcExitCode {
281281

282282
logger::INSTANCE_ID.set(String::from(instance_id)).unwrap();
283283

284-
if let Some(log_path) = arguments.single_value("log-path") {
284+
// Configure logger, the logger handles can be used to re-configure the logger with the API.
285+
let logger_handles = {
285286
let level_res = arguments
286287
.single_value("level")
287288
.map(|s| Level::from_str(s))
@@ -297,18 +298,20 @@ fn main_exitable() -> FcExitCode {
297298
}
298299
};
299300

300-
let logger_config = vmm::vmm_config::LoggerConfig {
301-
log_path: PathBuf::from(log_path),
301+
let config = vmm::vmm_config::LoggerConfig {
302+
log_path: arguments.single_value("log-path").map(PathBuf::from),
302303
level,
303304
show_level: Some(arguments.flag_present("show-level")),
304305
show_log_origin: Some(arguments.flag_present("show-log-origin")),
305306
new_format: Some(arguments.flag_present("new-format")),
306307
};
307-
308-
if let Err(err) = logger_config.init() {
309-
return generic_error_exit(&format!("Could not initialize logger: {}", err));
310-
};
311-
}
308+
match config.init() {
309+
Ok(h) => h,
310+
Err(err) => {
311+
return generic_error_exit(&format!("Could not initialize logger: {}", err));
312+
}
313+
}
314+
};
312315

313316
if let Some(metrics_path) = arguments.single_value("metrics-path") {
314317
let metrics_config = MetricsConfig {
@@ -398,6 +401,7 @@ fn main_exitable() -> FcExitCode {
398401
api_payload_limit,
399402
mmds_size_limit,
400403
metadata_json.as_deref(),
404+
logger_handles,
401405
)
402406
} else {
403407
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)