Delgan / loguru

Python logging made (stupidly) simple
MIT License
18.69k stars 682 forks source link

Can I have multiple loggers? #1127

Open mdelmans opened 2 months ago

mdelmans commented 2 months ago

I'm running an async server and I want users to chose which sinks to use for logging, so I need to customise logger before passing it to an async function.

Is it possible to create multiple loguru._logger.Logger instances so there is no cross-talk between them? Is there a better approach?

Delgan commented 2 months ago

One way would be to use bind() but that requires the added sink to have a filter based on the bounded name.

Maybe you can use this workaround to create inepependent loggers until I implement a new() method: Creating independent loggers with separate set of handlers.

mdelmans commented 2 months ago

Thanks, I think this should work.

xinjie-h commented 2 weeks ago

This answer as well as the question helps me a lot. Thx.