diff --git a/.gitignore b/.gitignore index 2e17483..ed68b57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ target/ /Cargo.lock +output.log /.idea/* !/.idea/runConfigurations diff --git a/satrs-minisim/Cargo.toml b/satrs-minisim/Cargo.toml index 9f8058e..e1449a9 100644 --- a/satrs-minisim/Cargo.toml +++ b/satrs-minisim/Cargo.toml @@ -10,6 +10,8 @@ serde = { version = "1", features = ["derive"] } serde_json = "1" log = "0.4" thiserror = "1" +fern = "0.5" +humantime = "2" [dependencies.asynchronix] version = "0.2.1" diff --git a/satrs-minisim/src/lib.rs b/satrs-minisim/src/lib.rs index aa32e4a..2762326 100644 --- a/satrs-minisim/src/lib.rs +++ b/satrs-minisim/src/lib.rs @@ -1,6 +1,8 @@ use asynchronix::time::MonotonicTime; use serde::{de::DeserializeOwned, Deserialize, Serialize}; +pub const SIM_CTRL_UDP_PORT: u16 = 7303; + #[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum SimTarget { SimCtrl, diff --git a/satrs-minisim/src/main.rs b/satrs-minisim/src/main.rs index bfa4a26..409d542 100644 --- a/satrs-minisim/src/main.rs +++ b/satrs-minisim/src/main.rs @@ -3,7 +3,7 @@ use asynchronix::simulation::{Mailbox, SimInit}; use asynchronix::time::{MonotonicTime, SystemClock}; use controller::SimController; use eps::PcduModel; -use satrs_minisim::{SimReply, SimRequest}; +use satrs_minisim::{SimReply, SimRequest, SIM_CTRL_UDP_PORT}; use std::sync::mpsc; use std::thread; use std::time::{Duration, SystemTime}; @@ -83,14 +83,37 @@ fn main() { let t0 = MonotonicTime::EPOCH; let mut sim_ctrl = create_sim_controller(ThreadingModel::Default, t0, reply_sender, request_receiver); + // Configure logger at runtime + fern::Dispatch::new() + // Perform allocation-free log formatting + .format(|out, message, record| { + out.finish(format_args!( + "[{} {} {}] {}", + humantime::format_rfc3339(std::time::SystemTime::now()), + record.level(), + record.target(), + message + )) + }) + // Add blanket level filter - + .level(log::LevelFilter::Debug) + // - and per-module overrides + // Output to stdout, files, and other Dispatch configurations + .chain(std::io::stdout()) + .chain(fern::log_file("output.log").expect("could not open log output file")) + // Apply globally + .apply().expect("could not apply logger configuration"); + log::info!("starting simulation thread"); // This thread schedules the simulator. let sim_thread = thread::spawn(move || { sim_ctrl.run(t0, 1); }); - let mut udp_server = SimUdpServer::new(0, request_sender, reply_receiver, 200, None) - .expect("could not create UDP request server"); + let mut udp_server = + SimUdpServer::new(SIM_CTRL_UDP_PORT, request_sender, reply_receiver, 200, None) + .expect("could not create UDP request server"); + log::info!("starting UDP server on port {}", SIM_CTRL_UDP_PORT); // This thread manages the simulator UDP server. let udp_tc_thread = thread::spawn(move || { udp_server.run();