#tracing #env-logger #parser #env-filter

no-std parse-env-filter

parser for the env logger filter format

1 unstable release

0.1.0 Sep 7, 2021

#2298 in Parser implementations

Download history 168/week @ 2024-01-04 193/week @ 2024-01-11 159/week @ 2024-01-18 354/week @ 2024-01-25 483/week @ 2024-02-01 310/week @ 2024-02-08 224/week @ 2024-02-15 355/week @ 2024-02-22 352/week @ 2024-02-29 343/week @ 2024-03-07 286/week @ 2024-03-14 229/week @ 2024-03-21 293/week @ 2024-03-28 229/week @ 2024-04-04 352/week @ 2024-04-11 393/week @ 2024-04-18

1,298 downloads per month

MIT/Apache

21KB
400 lines

Parsing support for a log target filter, as used by env_logger and tracing::EnvFilter.

We always support the extended tracing format, that is

target[span{field=value}]=level

with the following validity rules:

  • All fields are optional, and MAY be omitted
  • All fields MUST NOT contain the syntax characters []{}=,"/
    • This may be relaxed in the future, to allow e.g. matched brackets in value and/or quoting values
  • Unlike env_logger/tracing::EnvFilter, we treat a bare level name as a target, not a level directive
    • Adding this behavior back is simple — check if only a target is set and if so try it as a level

Note that these rules do not trim whitespace; you'll likely want to yourself. If you want further verification, you can add it on after the parse step. This crate is merely intended to pull the directives out of the format, not to ensure that the directives are otherwise well-formed or meaningful.

Features not supported

  • With tracing::EnvFilter, parsing is ad-hoc and can often allow odd edge cases through. We instead opt to be strict and require exactly matching the syntax, rather than sloppy acceptance.
  • Along the same lines, tracing allows (and sometimes expects) using quotes in field filter values. Quotes are currently reserved, such that a quoted syntax that allows syntax characters in filter fields can be added in the future.
  • env_logger supports a global /regex directive to filter messages via a regex. This applies separately and to all other earlier directives, and as such doesn't quite fit the filter iterator design we've taken. However, we have reserved the / character for clarity and such that a filter field can potentially be added with this syntax in the future.
  • tracing::EnvFilter interprets the value of field=value as a regular expression. We explicitly leave that level of interpretation up to the consumer, as this library is just for parsing.

No runtime deps

Features