emabee / flexi_logger

A flexible logger for rust programs that can write to stderr, stdout, and/or to log files
Apache License 2.0
315 stars 55 forks source link

Does this library support multiple log files and/or multiple named/filtered outputs? #157

Closed JohnAllen closed 7 months ago

JohnAllen commented 7 months ago

First off thank you for writing this and making it public.

Does this library support logging to multiple files based on a string? Something like the Bar example in examples but multiple different filters.

I just tried instantiating two loggers with different FileSpec.basenames and it threw an error, so it seems like not.

To be clear I mean piping multiple info!s to different files.

emabee commented 7 months ago

I think a fairly reasonable approach would be to create your own implementation of LogWriter, which holds itself as many FileLogWriters as you need, and dispatch the LogWriter methods according to your needs. The dispatching based on the String would happen in the write method. You then configure flexi_logger with Logger::log_to_writer.

I just tried instantiating two loggers...

The logcrate does not allow instantiating more than one logger. The dispatching thus has to happen within the logger.