Проектная работа - WIP

This commit is contained in:
5 changed files with 304 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
/// Инициализация логирования
pub fn define_log_layer() -> Option<bevy::log::BoxedFmtLayer> {
use std::fs::File;
use tracing::Level;
use tracing_subscriber::{Layer, filter::Targets, fmt::layer};
let targets = Targets::new()
.with_target("bevy_asset", Level::INFO)
.with_target("bevy_app", Level::INFO)
.with_target("bevy_diagnostic", Level::WARN)
.with_target("bevy_render", Level::INFO)
.with_target("bevy_shader", Level::INFO)
.with_target("bevy_time", Level::INFO)
.with_target("bevy_winit", Level::INFO)
.with_target("gilrs", Level::INFO)
.with_target("naga", Level::INFO)
.with_target("wgpu_core", Level::INFO)
.with_target("wgpu_hal", Level::WARN)
.with_target("offset_allocator", Level::INFO)
.with_default(Level::TRACE);
let stdout = layer()
.compact()
.with_thread_names(true)
.with_file(false)
.with_line_number(false)
.with_filter(targets.clone())
.boxed();
let file = match File::options()
.write(true)
.create(true)
.append(true)
.open("snake-game.log")
{
Ok(file) => file,
Err(e) => {
eprintln!("No access to log file: {:?}", e);
return Some(stdout);
}
};
let log_file = layer()
.compact()
.with_ansi(false)
.with_thread_names(true)
.with_file(false)
.with_line_number(false)
.with_writer(file)
.with_filter(targets.clone())
.boxed();
Some(Box::new(vec![stdout, log_file]))
}