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