diff --git a/editor-standalone/Cargo.toml b/editor-standalone/Cargo.toml index b5c0b078d..b9092d0a2 100644 --- a/editor-standalone/Cargo.toml +++ b/editor-standalone/Cargo.toml @@ -4,7 +4,7 @@ version = "0.17.0" license = "MIT" authors = ["Dmitry Stepanov "] edition = "2021" -rust-version = "1.72" +rust-version = "1.80" description = "A standalone scene editor for Fyrox game engine" homepage = "https://github.com/FyroxEngine/Fyrox" keywords = ["fyrox", "editor", "rust"] diff --git a/editor-standalone/src/main.rs b/editor-standalone/src/main.rs index 2dec6cb81..da74fb229 100644 --- a/editor-standalone/src/main.rs +++ b/editor-standalone/src/main.rs @@ -19,6 +19,7 @@ // SOFTWARE. use clap::Parser; +use fyrox::core::log::Log; use fyrox::event_loop::EventLoop; use fyroxed_base::{Editor, StartupData}; @@ -35,6 +36,8 @@ struct Args { } fn main() { + Log::set_file_name("fyrox.log"); + let args = Args::parse(); let startup_data = if let Some(proj_dir) = args.project_directory { Some(StartupData { diff --git a/editor/Cargo.toml b/editor/Cargo.toml index 9d5123835..93c70397f 100644 --- a/editor/Cargo.toml +++ b/editor/Cargo.toml @@ -4,7 +4,7 @@ license = "MIT" version = "0.21.1" authors = ["Dmitry Stepanov "] edition = "2021" -rust-version = "1.72" +rust-version = "1.80" description = "A scene editor for Fyrox game engine" homepage = "https://github.com/FyroxEngine/Fyrox" keywords = ["fyrox", "editor", "rust"] diff --git a/fyrox-animation/Cargo.toml b/fyrox-animation/Cargo.toml index ae3b6d0aa..d1e7b90d0 100644 --- a/fyrox-animation/Cargo.toml +++ b/fyrox-animation/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-animation" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-core = { version = "0.28.1", path = "../fyrox-core" } diff --git a/fyrox-core-derive/Cargo.toml b/fyrox-core-derive/Cargo.toml index c5a59e406..db6367efa 100644 --- a/fyrox-core-derive/Cargo.toml +++ b/fyrox-core-derive/Cargo.toml @@ -8,7 +8,7 @@ description = "Proc-macro for the Visit trait" repository = "https://github.com/FyroxEngine/Fyrox" include = ["/src/**/*", "/Cargo.toml", "/README.md"] readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [lib] proc-macro = true diff --git a/fyrox-core/Cargo.toml b/fyrox-core/Cargo.toml index bb556b6b4..dbb5ad777 100644 --- a/fyrox-core/Cargo.toml +++ b/fyrox-core/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-core" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-core-derive = { path = "../fyrox-core-derive", version = "0.23.0" } diff --git a/fyrox-core/src/log.rs b/fyrox-core/src/log.rs index 88f56f562..87c17d429 100644 --- a/fyrox-core/src/log.rs +++ b/fyrox-core/src/log.rs @@ -18,16 +18,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -//! Simple logger, it writes in file and in console at the same time. +//! Simple logger. By default, it writes in the console only. To enable logging into a file, call +//! [`Log::set_file_name`] somewhere in your `main` function. -use crate::lazy_static::lazy_static; use crate::parking_lot::Mutex; use std::fmt::{Debug, Display}; use crate::instant::Instant; #[cfg(not(target_arch = "wasm32"))] use std::io::{self, Write}; +use std::path::Path; use std::sync::mpsc::Sender; +use std::sync::LazyLock; use std::time::Duration; #[cfg(target_arch = "wasm32")] @@ -53,15 +55,15 @@ pub struct LogMessage { pub time: Duration, } -lazy_static! { - static ref LOG: Mutex = Mutex::new(Log { +static LOG: LazyLock> = LazyLock::new(|| { + Mutex::new(Log { #[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))] - file: std::fs::File::create("fyrox.log").unwrap(), + file: None, verbosity: MessageKind::Information, listeners: Default::default(), - time_origin: Instant::now() - }); -} + time_origin: Instant::now(), + }) +}); /// A kind of message. #[derive(Copy, Clone, PartialOrd, PartialEq, Eq, Ord, Hash)] @@ -88,13 +90,28 @@ impl MessageKind { /// See module docs. pub struct Log { #[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))] - file: std::fs::File, + file: Option, verbosity: MessageKind, listeners: Vec>, time_origin: Instant, } impl Log { + /// Creates a new log file at the specified path. + pub fn set_file_name>(#[allow(unused_variables)] path: P) { + #[cfg(all(not(target_arch = "wasm32"), not(target_os = "android")))] + { + let mut guard = LOG.lock(); + guard.file = std::fs::File::create(path).ok(); + } + } + + /// Sets new file to write the log to. + pub fn set_file(#[allow(unused_variables)] file: Option) { + let mut guard = LOG.lock(); + guard.file = file; + } + fn write_internal(&mut self, kind: MessageKind, message: S) where S: AsRef, @@ -122,7 +139,11 @@ impl Log { #[cfg(all(not(target_os = "android"), not(target_arch = "wasm32")))] { let _ = io::stdout().write_all(msg.as_bytes()); - let _ = self.file.write_all(msg.as_bytes()); + + if let Some(log_file) = self.file.as_mut() { + let _ = log_file.write_all(msg.as_bytes()); + let _ = log_file.flush(); + } } #[cfg(target_os = "android")] diff --git a/fyrox-dylib/Cargo.toml b/fyrox-dylib/Cargo.toml index 631c5bf9a..5b29e3e10 100644 --- a/fyrox-dylib/Cargo.toml +++ b/fyrox-dylib/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-dylib" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [lib] crate-type = ["dylib"] diff --git a/fyrox-graph/Cargo.toml b/fyrox-graph/Cargo.toml index a80a2413f..727e2fa87 100644 --- a/fyrox-graph/Cargo.toml +++ b/fyrox-graph/Cargo.toml @@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"] homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-graph" repository = "https://github.com/FyroxEngine/Fyrox" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-core = { path = "../fyrox-core", version = "0.28.1" } diff --git a/fyrox-impl/Cargo.toml b/fyrox-impl/Cargo.toml index 5e9058cad..2ba2905c3 100644 --- a/fyrox-impl/Cargo.toml +++ b/fyrox-impl/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-core-derive = { path = "../fyrox-core-derive", version = "0.23.0" } diff --git a/fyrox-math/Cargo.toml b/fyrox-math/Cargo.toml index a2f3bf8ae..a817d19d2 100644 --- a/fyrox-math/Cargo.toml +++ b/fyrox-math/Cargo.toml @@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"] homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-math" repository = "https://github.com/FyroxEngine/Fyrox" -rust-version = "1.72" +rust-version = "1.80" [dependencies] rectutils = "0.3.0" diff --git a/fyrox-resource/Cargo.toml b/fyrox-resource/Cargo.toml index df616acfa..dffa8af51 100644 --- a/fyrox-resource/Cargo.toml +++ b/fyrox-resource/Cargo.toml @@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"] homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-resource" repository = "https://github.com/FyroxEngine/Fyrox" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-core = { path = "../fyrox-core", version = "0.28.1" } diff --git a/fyrox-scripts/Cargo.toml b/fyrox-scripts/Cargo.toml index 188fc4481..554bd5226 100644 --- a/fyrox-scripts/Cargo.toml +++ b/fyrox-scripts/Cargo.toml @@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE"] homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-scripts" repository = "https://github.com/FyroxEngine/Fyrox" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox = { version = "0.34.0", path = "../fyrox" } \ No newline at end of file diff --git a/fyrox-sound/Cargo.toml b/fyrox-sound/Cargo.toml index 71f3bf32f..54cd1606d 100644 --- a/fyrox-sound/Cargo.toml +++ b/fyrox-sound/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-sound" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-core = { path = "../fyrox-core", version = "0.28.1" } diff --git a/fyrox-ui/Cargo.toml b/fyrox-ui/Cargo.toml index e96efeeac..a6b8c5e58 100644 --- a/fyrox-ui/Cargo.toml +++ b/fyrox-ui/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox-ui" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-core = { path = "../fyrox-core", version = "0.28.1", features = ["serde"] } diff --git a/fyrox/Cargo.toml b/fyrox/Cargo.toml index f59b963c5..069f3ca73 100644 --- a/fyrox/Cargo.toml +++ b/fyrox/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://fyrox.rs" documentation = "https://docs.rs/fyrox" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [features] default = ["fyrox-impl"] diff --git a/project-manager/src/main.rs b/project-manager/src/main.rs index ddb96425c..35bdc41be 100644 --- a/project-manager/src/main.rs +++ b/project-manager/src/main.rs @@ -63,6 +63,8 @@ fn set_ui_scaling(ui: &UserInterface, scale: f32) { #[allow(clippy::unnecessary_to_owned)] fn main() { + Log::set_file_name("project_manager.log"); + let mut window_attributes = WindowAttributes::default(); window_attributes.inner_size = Some(PhysicalSize::new(720, 520).into()); window_attributes.resizable = true; diff --git a/template-core/Cargo.toml b/template-core/Cargo.toml index 8d46a6d8e..d72d0becc 100644 --- a/template-core/Cargo.toml +++ b/template-core/Cargo.toml @@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"] homepage = "https://fyrox.rs" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [dependencies] uuid = { version = "1", features = ["v4"] } diff --git a/template-core/src/lib.rs b/template-core/src/lib.rs index 104ede8ab..a23f777ec 100644 --- a/template-core/src/lib.rs +++ b/template-core/src/lib.rs @@ -241,8 +241,11 @@ dylib = ["fyrox/dylib"] format!( r#"//! Executor with your game connected to it as a plugin. use fyrox::engine::executor::Executor; +use fyrox::core::log::Log; fn main() {{ + Log::set_file_name("{name}.log"); + let mut executor = Executor::new(); // Dynamic linking with hot reloading. @@ -407,9 +410,11 @@ dylib = ["fyroxed_base/dylib_engine"] base_path.join("editor/src/main.rs"), format!( r#"//! Editor with your game connected to it as a plugin. -use fyroxed_base::{{fyrox::event_loop::EventLoop, Editor, StartupData}}; +use fyroxed_base::{{fyrox::event_loop::EventLoop, Editor, StartupData, fyrox::core::log::Log}}; fn main() {{ + Log::set_file_name("{name}.log"); + let event_loop = EventLoop::new().unwrap(); let mut editor = Editor::new( Some(StartupData {{ diff --git a/template/Cargo.toml b/template/Cargo.toml index 2c35cad02..8a019bfb1 100644 --- a/template/Cargo.toml +++ b/template/Cargo.toml @@ -11,7 +11,7 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"] homepage = "https://fyrox.rs" repository = "https://github.com/FyroxEngine/Fyrox" readme = "README.md" -rust-version = "1.72" +rust-version = "1.80" [dependencies] fyrox-template-core = { version = "0.11.0", path = "../template-core" }