Skip to content

Support reparsing filters at runtime #113

Description

@KodrAus

Originally raised in #103

Currently, I don't see a nice way to change logging levels dynamically. (Or is there?). It is not very friendly with log::set_max_level_filter either to able to make even small changes.

Would be nice to be able to make small changes if not full reparse during runtime. It becomes extremely helpful in server environments to be able to to that.

Activity

  1. jose-acevedoflores commented on Apr 10, 2021

    @jose-acevedoflores

    I took a jab at adding support for this and have come up with two prototypes:

    • Non breaking change: Added an RwLock around the filter field of the Logger struct. This approach is simple but there is a read penalty when accessing the filter field anytime something is logged. Code for this approach here
    • Breaking change: Used generics to create a logger that can change filters at runtime or forgo the ability to change at runtime to avoid the read penalty and remain static (basically how it is now). Code for this approach here

    For both prototypes, when the logger is built you can get an instance of a new struct called DynamicLogLevel. It has a check_filter_config method that when called, checks a config file and updates the filter if the levels have changed.
    The contents of this config file should follow the same syntax used for the RUST_LOG env var.

    My goal is to start the conversation and possibly see if there are better ways to add support for this.

  2. steveklabnik commented on Feb 17, 2022

    @steveklabnik

    +1 to "this would be nice"

  3. RobertJacobsonCDC commented on Jan 24, 2025

    @RobertJacobsonCDC

    This suggestion doesn't feel like the "right" solution, especially if you're doing anything beyond logging to a console, but an alternative might be to have different configurations in different Builders, and when you want to change the active configuration you just call on the appropriate Builder to install a new logger. If Builder was clonable, say, it'd be easier to incrementally modify configurations.

    I'm thinking about a debugger interface I'm working on in which the user can dynamically enable/disable log messages from a debug console. The actual logging features I need are dead simple—except that I want to dynamically change filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions