Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ All notable changes to this project will be documented in this file.
* `Record::payload` is now `std::fmt::Arguments` instead of `Cow<'static, str>`.
* `RecordOwned::as_record` has been removed; use `RecordOwned::with` instead. (This is a limitation of Rust as described [here](https://github.com/rust-lang/rust/issues/92698#issuecomment-3311144848).)
* `logforth_core::Error::with_source` now set the optional source field instead of append a sources list.
* `logforth_core::kv` has been totally redesigned to decouple from `value-bag`. See [PR-229](https://github.com/fast/logforth/pull/229) for details.
* `logforth_core::filter::env_filter` is now factored out into `logforth-filter-rustlog` crate. `EnvFilter` is renamed to `RustLogFilter`. So do other related types and feature flags.
Comment thread
tisonkun marked this conversation as resolved.

## [0.29.1] 2025-11-03

Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"appenders/*",
"bridges/*",
"diagnostics/*",
"filters/*",
"layouts/*",
"xtask",
]
Expand Down Expand Up @@ -47,6 +48,7 @@ logforth-bridge-log = { version = "0.3.0", path = "bridges/log" }
logforth-core = { version = "0.3.1", path = "core" }
logforth-diagnostic-fastrace = { version = "0.3.0", path = "diagnostics/fastrace" }
logforth-diagnostic-task-local = { version = "0.3.0", path = "diagnostics/task-local" }
logforth-filter-rustlog = { version = "0.1.0", path = "filters/rustlog" }
logforth-layout-google-cloud-logging = { version = "0.3.0", path = "layouts/google-cloud-logging" }
logforth-layout-json = { version = "0.3.0", path = "layouts/json" }
logforth-layout-logfmt = { version = "0.3.0", path = "layouts/logfmt" }
Expand Down
8 changes: 4 additions & 4 deletions bridges/log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ use logforth_core::record::FilterCriteria;

/// Adapter to use a `logforth` logger instance as a `log` crate logger.
#[derive(Debug)]
pub struct LogAdapter {
pub struct LogBridge {
logger: Arc<Logger>,
}

impl LogAdapter {
impl LogBridge {
/// Create a new `LogAdapter` instance.
pub fn new(logger: impl Into<Arc<Logger>>) -> Self {
Comment thread
tisonkun marked this conversation as resolved.
Self {
Expand All @@ -40,15 +40,15 @@ impl LogAdapter {
}
}

impl Deref for LogAdapter {
impl Deref for LogBridge {
type Target = Logger;

fn deref(&self) -> &Self::Target {
&self.logger
}
}

impl log::Log for LogAdapter {
impl log::Log for LogBridge {
fn enabled(&self, metadata: &Metadata) -> bool {
forward_enabled(&self.logger, metadata)
}
Expand Down
3 changes: 0 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,5 @@ anyhow = { workspace = true }
# Optional dependencies
serde = { workspace = true, optional = true }

[dev-dependencies]
insta = { workspace = true }

[lints]
workspace = true
4 changes: 0 additions & 4 deletions core/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ use crate::record::FilterCriteria;
use crate::record::LevelFilter;
use crate::record::Record;

pub mod env_filter;

pub use self::env_filter::EnvFilter;

/// The result of a filter check.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FilterResult {
Expand Down
3 changes: 3 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ layout-text = ["logforth/layout-text"]
diagnostic-fastrace = ["logforth/diagnostic-fastrace"]
diagnostic-task-local = ["logforth/diagnostic-task-local"]

# Filters
filter-rustlog = ["logforth/filter-rustlog"]

[dependencies]
logforth = { workspace = true }

Expand Down
4 changes: 2 additions & 2 deletions examples/src/asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use logforth::append::asynchronous::AsyncBuilder;
use logforth::append::file::FileBuilder;
use logforth::bridge::log::LogAdapter;
use logforth::bridge::log::LogBridge;
use logforth::layout::JsonLayout;
use logforth::record::LevelFilter;

Expand All @@ -31,7 +31,7 @@ fn main() {
.dispatch(|d| d.filter(LevelFilter::All).append(asynchronous))
.build();

log::set_boxed_logger(Box::new(LogAdapter::new(logger))).unwrap();
log::set_boxed_logger(Box::new(LogBridge::new(logger))).unwrap();
log::set_max_level(log::LevelFilter::Trace);

log::error!("Hello single error!");
Expand Down
4 changes: 2 additions & 2 deletions examples/src/log_with_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use logforth::append;
use logforth::bridge::log::LogAdapter;
use logforth::bridge::log::LogBridge;

fn main() {
log::set_max_level(log::LevelFilter::Trace);
Expand All @@ -22,7 +22,7 @@ fn main() {
.dispatch(|d| d.append(append::Stdout::default()))
.build();

let l = LogAdapter::new(l);
let l = LogBridge::new(l);
log::error!(logger: l, "Hello error!");
log::warn!(logger: l, "Hello warn!");
log::info!(logger: l, "Hello info!");
Expand Down
6 changes: 3 additions & 3 deletions examples/src/per_module_log_levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
// limitations under the License.

use logforth::append;
use logforth::filter::env_filter::EnvFilterBuilder;
use logforth::filter::rustlog::RustLogFilterBuilder;
use logforth::record::Level;
use logforth::record::LevelFilter;

fn main() {
// This is how you can allow trace level logs for everything else while silencing them
// for the ones you probably don't need (in this case various rerun modules).
let my_filter = EnvFilterBuilder::from_default_env()
.filter_level(LevelFilter::MoreSevereEqual(logforth::record::Level::Trace))
let my_filter = RustLogFilterBuilder::from_default_env()
.filter_level(LevelFilter::MoreSevereEqual(Level::Trace))
.filter_module("rerun", LevelFilter::MoreSevereEqual(Level::Warn))
.filter_module("re_chunk", LevelFilter::MoreSevereEqual(Level::Warn))
.filter_module("re_log", LevelFilter::MoreSevereEqual(Level::Warn))
Expand Down
10 changes: 5 additions & 5 deletions examples/src/per_module_with_ctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use std::sync::OnceLock;
use std::sync::RwLock;

use logforth::append::Stdout;
use logforth::filter::EnvFilter;
use logforth::filter::env_filter::EnvFilterBuilder;
use logforth::filter::RustLogFilter;
use logforth::filter::rustlog::RustLogFilterBuilder;
use logforth::record::Level;
use logforth::starter_log;

Expand Down Expand Up @@ -59,7 +59,7 @@ fn main() {
.filter(
FILTER
.get_or_init(|| Filter::new(Level::Info))
.build_env_filter(),
.build_rustlog_filter(),
)
.append(Stdout::default())
})
Expand Down Expand Up @@ -91,7 +91,7 @@ impl Filter {
module_levels.insert(module_path.to_string(), level);
}

pub fn build_env_filter(&self) -> EnvFilter {
pub fn build_rustlog_filter(&self) -> RustLogFilter {
let module_levels = self.module_levels.read().expect("filter read is poisoned");

let mut directives = vec![self.default_level.name().to_string()];
Expand All @@ -100,6 +100,6 @@ impl Filter {
directives.push(format!("{module_path}={}", level.name()));
}

EnvFilterBuilder::from_spec(directives.join(",")).build()
RustLogFilterBuilder::from_spec(directives.join(",")).build()
}
}
37 changes: 37 additions & 0 deletions filters/rustlog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2024 FastLabs Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[package]
name = "logforth-filter-rustlog"
version = "0.1.0"

description = "RUST_LOG directive pattern filter for Logforth."
keywords = ["logging", "log", "fastrace"]

categories.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
readme.workspace = true
repository.workspace = true
rust-version.workspace = true
Comment thread
tisonkun marked this conversation as resolved.

[dependencies]
logforth-core = { workspace = true }

[dev-dependencies]
insta = { workspace = true }

[lints]
workspace = true
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RUST_LOG Environment Variable Filter
# Logforth RUST_LOG Filter

This filter is derived by [env_filter](https://crates.io/crates/env_filter), with significant modifications to suit our needs:

Expand Down
Loading