-
-
Notifications
You must be signed in to change notification settings - Fork 3k
replace prints with logging module #1423
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
Conversation
asafravid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You sometimes use logger.warning() and sometimes warning.warn() - can you elaborate why?
|
@asafravid, Logging and Conceptually, On the other hand, Conceptually In this PR, for example, I used Let me know if that does not answer your question. |
Thanks for the details |
asafravid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
I haven't looked through code yet, just want to say: rebase to |
|
This doesn't work for me. @asafravid did you actually run this? I put this at top of ... then nothing prints. If instead I put this at top, everything prints when only CRITICAL should print (according to their documentation) |
|
@asafravid That SO answer is fine if I want to print everything (or nothing), but not if I want to reduce verbosity to e.g. CRITICAL or ERROR. As I explained already. Have you successfully restricted |
@ValueRaider if you put However, I strongly advise against adding Notice that the distinction between module and app calls is important in the logging module context. I'm not sure what your use case is, but if you're just trying to enable DEBUG+ in yfinance only, while perhaps seeing WARNING+ from other libraries too (e.g. urllib), the you can do this on your script: import logging
# Basic configuration to log everything at WARNING, ERROR and CRITICAL
# to stderr. This will print WARNING+ messages from **all** modules (not
# only yfinance).
logging.basicConfig(level=logging.WARNING)
# Now configure yfinance logger to display DEBUG and above messages.
logger = logging.getLogger('yfinance')
logger.propagate = False
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(levelname)s:%(name)s:%(message)s'))
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)A simplified version of the above that logs DEBUG+ from all modules was added already to All that said, I want to remind you guys that I did not replace debugging |
|
Thanks @flaviovs , I think I understand now.
That's fine but I think these are in scope so I want to replace these too, And reminder: you need to rebase to |
@ValueRaider, I just did it (no conflicts). Let me know if you need any more help with the PR. |
|
I've converted more prints to logging - those wrapped in a |
|
@flaviovs I have a request: does |
|
@ValueRaider possibly we can insert this statefulness per logging message within the yfinance code (if not possible via the logging infrastructure) |
Hi @ValueRaider, logging does not "remember". I think you can find (or develop) a log handler that does that but, as far as I know, it does not that by default. However, I think that for this particular use case (deprecation), you want
|
|
@flaviovs Thanks for suggestion but @asafravid LRU cache idea works perfect. |
That's interesting. I've never depended on this behaviour so actually never tested it. Thanks for bringing me awareness to this.
I'm glad to hear that you guys found a solution. Let me know if I can help with anything else. |
This resolves #1378.
Here's what this PR does:
print()with properlogger.XXXX()calls.print()with proper Python warnings using the warnings module.NOTE: Some
print()calls were guarded byif debug:tests. This PR does not change those, because debug is toggled on/off inside the library sometimes, so there's some logic involved that I am not fully aware of. Ideally this internal debug flag should be removed altogether, and the logic replaced withlogger.debug()calls. I can provide a PR for that if desired.