integrate propper logging system
This commit is contained in:
parent
f20838e022
commit
bb28bb0c5e
@ -8,7 +8,9 @@ edition = "2021"
|
||||
[dependencies]
|
||||
config = "0.13.3"
|
||||
ctrlc = "3.4.0"
|
||||
env_logger = "0.10.0"
|
||||
helios-dac = { version = "0.1", default-features = false, features = ["native"] }
|
||||
log = "0.4.18"
|
||||
redis = "0.23.0"
|
||||
ron = "0.8.0"
|
||||
serde = { version = "1.0.163", features = ["derive"] }
|
||||
|
33
src/main.rs
33
src/main.rs
@ -22,15 +22,17 @@ use conf::Conf;
|
||||
use errors::{LJError,LJResult};
|
||||
use point::Point;
|
||||
use transformer::{Transformers,Translate,Replicate};
|
||||
use log::{LevelFilter,info,/* warn, */ error};
|
||||
use env_logger::Builder;
|
||||
|
||||
const DEFAULT_CONF_FILE : &str = "settings.toml";
|
||||
const CENTER : (f32,f32) = (2000.0, 2000.0);
|
||||
|
||||
pub fn main() {
|
||||
pub fn main() {
|
||||
match run_all() {
|
||||
Ok(()) => {},
|
||||
Err(err) => {
|
||||
println!("Error: {}", err);
|
||||
error!("Error: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,7 +42,11 @@ fn run_all() -> LJResult<()> {
|
||||
DEFAULT_CONF_FILE.to_string()
|
||||
});
|
||||
|
||||
let config = Conf::new(&filename)?;
|
||||
let config = Conf::new(&filename);
|
||||
init_logging(&config);
|
||||
let config = config?;
|
||||
info!("Starting up");
|
||||
|
||||
let mut rs = RedisCtrl::new(&config.redis_url)?;
|
||||
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
@ -59,7 +65,7 @@ fn run_all() -> LJResult<()> {
|
||||
while running.load(Ordering::SeqCst) {
|
||||
let order = rs.get_order(config.laser_id)?;
|
||||
if order != Order::Draw {
|
||||
println!("{:?}", order);
|
||||
info!("Order: {:?}", order);
|
||||
}
|
||||
|
||||
let frame = get_next_frame(&config, 1000, &transformers,
|
||||
@ -70,11 +76,26 @@ fn run_all() -> LJResult<()> {
|
||||
device.write_frame(frame)?;
|
||||
}
|
||||
|
||||
println!("Exiting, stoping device.");
|
||||
info!("Exiting, stoping device.");
|
||||
device.stop()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init_logging(config: &LJResult<Conf>) {
|
||||
if let Ok(ref config) = config {
|
||||
if config.debug {
|
||||
let mut builder = Builder::from_default_env();
|
||||
builder
|
||||
.filter(None, LevelFilter::Info)
|
||||
.init();
|
||||
} else {
|
||||
env_logger::init();
|
||||
}
|
||||
} else {
|
||||
env_logger::init();
|
||||
}
|
||||
}
|
||||
|
||||
fn get_helios_device() -> LJResult<NativeHeliosDac> {
|
||||
let controller = NativeHeliosDacController::new()?;
|
||||
let devices = controller.list_devices()?;
|
||||
@ -100,7 +121,7 @@ fn get_next_frame(
|
||||
line = transformer.apply(&line);
|
||||
}
|
||||
|
||||
println!("{:?}", line);
|
||||
info!("Line: {:?}", line);
|
||||
|
||||
let line2 : Vec<helios_dac::Point> = line.into_iter().map(| p | p.into()).collect();
|
||||
Ok(Frame::new(speed, line2))
|
||||
|
Loading…
Reference in New Issue
Block a user