Skip to content

Commit 7056894

Browse files
dianpopadpopa
authored and
dpopa
committed
logging: replacing syslog with new logger
For now, the functionality is not available through API commands. User can specify a file on disk (--log-file) for logging messages. Otherwise, all messages will be flushed to either stdout or stderr. Signed-off-by: Diana Popa <[email protected]>
1 parent d6061a1 commit 7056894

File tree

8 files changed

+42
-14
lines changed

8 files changed

+42
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ devices = { path = "devices" }
1111
net_util = { path = "net_util" }
1212
sys_util = { path = "sys_util" }
1313
vmm = { path = "vmm" }
14+
logger = { path = "logger" }
1415

1516
[workspace]

devices/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ sys_util = { path = "../sys_util" }
1414
virtio_sys = { path = "../virtio_sys" }
1515
vhost_sys = { path = "../vhost_sys" }
1616
vhost_backend = { path = "../vhost_backend" }
17+
logger = {path = "../logger"}
1718

1819
[dev-dependencies]
1920
data_model = { path = "../data_model"}

devices/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
// found in the LICENSE file.
44

55
//! Emulates virtual and hardware devices.
6-
76
extern crate byteorder;
87
extern crate epoll;
98
extern crate libc;
10-
9+
#[macro_use]
10+
extern crate logger;
1111
extern crate net_sys;
1212
extern crate net_util;
13-
#[macro_use]
1413
extern crate sys_util;
1514
extern crate vhost_backend;
1615
extern crate vhost_sys;

logger/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
//! error!("this is a error");
2222
//! }
2323
//! ```
24-
// workaround to marco_reexport
24+
// workaround to macro_reexport
2525
extern crate log;
2626
pub use log::*;
27+
pub use log::Level::*;
2728

2829
mod error;
2930
mod writers;
3031

3132
use error::LoggerError;
32-
use log::{set_boxed_logger, set_max_level, Level, Log, Metadata, Record};
33+
use log::{set_boxed_logger, set_max_level, Log, Metadata, Record};
3334
use std::result;
3435
use std::sync::{Arc, Once, ONCE_INIT};
3536
use writers::*;

src/main.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ extern crate clap;
33

44
extern crate api_server;
55
extern crate devices;
6+
extern crate logger;
67
extern crate net_util;
78
extern crate sys_util;
89
extern crate vmm;
@@ -18,19 +19,15 @@ use api_server::{ApiRequest, ApiServer};
1819
use api_server::request::instance_info::{InstanceInfo, InstanceState};
1920
use api_server::request::sync::{DeviceState, NetworkInterfaceBody, VsockJsonBody};
2021
use net_util::MacAddr;
21-
use sys_util::{syslog, EventFd, GuestAddress};
22+
use sys_util::{EventFd, GuestAddress};
23+
use logger::Logger;
2224
use vmm::{CMDLINE_MAX_SIZE, CMDLINE_OFFSET, KERNEL_START_OFFSET};
2325
use vmm::{kernel_cmdline, KernelConfig};
2426
use vmm::device_config::BlockDeviceConfig;
2527

2628
const DEFAULT_SUBNET_MASK: &str = "255.255.255.0";
2729

2830
fn main() {
29-
if let Err(e) = syslog::init() {
30-
println!("failed to initialize syslog: {:?}", e);
31-
return;
32-
}
33-
3431
let cmd_arguments = App::new("firecracker")
3532
.version(crate_version!())
3633
.author(crate_authors!())
@@ -111,6 +108,13 @@ fn main() {
111108
.long("guest-mac")
112109
.help("The MAC address of the guest network interface.")
113110
.takes_value(true),
111+
)
112+
.arg(
113+
Arg::with_name("log_file")
114+
.short("l")
115+
.long("log-file")
116+
.help("File to serve as logging output")
117+
.takes_value(true),
114118
),
115119
)
116120
.get_matches();
@@ -158,6 +162,27 @@ fn vmm_no_api_handler(
158162
from_api,
159163
).expect("cannot create VMM");
160164

165+
// this is temporary; user will be able to customize logging subsystem through API
166+
if cmd_arguments.is_present("log_file") {
167+
if let Err(e) = Logger::new()
168+
.set_level(logger::Level::Info)
169+
.init(Some(String::from(
170+
cmd_arguments.value_of("log_file").unwrap(),
171+
))) {
172+
eprintln!(
173+
"main: Failed to initialize logging subsystem: {:?}. Trying without a file",
174+
e
175+
);
176+
if let Err(e) = Logger::new().set_level(logger::Level::Info).init(None) {
177+
panic!("main: Failed to initialize logging subsystem: {:?}", e);
178+
}
179+
}
180+
} else {
181+
if let Err(e) = Logger::new().set_level(logger::Level::Info).init(None) {
182+
panic!("main: Failed to initialize logging subsystem: {:?}", e);
183+
}
184+
}
185+
161186
// configure virtual machine from command line
162187
if cmd_arguments.is_present("vcpu_count") {
163188
match cmd_arguments

sys_util/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ extern crate syscall_defines;
1010

1111
#[macro_use]
1212
pub mod ioctl;
13-
#[macro_use]
14-
pub mod syslog;
13+
1514
mod mmap;
1615
mod eventfd;
1716
mod errno;

vmm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ devices = { path = "../devices" }
1313
kernel_loader = { path = "../kernel_loader" }
1414
kvm = { path = "../kvm" }
1515
kvm_sys = { path = "../kvm_sys" }
16+
logger = { path = "../logger" }
1617
net_util = { path = "../net_util"}
1718
sys_util = { path = "../sys_util" }
1819
x86_64 = { path = "../x86_64" }

vmm/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ extern crate devices;
66
extern crate kernel_loader;
77
extern crate kvm;
88
extern crate kvm_sys;
9-
extern crate net_util;
109
#[macro_use]
10+
extern crate logger;
11+
extern crate net_util;
1112
extern crate sys_util;
1213
extern crate x86_64;
1314

0 commit comments

Comments
 (0)