1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*!
# [stderr](https://github.com/biluohc/stderr)
  A library that using macro to write to `io::stderr()` like `print!()/println!()` for rust.

# Usage

 On Cargo.toml:

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

# About stderr
Usage as same as `print!/println!`.

1. `err!`/`errln!`: Panics if writing to `io::stderr()` fails.
2. `errst!`/`errstln!`: Do nothing if writing to `io::stderr()` fails(silent->st).


# Example

```Rust
#[macro_use]
extern crate stderr;

fn main() {
  println!("err!/errln!/errst!/errstln!()@stderr !");
  let vec = vec![1, 2, 3, 4, 5];
  let s = std::env::args().nth(0).unwrap();

  err!("err!(expr\\n)\n");
  err!("err!(String: vec![1, 2, 3, 4, 5])\n{}: {:?}", s, vec);
  errln!();
  errln!("errln!(expr)");

  println!();

  errst!("errst!(expr\\n)\n");
  errst!("errst!(String: vec![1, 2, 3, 4, 5])\n{}: {:?}", s, vec);
  errstln!();
  errstln!("errstln!(expr)");
}
```
# If you only need `errxxx` and don't want be polluted by other macros, you can: 
* use v0.3.0(The part has been stable since this version)

On Cargo.toml:

```toml
  [dependencies]
  stderr = "0.3.0"
```

## Or

* Only import you need by `macro_use`

On Code:

```rustful
  #[macro_use(err,errln,errst,errstln)]
  extern crate stderr;
```

# About [stderr::StaticMut](struct.StaticMut.html)

[`StaticMut`](struct.StaticMut.html): Internal variability for [`Lazystatic`](https://crates.io/crates/lazy_static)

*/
#[macro_use]
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`

**Synntax: `LogLvl?/module_path,*`**

`Logger` will init by above value, stderr will print the message at `stderr()` if them's location and level pass `Logger::filter()`(Use a stderr crate.)

### Example(if crate'name is 'app', a dependency's name is map):

### Bash

```bash
   env LOG=/                # -> `all/app`
   env LOG="info/app"       # -> `info/app`
   env LOG="info/app,map"   # -> `info/app,map`
```
*/
///`    env LOG=info/*         # -> "info/*"`  ,`#` is all crate
/**
### Fish
```fish
 set -x LOG /                # -> `all/app`
 set -x LOG "info/app"       # -> `info/app`
 set -x LOG "info/app,map"   # -> `info/app,map`
 set -e LOG                  # remove environment variable
```
### Cli_Options_Argument

```sh
   ./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.
*/
pub mod log;
include!("static_mut.rs");

// err!,errln!
/// `print!()` for stderr
#[macro_export]
macro_rules! err {
    ($($arg:tt)*) => {
        {
        use std::io::{self, Write};
        write!(&mut io::stderr(),$($arg)*).unwrap();
        // Panics if writing to io::stdout() fails.        
        }
        };
}
/// `println!()` for stderr
#[macro_export]
macro_rules! errln {
       () => (err!("\n"));
       ($fmt:expr) => (err!(concat!($fmt, "\n")));
        ($fmt:expr, $($arg:tt)*) => (err!(concat!($fmt, "\n"), $($arg)*));
}

// errst!,errstln!
/// `print!()` without `unwrap()` for stderr
#[macro_export]
macro_rules! errst {
    ($($arg:tt)*) => {
        {
        use std::io::{self, Write};
        if let Ok(..) =  write!(&mut io::stderr(),$($arg)* ) {};
        // Do nothing if writing to io::stdout() fails(silent->st).
        }
        };
}
/// `println!()` without `unwrap()` for stderr
#[macro_export]
macro_rules! errstln {
       () => (errst!("\n"));
       ($fmt:expr) => (errst!(concat!($fmt, "\n")));
        ($fmt:expr, $($arg:tt)*) => (errst!(concat!($fmt, "\n"), $($arg)*));
}