Skip to content

Commit

Permalink
feat: Replace log with tracing
Browse files Browse the repository at this point in the history
Replaces `log` with `tracing` and the custom logger with
`tracing_subscriber::Fmt`.

Adding support for re-configuring the logger at run-time and
removing the old logger format.

Signed-off-by: Jonathan Woollett-Light <[email protected]>
  • Loading branch information
Jonathan Woollett-Light committed Aug 13, 2023
1 parent 2a13579 commit 5262168
Show file tree
Hide file tree
Showing 25 changed files with 663 additions and 2,138 deletions.
171 changes: 149 additions & 22 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/api_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mmds = { path = "../mmds" }
seccompiler = { path = "../seccompiler" }
utils = { path = "../utils" }
vmm = { path = "../vmm" }
tracing = "0.1.37"

[dev-dependencies]
libc = "0.2.117"
log = "0.4.19"
4 changes: 2 additions & 2 deletions src/api_server/src/parsed_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use std::fmt::Debug;

use logger::{error, info, log_enabled, Level};
use logger::{error, info, Level};
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
use serde::ser::Serialize;
use serde_json::Value;
Expand Down Expand Up @@ -232,7 +232,7 @@ fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
("/cpu-config", Some(payload_value)) => {
// If the log level is at Debug or higher, include the CPU template in
// the log line.
if log_enabled!(Level::Debug) {
if tracing::enabled!(Level::DEBUG) {
describe_with_body(method, path, payload_value)
} else {
format!(
Expand Down
18 changes: 9 additions & 9 deletions src/api_server/src/request/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn parse_put_logger(body: &Body) -> Result<ParsedRequest, Error> {
mod tests {
use std::path::PathBuf;

use vmm::vmm_config::logger::LoggerLevel;
use vmm::vmm_config::logger::Level;

use super::*;
use crate::parsed_request::tests::vmm_action_from_request;
Expand All @@ -37,10 +37,10 @@ mod tests {
}"#;

let mut expected_cfg = LoggerConfig {
log_path: PathBuf::from("log"),
level: LoggerLevel::Warning,
show_level: false,
show_log_origin: false,
log_path: Some(PathBuf::from("log")),
level: Some(Level::Warn),
show_level: Some(false),
show_log_origin: Some(false),
};
match vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()) {
VmmAction::ConfigureLogger(cfg) => assert_eq!(cfg, expected_cfg),
Expand All @@ -55,10 +55,10 @@ mod tests {
}"#;

expected_cfg = LoggerConfig {
log_path: PathBuf::from("log"),
level: LoggerLevel::Debug,
show_level: false,
show_log_origin: false,
log_path: Some(PathBuf::from("log")),
level: Some(Level::Debug),
show_level: Some(false),
show_log_origin: Some(false),
};
match vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()) {
VmmAction::ConfigureLogger(cfg) => assert_eq!(cfg, expected_cfg),
Expand Down
1 change: 1 addition & 0 deletions src/cpu-template-helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libc = "0.2.147"
serde = { version = "1.0.183", features = ["derive"] }
serde_json = "1.0.104"
thiserror = "1.0.44"
tracing = "0.1.37"

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

Expand Down
1 change: 1 addition & 0 deletions src/dumbo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bench = false
[dependencies]
bitflags = "1.3.2"
derive_more = { version = "0.99.17", default-features = false, features = ["from"] }
tracing = "0.1.37"

logger = { path = "../logger" }
micro_http = { git = "https://github.com/firecracker-microvm/micro-http", rev = "4b18a04" }
Expand Down
3 changes: 3 additions & 0 deletions src/firecracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ bench = false
[dependencies]
event-manager = "0.3.0"
libc = "0.2.147"
log = "0.4.19"
serde_json = "1.0.104"
thiserror = "1.0.44"
timerfd = "1.5.0"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"

api_server = { path = "../api_server" }
logger = { path = "../logger" }
Expand Down
2 changes: 2 additions & 0 deletions src/firecracker/src/api_server_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ pub(crate) fn run_with_api(
api_payload_limit: usize,
mmds_size_limit: usize,
metadata_json: Option<&str>,
logger_handles: vmm::vmm_config::logger::LoggerHandles,
) -> Result<(), ApiServerError> {
// FD to notify of API events. This is a blocking eventfd by design.
// It is used in the config/pre-boot loop which is a simple blocking loop
Expand Down Expand Up @@ -211,6 +212,7 @@ pub(crate) fn run_with_api(
boot_timer_enabled,
mmds_size_limit,
metadata_json,
logger_handles,
)
.map_err(ApiServerError::MicroVMStoppedWithError),
};
Expand Down
Loading

0 comments on commit 5262168

Please sign in to comment.