Skip to content

Commit d947037

Browse files
author
Jonathan Woollett-Light
committed
fix: tracing
Replaces custom logger with `tracing_subscriber`. Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
1 parent a03dece commit d947037

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+674
-520
lines changed

Cargo.lock

Lines changed: 131 additions & 2 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ mmds = { path = "../mmds" }
2121
seccompiler = { path = "../seccompiler" }
2222
utils = { path = "../utils" }
2323
vmm = { path = "../vmm" }
24+
tracing = { version = "0.1.37", features = ["attributes"] }
2425

2526
[dev-dependencies]
2627
libc = "0.2.117"
28+
log = "0.4.19"

src/api_server/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ use std::fmt::Debug;
1414
use std::path::PathBuf;
1515
use std::sync::mpsc;
1616

17-
use logger::{
18-
debug, error, info, update_metric_with_elapsed_time, warn, ProcessTimeReporter, METRICS,
19-
};
17+
use logger::{update_metric_with_elapsed_time, ProcessTimeReporter, METRICS};
2018
pub use micro_http::{
2119
Body, HttpServer, Method, Request, RequestError, Response, ServerError, ServerRequest,
2220
ServerResponse, StatusCode, Version,
2321
};
2422
use seccompiler::BpfProgramRef;
2523
use serde_json::json;
24+
use tracing::{debug, error, info, warn};
2625
use utils::eventfd::EventFd;
2726
use vmm::rpc_interface::{VmmAction, VmmActionError, VmmData};
2827
use vmm::vmm_config::snapshot::SnapshotType;

src/api_server/src/parsed_request.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
use std::fmt::Debug;
55

6-
use logger::{error, info, log_enabled, Level};
76
use micro_http::{Body, Method, Request, Response, StatusCode, Version};
87
use serde::ser::Serialize;
98
use serde_json::Value;
9+
use tracing::{error, info};
1010
use vmm::rpc_interface::{VmmAction, VmmActionError};
1111

1212
use super::VmmData;
@@ -229,19 +229,7 @@ fn log_received_api_request(api_description: String) {
229229
fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
230230
match (path, body) {
231231
("/mmds", Some(_)) | (_, None) => format!("{:?} request on {:?}", method, path),
232-
("/cpu-config", Some(payload_value)) => {
233-
// If the log level is at Debug or higher, include the CPU template in
234-
// the log line.
235-
if log_enabled!(Level::Debug) {
236-
describe_with_body(method, path, payload_value)
237-
} else {
238-
format!(
239-
"{:?} request on {:?}. To view the CPU template received by the API, \
240-
configure log-level to DEBUG",
241-
method, path
242-
)
243-
}
244-
}
232+
("/cpu-config", Some(payload_value)) => describe_with_body(method, path, payload_value),
245233
(_, Some(payload_value)) => describe_with_body(method, path, payload_value),
246234
}
247235
}
@@ -763,7 +751,7 @@ pub mod tests {
763751
fn test_try_from_put_logger() {
764752
let (mut sender, receiver) = UnixStream::pair().unwrap();
765753
let mut connection = HttpConnection::new(receiver);
766-
let body = "{ \"log_path\": \"string\", \"level\": \"Warning\", \"show_level\": false, \
754+
let body = "{ \"log_path\": \"string\", \"level\": \"Warn\", \"show_level\": false, \
767755
\"show_log_origin\": false }";
768756
sender
769757
.write_all(http_request("PUT", "/logger", Some(body)).as_bytes())

0 commit comments

Comments
 (0)