mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-11 22:50:08 +00:00
disable log file by default + explicit api to change log file
- log file could be undesirable in some cases and now it is off by default and can be enabled by `Log::set_file_name/set_file` in `fn main` - bumped MSRV to 1.80 and to use LazyLock
This commit is contained in:
@@ -4,7 +4,7 @@ version = "0.17.0"
|
||||
license = "MIT"
|
||||
authors = ["Dmitry Stepanov <[email protected]>"]
|
||||
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"]
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ license = "MIT"
|
||||
version = "0.21.1"
|
||||
authors = ["Dmitry Stepanov <[email protected]>"]
|
||||
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"]
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" }
|
||||
|
||||
+31
-10
@@ -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<Log> = Mutex::new(Log {
|
||||
static LOG: LazyLock<Mutex<Log>> = 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<std::fs::File>,
|
||||
verbosity: MessageKind,
|
||||
listeners: Vec<Sender<LogMessage>>,
|
||||
time_origin: Instant,
|
||||
}
|
||||
|
||||
impl Log {
|
||||
/// Creates a new log file at the specified path.
|
||||
pub fn set_file_name<P: AsRef<Path>>(#[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<std::fs::File>) {
|
||||
let mut guard = LOG.lock();
|
||||
guard.file = file;
|
||||
}
|
||||
|
||||
fn write_internal<S>(&mut self, kind: MessageKind, message: S)
|
||||
where
|
||||
S: AsRef<str>,
|
||||
@@ -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")]
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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" }
|
||||
@@ -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" }
|
||||
|
||||
+1
-1
@@ -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"] }
|
||||
|
||||
+1
-1
@@ -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"]
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
@@ -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 {{
|
||||
|
||||
+1
-1
@@ -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" }
|
||||
|
||||
Reference in New Issue
Block a user