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

mark lazy mode is deprecated and add LazyValue for lazy format value #1233

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

trim21
Copy link
Contributor

@trim21 trim21 commented Nov 12, 2024

No description provided.

@trim21
Copy link
Contributor Author

trim21 commented Nov 12, 2024

ci failed at codecov, not test/lint

@Delgan
Copy link
Owner

Delgan commented Nov 20, 2024

Hi @trim21, thanks for opening a PR. I understand it refers to #1207.

I've been thinking about this lately, and to be honest I'm not very keen on the idea adding a new LazyValue class just to optimize lazy evaluations of message formatting. So far, the logger has been the only publicly importable component from loguru. That would be a significant change of this idiom for what seems to be a relatively small inconvenience.

I would welcome a new API for lazy evaluated arguments if it also address #782. However, this is not necessarily easy.

Another thing to consider is PEP 750. It's still draft and there's no guarantee that it will be accepted, but it could be interesting for our use case, without requiring a new API.

@trim21
Copy link
Contributor Author

trim21 commented Nov 20, 2024

maybe we can add a api logger.lazy(fn, *args, **kwargs)?

I don't think PEP 750 will help #782 or this, even with pep750 accepted, value in template str is still calculcated before logger function is called.

@trim21
Copy link
Contributor Author

trim21 commented Nov 20, 2024

also we have only sync api, I don't know there is a method to handle #782

@Delgan
Copy link
Owner

Delgan commented Nov 20, 2024

value in template str is still calculcated before logger function is called.

Indeed, but it's possible to pass a lambda: Approaches to Lazy Evaluation

We could imagine than when a template string is used, then Loguru will convert callable arguments, but only if the log level requires it. This would make the opt(lazy=true) argument obsolete, while making it straightforward to combine with non-lazy arguments.

This PEP is actively discussed here.

maybe we can add a api logger.lazy(fn, *args, **kwargs)?

I would prefer such API, yes. But still, that's a new method that increases the complexity of Loguru's API, for a marginal gain in my opinion.

also we have only sync api, I don't know there is a method to handle #782

Yes, unfortunately I don't know how to integrate it either.

@trim21
Copy link
Contributor Author

trim21 commented Nov 20, 2024

We could imagine than when a template string is used, then Loguru will convert callable arguments, but only if the log level requires it.

personal I think this is confusing and dangerous behaviour to call callable in arguments unless explicit specified with lazy or something

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

Successfully merging this pull request may close these issues.

2 participants