Debian Codegraph @

README.md

raw symbols SCIP
1 # simple_logger [![](https://img.shields.io/github/tag/borntyping/rust-simple_logger.svg)](https://github.com/borntyping/rust-simple_logger/tags)
2
3 A logger that prints all messages with a readable output format.
4
5 The output format is based on the format used by [Supervisord](https://github.com/Supervisor/supervisor), with timestamps in [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) format.
6
7 The format and timezone used for timestamps can be customised, simple colours based on log level can be enabled, thread metadata can be included, and output can be toggled between STDOUT and STDERR.
8
9 * [Source on GitHub](https://github.com/borntyping/rust-simple_logger)
10 * [Packages on Crates.io](https://crates.io/crates/simple_logger)
11 * [Documentation on Docs.rs](https://docs.rs/simple_logger)
12
13 Notices
14 -------
15
16 ### Project status
17
18 I wrote the initial version of this library in 2015, and haven't written Rust professionally since then.
19 I consider this as close as I'll ever get to a "finished" project and don't plan on adding any more features to it.
20
21 It is still maintained and I try and merge pull requests for fixes, improvements, and features; though I generally turn down pull requests for large or complex features that go outside the library's aim to be a simple logger.
22 If you need more, the `log` module has a list of [available logging implementations](https://docs.rs/log/latest/log/#available-logging-implementations), or you could consider forking `simple_logger` and building on top of it.
23
24 ### Breaking changes
25
26 - **Version 2.0.0 changes the default from displaying timestamps in the local timezone to displaying timestamps in UTC.** See issue [#52](https://github.com/borntyping/rust-simple_logger/issues/52) for more information.
27
28 Usage
29 -----
30
31 ```rust
32 use simple_logger::SimpleLogger;
33
34 fn main() {
35 SimpleLogger::new().init().unwrap();
36
37 log::warn!("This is an example message.");
38 }
39 ```
40
41 This outputs:
42
43 ```txt
44 2022-01-19T17:27:07.013874956Z WARN [logging_example] This is an example message.
45 ```
46
47 You can run the above example with:
48
49 ```sh
50 cargo run --example init
51 ```
52
53 ### Optional features
54
55 The `colors` and `timestamps` features are enabled by default. You can remove these
56 features and their respective dependencies by disabling all features in your
57 `Cargo.toml`.
58
59 ```toml
60 [dependencies.simple_logger]
61 default-features = false
62 ```
63
64 To include the `timestamps` feature, but not the `colors` feature:
65
66 ```toml
67 [dependencies.simple_logger]
68 default-features = false
69 features = ["timestamps"]
70 ```
71
72 To include the `colors` feature, but not the `timestamps` feature:
73
74 ```toml
75 [dependencies.simple_logger]
76 default-features = false
77 features = ["colors"]
78 ```
79
80 To include thread metadata use the `threads` and `nightly` features:
81
82 ```toml
83 [dependencies.simple_logger]
84 features = ["threads", "nightly"]
85 ```
86
87 To direct logging output to `stderr` use the `stderr` feature:
88
89 ```toml
90 [dependencies.simple_logger]
91 features = ["stderr"]
92 ```
93
94 Multiple features can be combined.
95
96 ```toml
97 [dependencies.simple_logger]
98 features = ["colors", "threads", "timestamps", "nightly", "stderr"]
99 ```
100
101 ### Wrapping with another logger
102
103 You might want to wrap this logger to do your own processing before handing events to a SimpleLogger instance. Instead
104 of calling `init()` which calls `log::set_max_level` and `log::set_boxed_logger`, you can call those functions directly
105 giving you the chance to wrap or adjust the logger. See [wrap.rs](examples/wrap.rs) for a more detailed example.
106
107 ### Console setup
108
109 The `SimpleLogger.init()` function attempts to configure colours support as best it can in various situations:
110
111 - On Windows, it will enable colour output. _See `set_up_windows_color_terminal()`._
112 - When using the `colors` *and* `stderr` features, it will instruct the `colored` library to display colors if STDERR
113 is a terminal (instead of checking if STDOUT is a terminal). _See `use_stderr_for_colors()`._
114
115 Licence
116 -------
117
118 `simple_logger` is licenced under the [MIT Licence](http://opensource.org/licenses/MIT).
119
120 Authors
121 -------
122
123 Written by [Sam Clements]([email protected]).