diff options
| -rw-r--r-- | Cargo.lock | 182 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | mingling/Cargo.toml | 1 | ||||
| -rw-r--r-- | mingling_core/Cargo.toml | 4 | ||||
| -rw-r--r-- | mingling_core/src/debug.rs | 104 |
5 files changed, 292 insertions, 1 deletions
@@ -3,6 +3,65 @@ version = 4 [[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] name = "bitflags" version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -24,6 +83,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "env_filter" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e90c2accc4b07a8456ea0debdc2e7587bdd890680d71173a15d4ae604f6eef" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0621c04f2196ac3f488dd583365b9c09be011a4ab8b9f37248ffcc8f6198b56a" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "jiff", + "log", +] + +[[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -83,12 +171,42 @@ dependencies = [ ] [[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] name = "itoa" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] +name = "jiff" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a3546dc96b6d42c5f24902af9e2538e82e39ad350b0c766eb3fbf2d8f3d8359" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-static" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a8c8b344124222efd714b73bb41f8b5120b27a7cc1c75593a6ff768d9d05aa4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] name = "just_fmt" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -119,6 +237,12 @@ dependencies = [ ] [[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] name = "memchr" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -153,8 +277,10 @@ dependencies = [ name = "mingling_core" version = "0.1.4" dependencies = [ + "env_logger", "just_fmt", "just_template", + "log", "once_cell", "ron", "serde", @@ -194,6 +320,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] name = "parking_lot" version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -223,6 +355,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] +name = "portable-atomic" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" + +[[package]] +name = "portable-atomic-util" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "091397be61a01d4be58e7841595bd4bfedb15f1cd54977d79b8271e94ed799a3" +dependencies = [ + "portable-atomic", +] + +[[package]] name = "proc-macro2" version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -250,6 +397,35 @@ dependencies = [ ] [[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] name = "ron" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -489,6 +665,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" [[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -18,6 +18,6 @@ members = [ resolver = "2" [workspace.dependencies] -mingling = { path = "mingling", features = ["full"] } +mingling = { path = "mingling", features = ["full", "debug"] } serde = { version = "1", features = ["derive"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] } diff --git a/mingling/Cargo.toml b/mingling/Cargo.toml index 09b490b..7ff8cdf 100644 --- a/mingling/Cargo.toml +++ b/mingling/Cargo.toml @@ -16,6 +16,7 @@ tokio = { version = "1", features = ["full"] } mingling = { path = ".", features = ["full"] } [features] +debug = ["mingling_core/debug"] default = ["mingling_core/default"] full = ["mingling_core/full", "mingling_macros/full", "comp", "parser"] general_renderer = [ diff --git a/mingling_core/Cargo.toml b/mingling_core/Cargo.toml index 0d4baaa..f7f7c00 100644 --- a/mingling_core/Cargo.toml +++ b/mingling_core/Cargo.toml @@ -10,6 +10,7 @@ repository = "https://github.com/catilgrass/mingling" default = [] full = ["comp", "general_renderer"] comp = ["dep:just_template"] +debug = ["dep:log", "dep:env_logger"] general_renderer = [ "dep:serde", "dep:ron", @@ -31,3 +32,6 @@ ron = { version = "0.12.1", optional = true } serde_json = { version = "1", optional = true } serde_yaml = { version = "0.9", optional = true } toml = { version = "0.9.8", optional = true } + +log = { version = "0.4", optional = true } +env_logger = { version = "0.11", optional = true } diff --git a/mingling_core/src/debug.rs b/mingling_core/src/debug.rs new file mode 100644 index 0000000..9fd553c --- /dev/null +++ b/mingling_core/src/debug.rs @@ -0,0 +1,104 @@ +#[macro_export] +macro_rules! only_debug { + ($($expr:expr);* $(;)?) => { + #[cfg(feature = "debug")] + { + $($expr;)* + } + }; +} + +#[macro_export] +macro_rules! trace { + ($($arg:tt)*) => { + $crate::only_debug! { + log::trace!($($arg)*) + } + }; +} + +#[macro_export] +macro_rules! debug { + ($($arg:tt)*) => { + $crate::only_debug! { + log::debug!($($arg)*) + } + }; +} + +#[macro_export] +macro_rules! info { + ($($arg:tt)*) => { + $crate::only_debug! { + log::info!($($arg)*) + } + }; +} + +#[macro_export] +macro_rules! warn { + ($($arg:tt)*) => { + $crate::only_debug! { + log::warn!($($arg)*) + } + }; +} + +#[macro_export] +macro_rules! error { + ($($arg:tt)*) => { + $crate::only_debug! { + log::error!($($arg)*) + } + }; +} + +#[cfg(feature = "debug")] +pub fn init_env_logger() { + let mut log_path = std::env::current_exe() + .expect("Failed to get current executable path") + .parent() + .expect("Failed to get parent directory") + .to_path_buf(); + // Search for _log.txt in parent directories + let mut current_dir = log_path.parent().unwrap().to_path_buf(); + let mut found_log = false; + + while current_dir.parent().is_some() { + let log_file = current_dir.join("_log.txt"); + if log_file.exists() { + log_path = log_file; + found_log = true; + break; + } + current_dir = current_dir.parent().unwrap().to_path_buf(); + } + + // If not found, use "log.txt" in the original location + if !found_log { + log_path = std::env::current_exe() + .expect("Failed to get current executable path") + .parent() + .expect("Failed to get parent directory") + .to_path_buf(); + log_path.push("log.txt"); + } + + // Only initialize logger if log file exists + if log_path.exists() { + use env_logger::Target; + use log::LevelFilter; + use std::fs::OpenOptions; + + let log_file = OpenOptions::new() + .create(true) + .append(true) + .open(&log_path) + .expect("Failed to open log file"); + + env_logger::Builder::new() + .filter_level(LevelFilter::Trace) + .target(Target::Pipe(Box::new(log_file))) + .init(); + } +} |
