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

no-std parse-env-filter

parser for the env logger filter format

1 unstable release

0.1.0 Sep 7, 2021

#2012 in Parser implementations

Download history 409/week @ 2024-07-20 338/week @ 2024-07-27 28/week @ 2024-08-03 4/week @ 2024-08-10 12/week @ 2024-08-24 2/week @ 2024-08-31 80/week @ 2024-09-21 6/week @ 2024-09-28 37/week @ 2024-10-12 1/week @ 2024-10-19 16/week @ 2024-10-26 4/week @ 2024-11-02

58 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