mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
refactor log adaptor stuff
This commit is contained in:
parent
68b0983436
commit
def2f60a92
@ -4,7 +4,9 @@ version = "0.1.0"
|
||||
authors = ["Dustin Carlino <dabreegster@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.5"
|
||||
multimap = "0.4.0"
|
||||
serde = "1.0"
|
||||
serde_cbor = "0.8.2"
|
||||
serde_json = "1.0"
|
||||
yansi = "0.4.0"
|
||||
|
@ -1,12 +1,15 @@
|
||||
extern crate log;
|
||||
extern crate multimap;
|
||||
extern crate serde;
|
||||
extern crate serde_cbor;
|
||||
extern crate serde_json;
|
||||
extern crate yansi;
|
||||
|
||||
mod abst_multimap;
|
||||
mod clone;
|
||||
mod error;
|
||||
mod io;
|
||||
mod logs;
|
||||
mod time;
|
||||
|
||||
pub use abst_multimap::MultiMap;
|
||||
@ -17,4 +20,5 @@ pub use io::{
|
||||
read_json, save_object, serialize_btreemap, serialize_multimap, to_json, write_binary,
|
||||
write_json,
|
||||
};
|
||||
pub use logs::{format_log_record, LogAdapter};
|
||||
pub use time::elapsed_seconds;
|
||||
|
30
abstutil/src/logs.rs
Normal file
30
abstutil/src/logs.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use log::{Log, Metadata, Record};
|
||||
use yansi::Paint;
|
||||
|
||||
pub struct LogAdapter;
|
||||
|
||||
impl Log for LogAdapter {
|
||||
fn enabled(&self, _metadata: &Metadata) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
println!("{}", format_log_record(record));
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
||||
pub fn format_log_record(record: &Record) -> String {
|
||||
format!(
|
||||
"[{}] [{}] {}",
|
||||
Paint::white(record.level()),
|
||||
match record.target() {
|
||||
"UI" => Paint::red("UI"),
|
||||
"sim" => Paint::green("sim"),
|
||||
"map" => Paint::blue("map"),
|
||||
x => Paint::cyan(x),
|
||||
},
|
||||
record.args()
|
||||
)
|
||||
}
|
@ -28,4 +28,3 @@ sim = { path = "../sim" }
|
||||
structopt = "0.2"
|
||||
strum = "0.9.0"
|
||||
strum_macros = "0.9.0"
|
||||
yansi = "0.4.0"
|
||||
|
@ -30,7 +30,6 @@ extern crate structopt;
|
||||
extern crate strum;
|
||||
#[macro_use]
|
||||
extern crate strum_macros;
|
||||
extern crate yansi;
|
||||
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
@ -1,3 +1,4 @@
|
||||
use abstutil::format_log_record;
|
||||
use ezgui::{Canvas, GfxCtx, LogScroller, UserInput};
|
||||
use log;
|
||||
use log::{LevelFilter, Log, Metadata, Record};
|
||||
@ -62,20 +63,8 @@ impl Log for LogAdapter {
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
use yansi::Paint;
|
||||
println!("{}", format_log_record(record));
|
||||
|
||||
let line = format!(
|
||||
"[{}] [{}] {}",
|
||||
Paint::white(record.level()),
|
||||
match record.target() {
|
||||
"UI" => Paint::red("UI"),
|
||||
"sim" => Paint::green("sim"),
|
||||
"map" => Paint::blue("map"),
|
||||
x => Paint::cyan(x),
|
||||
},
|
||||
record.args()
|
||||
);
|
||||
println!("{}", line);
|
||||
// TODO could handle newlines here
|
||||
LOGGER.lock().unwrap().add_line(&format!(
|
||||
"[{}] [{}] {}",
|
||||
|
@ -12,4 +12,3 @@ map_model = { path = "../map_model" }
|
||||
pretty_assertions = "0.5.1"
|
||||
sim = { path = "../sim" }
|
||||
structopt = "0.2"
|
||||
yansi = "0.4.0"
|
||||
|
@ -8,9 +8,9 @@ extern crate map_model;
|
||||
extern crate sim;
|
||||
#[macro_use]
|
||||
extern crate structopt;
|
||||
extern crate yansi;
|
||||
|
||||
use log::{LevelFilter, Log, Metadata, Record};
|
||||
use abstutil::LogAdapter;
|
||||
use log::LevelFilter;
|
||||
use sim::SimFlags;
|
||||
use structopt::StructOpt;
|
||||
|
||||
@ -78,31 +78,3 @@ fn main() {
|
||||
sim::save_backtraces("call_graph.json");
|
||||
println!("{:?}", sim.get_score());
|
||||
}
|
||||
|
||||
// TODO This is copied from editor; dedupe how?
|
||||
struct LogAdapter;
|
||||
|
||||
impl Log for LogAdapter {
|
||||
fn enabled(&self, _metadata: &Metadata) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn log(&self, record: &Record) {
|
||||
use yansi::Paint;
|
||||
|
||||
let line = format!(
|
||||
"[{}] [{}] {}",
|
||||
Paint::white(record.level()),
|
||||
match record.target() {
|
||||
"UI" => Paint::red("UI"),
|
||||
"sim" => Paint::green("sim"),
|
||||
"map" => Paint::blue("map"),
|
||||
x => Paint::cyan(x),
|
||||
},
|
||||
record.args()
|
||||
);
|
||||
println!("{}", line);
|
||||
}
|
||||
|
||||
fn flush(&self) {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user