-
Notifications
You must be signed in to change notification settings - Fork 142
feat: Adding support for no_std
environments for env_filter
#378
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,13 @@ pre-release-replacements = [ | |
] | ||
|
||
[features] | ||
default = ["regex"] | ||
regex = ["dep:regex"] | ||
default = ["std", "regex"] | ||
regex = ["std", "dep:regex"] | ||
std = [] | ||
|
||
[dependencies] | ||
log = { version = "0.4.8", features = ["std"] } | ||
regex = { version = "1.0.3", optional = true, default-features=false, features=["std", "perf"] } | ||
log = { version = "0.4.8", default-features = false } | ||
regex = { version = "1.0.3", optional = true, default-features = false, features = ["std", "perf"] } | ||
Comment on lines
+34
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this belongs in the previous comit, could you move it there? |
||
|
||
[dev-dependencies] | ||
snapbox = "0.6" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use alloc::string::String; | ||
|
||
use log::Level; | ||
use log::LevelFilter; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
use std::env; | ||
use std::fmt; | ||
use std::mem; | ||
use alloc::borrow::ToOwned; | ||
use alloc::string::ToString; | ||
use alloc::vec::Vec; | ||
|
||
use core::fmt; | ||
use core::mem; | ||
|
||
use log::{LevelFilter, Metadata, Record}; | ||
|
||
use crate::enabled; | ||
Comment on lines
+1
to
10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
use crate::parse_spec; | ||
use crate::parser::ParseResult; | ||
use crate::Directive; | ||
use crate::FilterOp; | ||
use crate::ParseError; | ||
|
@@ -48,10 +50,11 @@ impl Builder { | |
} | ||
|
||
/// Initializes the filter builder from an environment. | ||
#[cfg(feature = "std")] | ||
pub fn from_env(env: &str) -> Builder { | ||
let mut builder = Builder::new(); | ||
|
||
if let Ok(s) = env::var(env) { | ||
if let Ok(s) = std::env::var(env) { | ||
builder.parse(&s); | ||
} | ||
|
||
|
@@ -98,10 +101,11 @@ impl Builder { | |
/// See the [Enabling Logging] section for more details. | ||
/// | ||
/// [Enabling Logging]: ../index.html#enabling-logging | ||
#[cfg(feature = "std")] | ||
pub fn parse(&mut self, filters: &str) -> &mut Self { | ||
#![allow(clippy::print_stderr)] // compatibility | ||
|
||
let ParseResult { | ||
let crate::parser::ParseResult { | ||
directives, | ||
filter, | ||
errors, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
use std::fmt; | ||
use alloc::string::{String, ToString}; | ||
|
||
use core::fmt; | ||
Comment on lines
+1
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you group these? |
||
|
||
#[derive(Debug)] | ||
pub(crate) struct FilterOp { | ||
|
@@ -24,13 +26,13 @@ impl FilterOp { | |
|
||
#[cfg(not(feature = "regex"))] | ||
impl FilterOp { | ||
pub fn new(spec: &str) -> Result<Self, String> { | ||
pub(crate) fn new(spec: &str) -> Result<Self, String> { | ||
Ok(Self { | ||
inner: spec.to_string(), | ||
}) | ||
} | ||
|
||
pub fn is_match(&self, s: &str) -> bool { | ||
pub(crate) fn is_match(&self, s: &str) -> bool { | ||
Comment on lines
+29
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you split this out into a separate commit? |
||
s.contains(&self.inner) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
use alloc::borrow::ToOwned; | ||
use alloc::format; | ||
use alloc::string::String; | ||
use alloc::vec::Vec; | ||
|
||
use core::fmt::{Display, Formatter}; | ||
use log::LevelFilter; | ||
use std::error::Error; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
use crate::Directive; | ||
use crate::FilterOp; | ||
Comment on lines
+1
to
10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're changing grouping, could you do
|
||
|
@@ -46,12 +50,16 @@ pub struct ParseError { | |
} | ||
|
||
impl Display for ParseError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | ||
write!(f, "error parsing logger filter: {}", self.details) | ||
} | ||
} | ||
|
||
impl Error for ParseError {} | ||
#[cfg(feature = "std")] | ||
impl std::error::Error for ParseError {} | ||
|
||
#[cfg(not(feature = "std"))] | ||
impl core::error::Error for ParseError {} | ||
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the lack of |
||
|
||
/// Parse a logging specification string (e.g: `crate1,crate2::mod3,crate3::x=error/foo`) | ||
/// and return a vector with log directives. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind fixing your commit type?
A refactor, by definition, has no user facing changes while this does. I would use
feat