loguru icon indicating copy to clipboard operation
loguru copied to clipboard

Adding two handlers with the same sink creates duplicated traces

Open albert-rz opened this issue 2 years ago • 1 comments

Hello,

I realized that adding two handlers with the same sink (same file) creates duplicated traces.

For example, the code below:

from loguru import logger

logger.add("my.log", level="INFO")
logger.add("my.log", level="INFO")

logger.info("hello")

Will create the following output:

image

At some point, I understand that the behavior is correct. However, is there any way to only add a new handler if and only if there is not other handler with the same configuration?

Thank you.

albert-rz avatar Mar 01 '23 14:03 albert-rz

Yes, this is the expected behavior but there is no way to get this information from Loguru API.

You'll have to keep a reference of which sinks you added by yourself.

Delgan avatar Mar 03 '23 16:03 Delgan