-
Notifications
You must be signed in to change notification settings - Fork 736
Errors when importing a library that also uses Loguru #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Speaking only for ciscoconfparse, this problem has been sufficiently addressed by the following commit: See ciscoconfparse issue #211 for usage details. I suspect we can close this loguru ticket, but I'll let @kace confirm... |
Thanks @mpenning! I still would like to follow up on this topic with regards to Loguru though. It would be great if I didn't have to ask library developers who also use Loguru for a method to disable their logger. |
I'm also curious to hear what the "official" loguru stance is on this. From #553, it looks like the basic sentiment is that:
which, correct me if I'm wrong, leads me to believe that packages & libraries that wish use loguru are sort of at the mercy of the rest of the python ecosystem – and whatever other libraries may be imported at runtime? Is that a correct interpretation of the state of multi-package loguru usage? Or are there any "tricks" that a library could use to protect themselves from a "rogue" library (who might not have read these posts and didn't realize they shouldn't touch the handlers) that calls thanks for your thoughts @Delgan! |
I apologize for overlooking this ticket for so long. I'll try to clarify for anyone who comes across this issue. Regarding the concerns raised by @kace and @tlambert03, it's indeed critical for library authors to follow the recommended best practices and not add or remove any handlers during import. At the very least, authors should provide an API to add and/or remove their custom handler. Unfortunately, I don't think it's possible to easily circumvent such misuse of Loguru, given the design of the unique I'm actually curious about why library authors would want to add any handler. If anyone knows, explanations could help me understand the use cases. From my point of view, using the logging methods from the This is consistent with the standard
I don't know the exact problem you faced, but I'm planning to create a The only workaround I can think of is to first import the misbehaving library, then re-configure the
Well, Loguru does indeed expect users to follow the guidelines, especially library authors. A library that behaves incorrectly will not integrate properly with others. If you are the author of a library, there's not much you can do about it. If your users depend on your library but then import a faulty library, they'll encounter problems using Loguru, but technically, that's not your concern. If you're the author of a library that depends on another library that's at fault, it's more complicated. Perhaps it's possible to create a mock of the logger for the time of the import so that the real logger isn't touched. If you are the author of an application that depends on a faulty library, you can try importing it before reconfiguring your logger. In any case, it's best to report the problem to the library author so that it can be fixed at the root. I can't think of a better solution. |
Hi Delgan,
I've run into issues integrating with another lib that recently moved their logging to Loguru from the stdlib. For reference I'm referring to the napalm dependency ciscoconfparse. I've linked their commits below for tag v1.5.48 for you reference.
Anyways, the ciscoconfparse dev's seem to configure the Loguru logger quite a bit - they remove all of the handlers and add their own. This results in errors on my side. First they are
BlockIOError
's then if I let it go a a bit longer also includeOSError
's - see below. It looks like my logging configuration is removed by thelogger.remove()
call in mpenning/ciscoconfparse@72dcc02 on line 138 after I import napalm and ciscoconfparse by extension.I know that you probably can't help me too much since it's another lib causing me problems, but I was curious if you could offer me some advice on how to handle conflicting Loguru logger config given that there is only one global logger? I unsuccessfully tried isolating a copy of the logger as described in https://loguru.readthedocs.io/en/stable/resources/recipes.html#creating-independent-loggers-with-separate-set-of-handlers.
I've also created mpenning/ciscoconfparse#211 to see if the lib dev's have any ideas.
As always thanks for all your effort on Loguru!
Relevant ciscoconfparse commits
The text was updated successfully, but these errors were encountered: