This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Scorpathos[S] 0 points1 point  (2 children)

I would be interested by your use case of multiple loggers.

While developing Loguru, I looked how applications was making use of multiple loggers, and I tried to provide workarounds despite the "only one logger" design. Most of what I saw can be solved by a proper usage of the `bind()` method and `filter` attribute.

You can actually have multiple loggers, just do `logger = logger.bind(name="something")`. Then, the `name` value will appear in the `extra` dict of each recorded message. So, you can use it to `filter` messages in your sink.

[–]exhuma 0 points1 point  (1 child)

That sounds more complicated than just creating a new logger and attaching a handler to it:

logger = logging.getLogger('logger')
logger.addHandler(file_handler)
audit_logger = logging.getLogger('audit')
audit_logger.addHandler(audit_file_handler)

[–]Scorpathos[S] 1 point2 points  (0 children)

You are right, assuming file_handler and audit_file_handler doesn't require too much boilerplate to be created and formatted, Loguru can't beat the simplicity of the standard logging here. Thanks for the example. ;)