Skip to content

Commit

Permalink
feat: Update the logger
Browse files Browse the repository at this point in the history
- Refactors the logger implementation, simplifying the implementation
  and reducing the binary size by ~20kb.
- Adds support for runtime reconfiguration.
- Updates the check for the `Running Firecracker` log to match.
- Updates the default log level to `Info`.

Signed-off-by: Jonathan Woollett-Light <jcawl@amazon.co.uk>
  • Loading branch information
Jonathan Woollett-Light authored and JonathanWoollett-Light committed Oct 6, 2023
1 parent 6fe29a1 commit 332f218
Show file tree
Hide file tree
Showing 15 changed files with 493 additions and 1,291 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@
v1.4.0 are available as an improved iteration of the static CPU templates. For
more information about the transition from static CPU templates to custom CPU
templates, please refer to [this GitHub discussion](https://github.com/firecracker-microvm/firecracker/discussions/4135).

- Changed default log level from
[`Warn`](https://docs.rs/log/latest/log/enum.Level.html#variant.Warn) to
[`Info`](https://docs.rs/log/latest/log/enum.Level.html#variant.Info). This
results in more logs being output by default.
### Fixed

- Fixed a change in behavior of normalize host brand string that breaks
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 22 additions & 21 deletions src/api_server/src/request/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
// SPDX-License-Identifier: Apache-2.0

use vmm::logger::{IncMetric, METRICS};
use vmm::vmm_config::logger_config::LoggerConfig;

use super::super::VmmAction;
use crate::parsed_request::{Error, ParsedRequest};
use crate::request::Body;

pub(crate) fn parse_put_logger(body: &Body) -> Result<ParsedRequest, Error> {
METRICS.put_api_requests.logger_count.inc();
let res = serde_json::from_slice::<LoggerConfig>(body.raw());
let res = serde_json::from_slice::<vmm::logger::LoggerConfig>(body.raw());
let config = res.map_err(|err| {
METRICS.put_api_requests.logger_fails.inc();
err
Expand All @@ -22,41 +21,43 @@ pub(crate) fn parse_put_logger(body: &Body) -> Result<ParsedRequest, Error> {
mod tests {
use std::path::PathBuf;

use vmm::vmm_config::logger_config::LoggerLevel;
use vmm::logger::{LevelFilter, LoggerConfig};

use super::*;
use crate::parsed_request::tests::vmm_action_from_request;

#[test]
fn test_parse_put_logger_request() {
let body = r#"{
"log_path": "log",
"level": "Warning",
"show_level": false,
"show_log_origin": false
}"#;
"log_path": "log",
"level": "Warning",
"show_level": false,
"show_log_origin": false
}"#;

let expected_config = LoggerConfig {
log_path: PathBuf::from("log"),
level: LoggerLevel::Warning,
show_level: false,
show_log_origin: false,
log_path: Some(PathBuf::from("log")),
level: Some(LevelFilter::Warn),
show_level: Some(false),
show_log_origin: Some(false),
};
assert_eq!(
vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()),
VmmAction::ConfigureLogger(expected_config)
);

let body = r#"{
"log_path": "log",
"level": "DEBUG",
"show_level": false,
"show_log_origin": false
}"#;
"log_path": "log",
"level": "DEBUG",
"show_level": false,
"show_log_origin": false
}"#;

let expected_config = LoggerConfig {
log_path: PathBuf::from("log"),
level: LoggerLevel::Debug,
show_level: false,
show_log_origin: false,
log_path: Some(PathBuf::from("log")),
level: Some(LevelFilter::Debug),
show_level: Some(false),
show_log_origin: Some(false),
};
assert_eq!(
vmm_action_from_request(parse_put_logger(&Body::new(body)).unwrap()),
Expand Down
4 changes: 2 additions & 2 deletions src/api_server/swagger/firecracker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,8 @@ definitions:
level:
type: string
description: Set the level. The possible values are case-insensitive.
enum: [Error, Warning, Info, Debug]
default: Warning
enum: [Error, Warning, Info, Debug, Trace, Off]
default: Info
log_path:
type: string
description: Path to the named pipe or file for the human readable log output.
Expand Down
1 change: 1 addition & 0 deletions src/firecracker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bench = false
displaydoc = "0.2.4"
event-manager = "0.3.0"
libc = "0.2.148"
log = "0.4.20"
serde_json = "1.0.107"
thiserror = "1.0.49"
timerfd = "1.5.0"
Expand Down
Loading

0 comments on commit 332f218

Please sign in to comment.