diff options
-rw-r--r-- | Cargo.lock | 102 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 88 | ||||
-rw-r--r-- | src/log_level.rs | 1 |
4 files changed, 152 insertions, 41 deletions
@@ -1,15 +1,109 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] -name = "ansi" +name = "inked" version = "1.0.0" -source = "git+git://benbridle.com/ansi?tag=v1.0.0#81d47867c2c97a9ae1d1c8fdfcd42c582410ad2a" +source = "git+git://benbridle.com/inked?tag=v1.0.0#2954d37b638fa2c1dd3d51ff53f08f475aea6ea3" +dependencies = [ + "termcolor", +] [[package]] name = "log" version = "1.1.2" dependencies = [ - "ansi", + "inked", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" @@ -4,4 +4,4 @@ version = "1.1.2" edition = "2021" [dependencies] -ansi = { git = "git://benbridle.com/ansi", tag = "v1.0.0" } +inked = { git = "git://benbridle.com/inked", tag = "v1.0.0" } @@ -1,11 +1,13 @@ mod log_level; pub use log_level::*; -pub mod ansi { pub use ansi::*; } +use inked::*; use std::sync::Mutex; -pub static LOG_LEVEL: Mutex<LogLevel> = Mutex::new(LogLevel::Warn); + +static LOG_LEVEL: Mutex<LogLevel> = Mutex::new(LogLevel::Warn); + pub fn set_log_level(level: LogLevel) { *LOG_LEVEL.lock().unwrap() = level; @@ -16,48 +18,64 @@ pub fn get_log_level() -> LogLevel { } -#[macro_export] macro_rules! info { - ($($tokens:tt)*) => { - if *$crate::LOG_LEVEL.lock().unwrap() <= { $crate::LogLevel::Info } { - use $crate::ansi::*; - eprint!("{BOLD}{BLUE}[INFO]{NORMAL}: "); - eprint!($($tokens)*); - eprintln!("{NORMAL}"); +pub fn log_info(message: &str, details: Option<impl Into<InkedString>>) { + if *LOG_LEVEL.lock().unwrap() <= LogLevel::Info { + let mut string = InkedString::new(); + string.push(ink!("[INFO]").blue().bold()); + string.push(ink!(": {message}\n")); + if let Some(details) = details { + string.append(details.into()); } - }; + string.eprint(); + } } -#[macro_export] macro_rules! warn { - ($($tokens:tt)*) => {{ - if *$crate::LOG_LEVEL.lock().unwrap() <= { $crate::LogLevel::Warn } { - use $crate::ansi::*; - eprint!("{BOLD}{YELLOW}[WARNING]{NORMAL}{WHITE}: "); - eprint!($($tokens)*); - eprintln!("{NORMAL}"); +pub fn log_warn(message: &str, details: Option<impl Into<InkedString>>) { + if *LOG_LEVEL.lock().unwrap() <= LogLevel::Warn { + let mut string = InkedString::new(); + string.push(ink!("[WARN]").yellow().bold()); + string.push(ink!(": {message}\n").white()); + if let Some(details) = details { + string.append(details.into()); } - }}; + string.eprint(); + } } -#[macro_export] macro_rules! error { - ($($tokens:tt)*) => {{ - if *$crate::LOG_LEVEL.lock().unwrap() <= { $crate::LogLevel::Error } { - use $crate::ansi::*; - eprint!("{BOLD}{RED}[ERROR]{WHITE}: "); - eprint!($($tokens)*); - eprintln!("{NORMAL}"); +pub fn log_error(message: &str, details: Option<impl Into<InkedString>>) { + if *LOG_LEVEL.lock().unwrap() <= LogLevel::Error { + let mut string = InkedString::new(); + string.push(ink!("[ERROR]").red().bold()); + string.push(ink!(": {message}\n").white()); + if let Some(details) = details { + string.append(details.into()); } - }}; + string.eprint(); + } } -#[macro_export] macro_rules! fatal { - ($($tokens:tt)*) => {{ - if *$crate::LOG_LEVEL.lock().unwrap() <= { $crate::LogLevel::Fatal } { - use $crate::ansi::*; - eprint!("{BOLD}{RED}[FATAL]{WHITE}: "); - eprint!($($tokens)*); - eprintln!("{NORMAL}"); +pub fn log_fatal(message: &str, details: Option<impl Into<InkedString>>) -> ! { + if *LOG_LEVEL.lock().unwrap() <= LogLevel::Fatal { + let mut string = InkedString::new(); + string.push(ink!("[FATAL]").red().bold()); + string.push(ink!(": {message}\n").white()); + if let Some(details) = details { + string.append(details.into()); } - std::process::exit(1); - }}; + string.eprint(); + } + std::process::exit(1); } +#[macro_export] macro_rules! info { + ($($tokens:tt)*) => { $crate::log_info(&format!($($tokens)*), Option::<String>::None) }; +} +#[macro_export] macro_rules! warn { + ($($tokens:tt)*) => { $crate::log_warn(&format!($($tokens)*), Option::<String>::None) }; +} +#[macro_export] macro_rules! error { + ($($tokens:tt)*) => { $crate::log_error(&format!($($tokens)*), Option::<String>::None) }; +} +#[macro_export] macro_rules! fatal { + ($($tokens:tt)*) => { $crate::log_fatal(&format!($($tokens)*), Option::<String>::None) }; +} diff --git a/src/log_level.rs b/src/log_level.rs index 9293efc..1937c07 100644 --- a/src/log_level.rs +++ b/src/log_level.rs @@ -1,4 +1,3 @@ - use std::cmp::Ordering; #[derive(Clone, Copy, Debug, PartialEq, Eq)] |