Skip to content

Commit

Permalink
fix #4, remove -log
Browse files Browse the repository at this point in the history
  • Loading branch information
biluohc committed Aug 13, 2017
1 parent f03f566 commit 2fd8eb8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[package]
name = "stderr"
version = "0.8.0"
version = "0.8.1"
authors = ["Wspsxing <biluohc@outlook.com>"]
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" }
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

```toml
[dependencies]
stderr = "0.8.0"
stderr = "0.8.1"
```

# About stderr
Expand Down Expand Up @@ -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!())`
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
```toml
[dependencies]
stderr = "0.8.0"
stderr = "0.8.1"
```
# About stderr
Expand Down Expand Up @@ -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,*`**
Expand All @@ -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.
*/
Expand Down
30 changes: 15 additions & 15 deletions src/log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Logger>=StaticMut::new(Logger::default());
Expand All @@ -29,7 +29,7 @@ pub struct Logger {
enabled: AtomicBool,
max_lvl: LogLvl,
mod_paths: Set<String>,
without_cli_options: AtomicBool,
without_cli_option: AtomicBool,
}

impl Logger {
Expand Down Expand Up @@ -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 {
Expand All @@ -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<String> {
fn cli_option(cli_option_key: &'static str) -> Option<String> {
let mut args: Vec<String> = 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));
}
}
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/static_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### On Cargo.toml:
```toml
lazy_static = "^0.2.8"
stderr = "0.8.0"
stderr = "0.8.1"
```
### On Code:
Expand Down
1 change: 1 addition & 0 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ fn main() {
#[should_panic]
fn fun() {
logger_init!();
errln!("errln pkg!(): {}", pkg!());
fataln!("I'm angry !!!");
}

0 comments on commit 2fd8eb8

Please sign in to comment.