Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Split out env_filter package #299

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 22 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
[package]
name = "env_logger"
version = "0.10.2"
description = """
A logging implementation for `log` which is configured via an environment
variable.
"""
repository = "https://github.com/rust-cli/env_logger"
categories = ["development-tools::debugging"]
keywords = ["logging", "log", "logger"]
[workspace]
resolver = "2"
members = ["crates/*"]

[workspace.package]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.71" # MSRV
Expand All @@ -23,6 +18,21 @@ include = [
"tests/**/*",
]

[package]
name = "env_logger"
version = "0.10.2"
description = """
A logging implementation for `log` which is configured via an environment
variable.
"""
repository = "https://github.com/rust-cli/env_logger"
categories = ["development-tools::debugging"]
keywords = ["logging", "log", "logger"]
license.workspace = true
edition.workspace = true
rust-version.workspace = true
include.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand All @@ -41,11 +51,11 @@ default = ["auto-color", "humantime", "regex"]
color = ["dep:anstream", "dep:anstyle"]
auto-color = ["color", "anstream/auto"]
humantime = ["dep:humantime"]
regex = ["dep:regex"]
regex = ["env_filter/regex"]

[dependencies]
log = { version = "0.4.8", features = ["std"] }
regex = { version = "1.0.3", optional = true, default-features=false, features=["std", "perf"] }
env_filter = { version = "0.1.0", path = "crates/env_filter", default-features = false }
humantime = { version = "2.0.0", optional = true }
anstream = { version = "0.6.11", default-features = false, features = ["wincon"], optional = true }
anstyle = { version = "1.0.4", optional = true }
Expand Down
11 changes: 11 additions & 0 deletions crates/env_filter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

<!-- next-header -->
## [Unreleased] - ReleaseDate

<!-- next-url -->
[Unreleased]: https://github.com/rust-cli/env_logger/compare/b4a2c304c16d1db4a2998f24c00e00c0f776113b...HEAD
34 changes: 34 additions & 0 deletions crates/env_filter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "env_filter"
version = "0.1.0"
description = """
Filter log events using environment variables
"""
repository = "https://github.com/rust-cli/env_logger"
categories = ["development-tools::debugging"]
keywords = ["logging", "log", "logger"]
license.workspace = true
edition.workspace = true
rust-version.workspace = true
include.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[package.metadata.release]
pre-release-replacements = [
{file="CHANGELOG.md", search="Unreleased", replace="{{version}}", min=1},
{file="CHANGELOG.md", search="\\.\\.\\.HEAD", replace="...{{tag_name}}", exactly=1},
{file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}", min=1},
{file="CHANGELOG.md", search="<!-- next-header -->", replace="<!-- next-header -->\n## [Unreleased] - ReleaseDate\n", exactly=1},
{file="CHANGELOG.md", search="<!-- next-url -->", replace="<!-- next-url -->\n[Unreleased]: https://github.com/rust-cli/env_logger/compare/{{tag_name}}...HEAD", exactly=1},
]

[features]
default = ["regex"]
regex = ["dep:regex"]

[dependencies]
log = { version = "0.4.8", features = ["std"] }
regex = { version = "1.0.3", optional = true, default-features=false, features=["std", "perf"] }
1 change: 1 addition & 0 deletions crates/env_filter/LICENSE-APACHE
1 change: 1 addition & 0 deletions crates/env_filter/LICENSE-MIT
6 changes: 6 additions & 0 deletions crates/env_filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# env_filter

[![crates.io](https://img.shields.io/crates/v/env_filter.svg)](https://crates.io/crates/env_filter)
[![Documentation](https://docs.rs/env_filter/badge.svg)](https://docs.rs/env_filter)

> Filter log events using environment variables
27 changes: 8 additions & 19 deletions src/filter/mod.rs → crates/env_filter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
//! Filtering for log records.
//!
//! This module contains the log filtering used by `env_logger` to match records.
//! You can use the `Filter` type in your own logger implementation to use the same
//! filter parsing and matching as `env_logger`. For more details about the format
//! for directive strings see [Enabling Logging].
//! You can use the [`Filter`] type in your own logger implementation to use the same
//! filter parsing and matching as `env_logger`.
//!
//! ## Using `env_logger` in your own logger
//! ## Using `env_filter` in your own logger
//!
//! You can use `env_logger`'s filtering functionality with your own logger.
//! You can use `env_filter`'s filtering functionality with your own logger.
//! Call [`Builder::parse`] to parse directives from a string when constructing
//! your logger. Call [`Filter::matches`] to check whether a record should be
//! logged based on the parsed filters when log records are received.
//!
//! ```
//! extern crate log;
//! extern crate env_logger;
//! use env_logger::filter::Filter;
//! use env_filter::Filter;
//! use log::{Log, Metadata, Record};
//!
//! struct MyLogger {
Expand All @@ -24,7 +20,7 @@
//!
//! impl MyLogger {
//! fn new() -> MyLogger {
//! use env_logger::filter::Builder;
//! use env_filter::Builder;
//! let mut builder = Builder::new();
//!
//! // Parse a directives string from an environment variable
Expand Down Expand Up @@ -53,10 +49,6 @@
//! fn flush(&self) {}
//! }
//! ```
//!
//! [Enabling Logging]: ../index.html#enabling-logging
//! [`Builder::parse`]: struct.Builder.html#method.parse
//! [`Filter::matches`]: struct.Filter.html#method.matches

use log::{Level, LevelFilter, Metadata, Record};
use std::env;
Expand All @@ -79,9 +71,8 @@ mod inner;
/// ## Example
///
/// ```
/// # #[macro_use] extern crate log;
/// # use std::env;
/// use env_logger::filter::Builder;
/// use env_filter::Builder;
///
/// let mut builder = Builder::new();
///
Expand All @@ -92,8 +83,6 @@ mod inner;
///
/// let filter = builder.build();
/// ```
///
/// [`Filter`]: struct.Filter.html
pub struct Builder {
directives: Vec<Directive>,
filter: Option<inner::Filter>,
Expand Down Expand Up @@ -248,7 +237,7 @@ impl Filter {
///
/// ```rust
/// use log::LevelFilter;
/// use env_logger::filter::Builder;
/// use env_filter::Builder;
///
/// let mut builder = Builder::new();
/// builder.filter(Some("module1"), LevelFilter::Info);
Expand Down
4 changes: 1 addition & 3 deletions src/filter/regex.rs → crates/env_filter/src/regex.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
extern crate regex;

use std::fmt;

use self::regex::Regex;
use regex::Regex;

#[derive(Debug)]
pub struct Filter {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@

mod logger;

pub mod filter;
#[doc(inline)]
pub use ::env_filter as filter;
pub mod fmt;

pub use self::fmt::{Target, TimestampPrecision, WriteStyle};
Expand Down