mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-10 06:07:55 -06:00
feat: buffer tracing logs before console init
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -2,8 +2,6 @@
|
||||
|
||||
use crate::{app::App, constants::LOOP_TIME};
|
||||
use tracing::info;
|
||||
use tracing_error::ErrorLayer;
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
|
||||
mod app;
|
||||
mod asset;
|
||||
@@ -23,14 +21,22 @@ mod texture;
|
||||
/// This function initializes SDL, the window, the game state, and then enters
|
||||
/// the main game loop.
|
||||
pub fn main() {
|
||||
// Setup tracing
|
||||
let subscriber = tracing_subscriber::fmt()
|
||||
.with_ansi(cfg!(not(target_os = "emscripten")))
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.finish()
|
||||
.with(ErrorLayer::default());
|
||||
// Setup buffered tracing subscriber that will buffer logs until console is ready
|
||||
let switchable_writer = platform::tracing_buffer::setup_switchable_subscriber();
|
||||
|
||||
tracing::subscriber::set_global_default(subscriber).expect("Could not set global default");
|
||||
// Log early to show buffering is working
|
||||
tracing::debug!("Tracing subscriber initialized with buffering - logs will be buffered until console is ready");
|
||||
|
||||
// Initialize platform-specific console
|
||||
tracing::debug!("Starting console initialization...");
|
||||
platform::get_platform().init_console().expect("Could not initialize console");
|
||||
tracing::debug!("Console initialization completed");
|
||||
|
||||
// Now that console is initialized, flush buffered logs and switch to direct output
|
||||
tracing::debug!("Switching to direct logging mode and flushing buffer...");
|
||||
if let Err(e) = switchable_writer.switch_to_direct_mode() {
|
||||
tracing::warn!("Failed to flush buffered logs to console: {}", e);
|
||||
}
|
||||
|
||||
let mut app = App::new().expect("Could not create app");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user