Use logging
This commit is contained in:
+13
-2
@@ -8,6 +8,8 @@ use app::Application;
|
||||
use clap::Parser;
|
||||
use emulator::EmulatorBuilder;
|
||||
use thread_priority::{ThreadBuilder, ThreadPriority};
|
||||
use tracing::error;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
|
||||
mod app;
|
||||
@@ -29,6 +31,13 @@ struct Args {
|
||||
debug_port: Option<u16>,
|
||||
}
|
||||
|
||||
fn init_logger() {
|
||||
let directives = std::env::var("RUST_LOG").unwrap_or("error,lemur=info".into());
|
||||
let filter = EnvFilter::builder().parse_lossy(directives);
|
||||
let layer = tracing_subscriber::fmt::layer().with_filter(filter);
|
||||
tracing_subscriber::registry().with(layer).init();
|
||||
}
|
||||
|
||||
fn set_panic_handler() {
|
||||
std::panic::set_hook(Box::new(|info| {
|
||||
let mut message = String::new();
|
||||
@@ -76,6 +85,8 @@ fn set_process_priority_to_high() -> Result<()> {
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
init_logger();
|
||||
|
||||
set_panic_handler();
|
||||
|
||||
#[cfg(windows)]
|
||||
@@ -97,8 +108,8 @@ fn main() -> Result<()> {
|
||||
.spawn_careless(move || {
|
||||
let mut emulator = match builder.build() {
|
||||
Ok(e) => e,
|
||||
Err(err) => {
|
||||
eprintln!("Error initializing emulator: {err}");
|
||||
Err(error) => {
|
||||
error!(%error, "Error initializing emulator");
|
||||
process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user