Skip to content

Commit

Permalink
core/http_bench: support -D flag to enable logging
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Apr 16, 2019
1 parent 1bfb443 commit 2719631
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion core/http_bench.rs
Expand Up @@ -22,6 +22,20 @@ use std::sync::atomic::Ordering;
use std::sync::Mutex;
use tokio::prelude::*;

static LOGGER: Logger = Logger;
struct Logger;
impl log::Log for Logger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
metadata.level() <= log::max_level()
}
fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) {
println!("{} - {}", record.level(), record.args());
}
}
fn flush(&self) {}
}

const OP_LISTEN: i32 = 1;
const OP_ACCEPT: i32 = 2;
const OP_READ: i32 = 3;
Expand Down Expand Up @@ -177,7 +191,15 @@ fn main() {

let args: Vec<String> = env::args().collect();
let args = deno::v8_set_flags(args);
if args.len() > 1 && args[1] == "--multi-thread" {

log::set_logger(&LOGGER).unwrap();
log::set_max_level(if args.iter().any(|a| a == "-D") {
log::LevelFilter::Debug
} else {
log::LevelFilter::Warn
});

if args.iter().any(|a| a == "--multi-thread") {
println!("multi-thread");
tokio::run(main_future);
} else {
Expand Down

0 comments on commit 2719631

Please sign in to comment.