|
1 |
| -# simple_logger [](https://github.com/borntyping/rust-simple_logger/tags) [](https://travis-ci.org/borntyping/rust-simple_logger) [](https://github.com/borntyping/rust-simple_logger/issues) |
| 1 | +# simple_logger [](https://github.com/borntyping/rust-simple_logger/tags) |
2 | 2 |
|
3 | 3 | A logger that prints all messages with a readable output format.
|
4 | 4 |
|
@@ -38,6 +38,8 @@ You can run the above example with:
|
38 | 38 | cargo run --example init
|
39 | 39 | ```
|
40 | 40 |
|
| 41 | +### Optional features |
| 42 | + |
41 | 43 | The `colors` and `timestamps` features are enabled by default. You can remove these
|
42 | 44 | features and their respective dependencies by disabling all features in your
|
43 | 45 | `Cargo.toml`.
|
@@ -84,26 +86,28 @@ Multiple features can be combined.
|
84 | 86 | features = ["colors", "threads", "timestamps", "nightly", "stderr"]
|
85 | 87 | ```
|
86 | 88 |
|
87 |
| -Wrapping with another logger |
88 |
| ----------------------------- |
| 89 | +### Wrapping with another logger |
89 | 90 |
|
90 |
| -Users that might want to wrap this logger to be able to catch log events for various |
91 |
| -reasons can setup the logger as follows: |
| 91 | +You might want to wrap this logger to do your own processing before handing events to a SimpleLogger instance. Instead |
| 92 | +of calling `init()` which calls `log::set_max_level` and `log::set_boxed_logger`, you can call those functions directly |
| 93 | +giving you the chance to wrap or adjust the logger. See [wrap.rs](examples/wrap.rs) for a more detailed example. |
92 | 94 |
|
93 |
| -On windows machines: |
94 |
| -```rust |
95 |
| -let logger = SimpleLogger::new(); |
96 |
| -set_up_color_terminal(); |
97 |
| -let max_level = logger.max_level(); |
98 |
| -``` |
| 95 | +The call to `set_up_color_terminal()` is currently only needed on Windows when the `colored` feature is enabled. If |
| 96 | +you're not on Windows and not using the `colored` feature, it will do nothing. |
99 | 97 |
|
100 |
| -Otherwise: |
101 | 98 | ```rust
|
102 |
| -let logger = SimpleLogger::new(); |
103 |
| -let max_level = logger.max_level(); |
104 |
| -``` |
| 99 | +use simple_logger::{SimpleLogger, set_up_color_terminal}; |
105 | 100 |
|
106 |
| -The user can then themselves call `log::set_max_level` and `log::set_boxed_logger` or equivalent as they wish. |
| 101 | +fn main() { |
| 102 | + set_up_color_terminal(); |
| 103 | + |
| 104 | + let logger = SimpleLogger::new(); |
| 105 | + let max_level = logger.max_level(); |
| 106 | + |
| 107 | + log::set_max_level(max_level); |
| 108 | + log::set_boxed_logger(Box::new(logger)).unwrap(); |
| 109 | +} |
| 110 | +``` |
107 | 111 |
|
108 | 112 | Licence
|
109 | 113 | -------
|
|
0 commit comments