Updated logging to both file and console
This commit is contained in:
@@ -11,7 +11,7 @@ use crate::{
|
||||
};
|
||||
use tauri::async_runtime;
|
||||
use tauri::Manager;
|
||||
use tracing_subscriber;
|
||||
use tracing_subscriber::{self, util::SubscriberInitExt};
|
||||
|
||||
static APP_HANDLE: std::sync::OnceLock<tauri::AppHandle<tauri::Wry>> = std::sync::OnceLock::new();
|
||||
|
||||
@@ -48,12 +48,31 @@ fn setup_fdoll() -> Result<(), tauri::Error> {
|
||||
let file_appender = tracing_appender::rolling::daily(&app_log_dir, "friendolls.log");
|
||||
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
// Create a filter - adjust the level as needed (trace, debug, info, warn, error)
|
||||
let filter = tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info"));
|
||||
|
||||
// Create a layer that writes to the file
|
||||
let file_layer = tracing_subscriber::fmt::layer()
|
||||
.with_target(false)
|
||||
.with_thread_ids(false)
|
||||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.with_writer(non_blocking) // Log to file
|
||||
.with_writer(non_blocking);
|
||||
|
||||
// Create a layer that writes to stdout (console)
|
||||
let console_layer = tracing_subscriber::fmt::layer()
|
||||
.with_target(false)
|
||||
.with_thread_ids(false)
|
||||
.with_file(true)
|
||||
.with_line_number(true);
|
||||
|
||||
// Combine both layers with filter
|
||||
use tracing_subscriber::layer::SubscriberExt;
|
||||
tracing_subscriber::registry()
|
||||
.with(filter)
|
||||
.with(file_layer)
|
||||
.with(console_layer)
|
||||
.init();
|
||||
|
||||
state::init_fdoll_state(Some(_guard));
|
||||
|
||||
Reference in New Issue
Block a user