-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Embed logger options in returned type #48
Comments
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
I believe this would also allow fixing cases such as this (excerpt from #42 (comment)): from loguru import logger
logger.configure(
handlers=[
dict(
sink=sys.stderr,
format="Site {extra[site]} broadcasting: {message}",
backtrace=False,
diagnose=False,
),
],
extra={"site": "unknown"},
)
site = 19
scp = 682
# We're passing the `site` number for local formatting of this message,
# but we're also passing the `scp` number as `extra` for the formatter of the handler.
logger.warning("SCP-{} containment breach detected", scp, site=site)
# error: Not all arguments converted during string formatting |
@ThibaultLemaire If you have an idea how to implement, please do. I am now stucked on various interviews ;). If you don't mind, let's rollback to #43 . I can't exactly figure out how an idea from there should work. Do you plan on implementing something inside of |
Honestly, I'm not sure I do. I just realised while working on #43 that we were returning a Type and that we were free to embed whatever we wanted on that type, so I figured this was the way mypy intended us to keep track of these kind of things (since storing global state is bad apparently). I'd like to dive into that, but I'm sure this is going to be some work, and I don't have the time right-now.
If I'm correct in what I wrote above, I should have all I need in this plugin. I hope I won't have to touch to loguru's source code, but I might consider it if there's no other way, now that mention it. |
As I originally pointed out in #43 (comment), if we could somehow pass the configured
.opt()
of a logger in the type we return, we could avoid storing global state.The text was updated successfully, but these errors were encountered: