Skip to content

Change subscriber settings on the fly #2623

Closed Answered by hds
avifenesh asked this question in Q&A
Discussion options

You must be logged in to vote

I came up with a somewhat contrived example. This code will set up 2 fmt layers, one which writes to stdout and the other to a file called output.log.

(update 2023-06-23): Important Caveat: This solution will work fine for tracing events, but modifying filter levels can cause undesired effects when used with span traces. Any span whose creation and entering isn't captured because of the filter level is "lost", so that events which are recorded within the scope of the span won't appear within the span. This is true for the fmt Layer from the tracing-subscriber crate, other subscribers/layers may behave differently. Use with caution.

Initially the stdout layer will log at INFO level and the…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@avifenesh
Comment options

@hds
Comment options

hds Jun 22, 2023
Collaborator

Answer selected by avifenesh
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants