tracing icon indicating copy to clipboard operation
tracing copied to clipboard

appender: Add appender to write same log line to multiple outputs in a loop.

Open SriRamanujam opened this issue 4 years ago • 3 comments

Motivation

tracing currently doesn't have a way to send the same log line to multiple appenders at the same time.

Solution

This is a very quick implementation of an appender that wraps an arbitrary number of other appenders and writes the same log line to all of them in a loop.

I didn't write any tests for this module because it legitimately doesn't do anything except call the implementations of its inner writers, so there's really nothing testable here.

SriRamanujam avatar Jul 02 '20 17:07 SriRamanujam

Could you also consider the use-case where you need to have different filters for different writers? I want to report only WARN+ logs in human-readable format to stderr while writing DEBUG+ messages in JSON format to some local file and INFO+ logs to centralized logs storage (e.g. graylog, or other solution which requires its own serialization format).

This solution does not seem to be able to fulfill the requirements, right?

I find Python logging being quite flexible: https://docs.python.org/3/howto/logging.html#advanced-logging-tutorial

frol avatar Aug 26 '20 12:08 frol

Could you also consider the use-case where you need to have different filters for different writers? I want to report only WARN+ logs in human-readable format to stderr while writing DEBUG+ messages in JSON format to some local file and INFO+ logs to centralized logs storage (e.g. graylog, or other solution which requires its own serialization format).

You're right, this PR doesn't allow you to selectively filter on a per-layer basis. That use case will be addressed in https://github.com/tokio-rs/tracing/pull/508.

davidbarsky avatar Aug 26 '20 15:08 davidbarsky

@SriRamanujam - Should we close this PR? cc @hawkw

bryangarza avatar May 06 '22 00:05 bryangarza