You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a port of the famous C++ logging framework [glog] as backend for Rusts [standard logging] frontend.
6
+
7
+
## Introduction
8
+
9
+
`glog-rs` tries to stay as close to [glog] as possible to maintain compatibility, which can be useful in mixed environments using C++ and Rust code at the same time.
10
+
11
+
This includes default values for flags, flag names and behavior.
12
+
13
+
Additional options or configurations can be enabled before initializing the framework to use more of what the Rust [standard logging] frontend has to offer or to solve different use cases.
14
+
15
+
## Examples
16
+
17
+
The most basic example is this:
18
+
19
+
```rust
20
+
uselog::*;
21
+
useglog::Flags;
22
+
23
+
glog::new().init(Flags::default()).unwrap();
24
+
25
+
info!("It works!");
26
+
27
+
```
28
+
which will write `I0401 12:34:56.987654 123 readme.rs:6] It works!` to the `INFO` log file.
29
+
30
+
If you want to have colored output on `stderr` as well consider initializing by using some of the flags:
31
+
32
+
```rust
33
+
glog::new().init(Flags {
34
+
colorlogtostderr:true,
35
+
alsologtostderr:true, // use logtostderr to only write to stderr and not to files
36
+
..Default::default()
37
+
}).unwrap();
38
+
```
39
+
40
+
A non standard extension would the year in addition to month and day in the timestamp. This is possible by calling the `with_year` method prior to `init` like this:
41
+
42
+
```rust
43
+
glog::new()
44
+
.with_year(true) // Add the year to the timestamp in the logfile
45
+
.init(Flags {
46
+
logtostderr:true, // don't write to log files
47
+
..Default::default()
48
+
}).unwrap();
49
+
50
+
info!("With the year");
51
+
```
52
+
53
+
will print `I20210401 12:34:56.987654 123 readme.rs:11] With the year`.
54
+
55
+
## Inspirations
56
+
57
+
This project was inspired by [glog] for the great C++ logging framework and [stderrlog-rs](https://github.com/cardoe/stderrlog-rs) as a kickstarter for a Rust logging backend.
0 commit comments