Skip to content

Commit c88fac0

Browse files
wlinnatisonkun
andauthored
docs: Add a per-module log level config example (#220)
Co-authored-by: tison <wander4096@gmail.com>
1 parent 7cad34b commit c88fac0

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

examples/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ name = "custom_layout_filter"
109109
path = "src/custom_layout_filter.rs"
110110
required-features = ["starter-log"]
111111

112+
[[example]]
113+
name = "per_module_log_levels"
114+
path = "src/per_module_log_levels.rs"
115+
required-features = ["starter-log"]
116+
112117
[[example]]
113118
name = "syslog"
114119
path = "src/syslog.rs"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2024 FastLabs Developers
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use logforth::append;
16+
use logforth::filter::env_filter::EnvFilterBuilder;
17+
use logforth::record::Level;
18+
use logforth::record::LevelFilter;
19+
20+
fn main() {
21+
// This is how you can allow trace level logs for everything else while silencing them
22+
// for the ones you probably don't need (in this case various rerun modules).
23+
let my_filter = EnvFilterBuilder::from_default_env()
24+
.filter_level(LevelFilter::MoreSevereEqual(logforth::record::Level::Trace))
25+
.filter_module("rerun", LevelFilter::MoreSevereEqual(Level::Warn))
26+
.filter_module("re_chunk", LevelFilter::MoreSevereEqual(Level::Warn))
27+
.filter_module("re_log", LevelFilter::MoreSevereEqual(Level::Warn))
28+
.filter_module("re_log_encoding", LevelFilter::MoreSevereEqual(Level::Warn))
29+
.filter_module("re_sdk", LevelFilter::MoreSevereEqual(Level::Warn))
30+
.filter_module("re_sorbet", LevelFilter::MoreSevereEqual(Level::Warn))
31+
.filter_module("tracing", LevelFilter::MoreSevereEqual(Level::Warn))
32+
.build();
33+
34+
logforth::starter_log::builder()
35+
.dispatch(|d| d.filter(my_filter).append(append::Stdout::default()))
36+
.apply();
37+
38+
log::error!("Hello error!");
39+
log::warn!("Hello warn!");
40+
log::info!("Hello info!");
41+
log::debug!("Hello debug!");
42+
log::trace!("Hello trace!");
43+
}

typos.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
[default.extend-words]
16+
"controllen" = "controllen" # libc's control_len
1617

1718
[files]
1819
extend-exclude = []

0 commit comments

Comments
 (0)