Skip to content

Commit 8c18960

Browse files
committed
Merge pull request #16 from cschlosser/update-readme
Update README.md with useful content
2 parents dfc149c + e1a88e0 commit 8c18960

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,60 @@
1-
# glog-rs
1+
# glog for Rust
2+
3+
[![CI](https://github.com/cschlosser/glog-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/cschlosser/glog-rs/actions/workflows/ci.yml)
4+
5+
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+
use log::*;
21+
use glog::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.
58+
59+
[glog]: https://github.com/google/glog
60+
[standard logging]: https://crates.io/crates/log

0 commit comments

Comments
 (0)