From 2fd8eb8977dc6e1dcd5ec36d21a410aab1ae1502 Mon Sep 17 00:00:00 2001 From: biluohc Date: Sun, 13 Aug 2017 17:13:35 +0800 Subject: [PATCH] fix #4, remove -log --- Cargo.toml | 7 ++++--- readme.md | 4 +++- src/lib.rs | 12 ++++++------ src/log/mod.rs | 30 +++++++++++++++--------------- src/static_mut.rs | 2 +- tests/main.rs | 1 + 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 022c80f..1ca5a20 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,16 @@ [package] name = "stderr" -version = "0.8.0" +version = "0.8.1" authors = ["Wspsxing "] +license = "MIT" description = "A library that using macro to write to io::stderr() like print!()/println!()." # homepage = "..." documentation = "https://docs.rs/stderr/" repository = "https://github.com/biluohc/stderr" readme = "readme.md" -keywords = ["err","errst","log","static","print"] -license = "MIT" +categories = ["development-tools::procedural-macro-helpers","development-tools::debugging"] +keywords = ["err","macros","log","static","print"] [badges] travis-ci = { repository = "biluohc/stderr" } diff --git a/readme.md b/readme.md index 3b386f6..8b55fbf 100644 --- a/readme.md +++ b/readme.md @@ -13,7 +13,7 @@ ```toml [dependencies] - stderr = "0.8.0" + stderr = "0.8.1" ``` # About stderr @@ -71,6 +71,8 @@ On Code: # About `StaticMut` or `log::*`, please read [document](https://docs.rs/stderr) ## ChangLog +2017-0813 **0.8.1** remove `-log` + 2017-0530 **0.8.0** `log::*, StaticMut` 2017-0424 **0.7.1** `loc!()` and `Loger::init(module_path!())` diff --git a/src/lib.rs b/src/lib.rs index b45ce68..ed11c50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ ```toml [dependencies] - stderr = "0.8.0" + stderr = "0.8.1" ``` # About stderr @@ -73,7 +73,7 @@ extern crate lazy_static; extern crate time; /** `log module` -`dbxx!()`/`infoxx!()`/`warnxx!()`/`errorxx!()/fatalxx` print message while environment variable 'LOG' or command line arguments conntains `-log` or `--log` +`dbxx!()`/`infoxx!()`/`warnxx!()`/`errorxx!()/fatalxx` print message while environment variable `LOG` or command line arguments conntains `--log` **Synntax: `LogLvl?/module_path,*`** @@ -98,12 +98,12 @@ extern crate time; set -x LOG "info/app,map" # -> `info/app,map` set -e LOG # remove environment variable ``` -### Cli_Options_Argument +### Cli_Option_Argument ```sh - ./app -log / # -> `all/app` - ./app -log info/app # -> `info/app` - ./app -log info/app,map # -> `info/app,map` + ./app --log / # -> `all/app` + ./app --log info/app # -> `info/app` + ./app --log info/app,map # -> `info/app,map` ``` You must use `logger_init!()` before use them on the current process. */ diff --git a/src/log/mod.rs b/src/log/mod.rs index 54a349b..f16d7de 100644 --- a/src/log/mod.rs +++ b/src/log/mod.rs @@ -13,8 +13,8 @@ use std::env::var; use std::env::args; /// `"LOG"` pub static mut ENV_VAR_KEY: &'static str = "LOG"; -/// `["-log", "--log"]` -pub static mut CLI_OPTION_KEYS: [&'static str; 2] = ["-log", "--log"]; +/// `"--log"` +pub static mut CLI_OPTION_KEY: &'static str = "--log"; lazy_static!{ static ref LOGGER:StaticMut=StaticMut::new(Logger::default()); @@ -29,7 +29,7 @@ pub struct Logger { enabled: AtomicBool, max_lvl: LogLvl, mod_paths: Set, - without_cli_options: AtomicBool, + without_cli_option: AtomicBool, } impl Logger { @@ -61,13 +61,13 @@ impl Logger { pub fn enable_set(b: bool) { LOGGER.as_ref().enabled.store(b, Ordering::SeqCst); } - pub fn without_cli_options() -> bool { - LOGGER.as_ref().without_cli_options.load(Ordering::Relaxed) + pub fn without_cli_option() -> bool { + LOGGER.as_ref().without_cli_option.load(Ordering::Relaxed) } - pub fn without_cli_options_set(b: bool) { + pub fn without_cli_option_set(b: bool) { LOGGER .as_ref() - .without_cli_options + .without_cli_option .store(b, Ordering::SeqCst); } pub fn max_lvl() -> &'static LogLvl { @@ -86,15 +86,15 @@ impl Logger { /// `Logger::init(pkg!());` or `logger_int!()` /// /// **Notice**: `Logger` only init once time, other will be ignored. - fn cli_options(cli_option_keys: &[&'static str]) -> Option { + fn cli_option(cli_option_key: &'static str) -> Option { let mut args: Vec = args().skip(1).collect(); let idx = args.as_slice() .iter() - .position(|s| cli_option_keys.iter().any(|ss| ss == &s.as_str())); - // println!("cli_options: {:?} -> {:?}", idx, args); + .position(|s| cli_option_key == s.as_str()); + // println!("cli_option: {:?} -> {:?}", idx, args); if let Some(idx) = idx { if args.len() >= idx + 2 { - // println!("cli_options/args[idx+1 = {}]: {:?}",idx+1, args[idx + 1]); + // println!("cli_option/args[idx+1 = {}]: {:?}",idx+1, args[idx + 1]); return Some(args.remove(idx + 1)); } } @@ -113,10 +113,10 @@ impl Logger { } // println!("LOGER_after_env: {:?}\ncli::cli_options({:?}): {:?}", // LOGGER.get(), - // CLI_OPTION_KEYS, - // Self::cli_options(&CLI_OPTION_KEYS[..])); - if !Self::initialized() && !Self::without_cli_options() { - if let Some(s) = Self::cli_options(unsafe { &CLI_OPTION_KEYS[..] }) { + // CLI_OPTION_KEY, + // Self::cli_option(CLI_OPTION_KEY)); + if !Self::initialized() && !Self::without_cli_option() { + if let Some(s) = Self::cli_option(unsafe { CLI_OPTION_KEY }) { Self::init_with_str(crate_name, s); } } diff --git a/src/static_mut.rs b/src/static_mut.rs index fd36e61..cefc8ba 100644 --- a/src/static_mut.rs +++ b/src/static_mut.rs @@ -5,7 +5,7 @@ ### On Cargo.toml: ```toml lazy_static = "^0.2.8" -stderr = "0.8.0" +stderr = "0.8.1" ``` ### On Code: diff --git a/tests/main.rs b/tests/main.rs index ccba2cb..6a6b718 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -35,5 +35,6 @@ fn main() { #[should_panic] fn fun() { logger_init!(); + errln!("errln pkg!(): {}", pkg!()); fataln!("I'm angry !!!"); }