Skip to content
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

Open
ThibaultLemaire opened this issue Oct 28, 2020 · 4 comments
Open

Embed logger options in returned type #48

ThibaultLemaire opened this issue Oct 28, 2020 · 4 comments

Comments

@ThibaultLemaire
Copy link
Contributor

ThibaultLemaire commented Oct 28, 2020

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.

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.87. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@ThibaultLemaire
Copy link
Contributor Author

ThibaultLemaire commented Jan 4, 2021

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

@kornicameister
Copy link
Owner

@ThibaultLemaire If you have an idea how to implement, please do. I am now stucked on various interviews ;).
I see it gets more and more interesting now. We could easily do this similary to lazy=True|False but this will work against your other idea.

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 loguru or in this plugin? Sorry if that's silly question but it was long ago and I just want to refresh my memory.

@ThibaultLemaire
Copy link
Contributor Author

If you have an idea how to implement, please do.

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.

Do you plan on implementing something inside of loguru or in this plugin?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants