-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add initial logger support #24
Conversation
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.
There's a warn()
from the warnings
package somewhere in the codebase as well. Should we also replace that one with logging.warning()
?
# Check if the log is the same as the reference log. This is more complicated as we have a time field | ||
with open('contrib/test-data/test_enzh_config_plain_expected.log', 'r', encoding='utf-8') as reffile: | ||
reference: List[str] = reffile.readlines() | ||
# Loglist has one extra `\n` compared to reference list, due to stderr flushing an extra empty line? |
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.
As far as i can tell, this is harmless.
Done. Ready to review now. |
handlers.append(logging.StreamHandler(stream=stderr)) | ||
if outputfilename is not None: | ||
handlers.append(logging.FileHandler(filename=outputfilename)) | ||
# This is the only logger we'd ever use. However during testing, due to the context, logger can't be recreated, |
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.
Not entirely happy about this, but the alternative is to create different loggers which I don't want to do.
"""Sets up the logger with the necessary settings. Outputs to both file and stderr""" | ||
loggingformat = '[%(asctime)s] [Trainer] [%(levelname)s] %(message)s' | ||
handlers: List[logging.StreamHandler[TextIO] | logging.StreamHandler[TextIOWrapper]] = [] | ||
# disable_stderr is to be used only when testing the logger |
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.
grumpy noises
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.
Why do you want strings for loglevel? Why not just export the log levels we support and reference logger.WARNING
instead of "WARNING"
in code? Additional upside is that you can't reference log levels that don't exist because the symbols to do so are not there.
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.
Why StreamHandler[TextIO]
? I can't find any reference of StreamHandler
inheriting Generic
.
Btw If you're okay with it I want to go through your changes and make them Python 3.8 compatible (which basically means not using generics where they're not supported, and using Union
instead of |
)
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.
My type checker flagged it as an incompatible type assignment and this was the inferred type. I guess UNION should be used instead.
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.
For the WARNING I thought it'd be easier to use a text based log level from modifiers, in case users want to add their own logging, rather than getting to python internals.
That being said, logging.getLevelNamesMapping()
is only available in python 3.11 so I shouldn't be using it.
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.
Also, since we define the level at runtime, I had to have str
-> loglevel
conversion anyways..
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.
There's a line print(f"[Trainer] Empty field in {self.dataset.name} line:\"{line}\", skipping...")
on trainer.py:212 that should probably also be a warning to the logger.
"""Sets up the logger with the necessary settings. Outputs to both file and stderr""" | ||
loggingformat = '[%(asctime)s] [Trainer] [%(levelname)s] %(message)s' | ||
handlers: List[logging.StreamHandler[TextIO] | logging.StreamHandler[TextIOWrapper]] = [] | ||
# disable_stderr is to be used only when testing the logger |
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.
Why do you want strings for loglevel? Why not just export the log levels we support and reference logger.WARNING
instead of "WARNING"
in code? Additional upside is that you can't reference log levels that don't exist because the symbols to do so are not there.
"""Sets up the logger with the necessary settings. Outputs to both file and stderr""" | ||
loggingformat = '[%(asctime)s] [Trainer] [%(levelname)s] %(message)s' | ||
handlers: List[logging.StreamHandler[TextIO] | logging.StreamHandler[TextIOWrapper]] = [] | ||
# disable_stderr is to be used only when testing the logger |
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.
Why StreamHandler[TextIO]
? I can't find any reference of StreamHandler
inheriting Generic
.
Btw If you're okay with it I want to go through your changes and make them Python 3.8 compatible (which basically means not using generics where they're not supported, and using Union
instead of |
)
Go ahead and do your changes, I think i'm good with everything. Runs on CSD3 |
Looks like 3.8 isn't complaining about the weird generics your type checker is introducing (I checked the source, they don't make any sense to me, but okay). Fixed an LGTM! 🥳 |
Will finish this after other PRs are in and then i'll also fix the tests:
Currently the output looks something like this: