-
Notifications
You must be signed in to change notification settings - Fork 87
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
[RHELC-1732] refactor: Improved logger usage #1327
Conversation
1119b7d
to
bd5a8f5
Compare
246d94f
to
d97b77e
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1327 +/- ##
==========================================
- Coverage 96.43% 96.34% -0.10%
==========================================
Files 66 66
Lines 4997 4983 -14
Branches 877 877
==========================================
- Hits 4819 4801 -18
- Misses 101 102 +1
- Partials 77 80 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
d97b77e
to
f0a0696
Compare
f0a0696
to
2995d32
Compare
2995d32
to
33f5ded
Compare
Ready for review and testing whenever (wanted it to be ready before I leave for PTO) |
# get root logger | ||
logging.setLoggerClass(CustomLogger) | ||
root_logger = logging.getLogger("convert2rhel") # type: CustomLogger # type: ignore |
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.
This can look a bit confusing but essentially we set it to a type explicitly, but since getLogger()
just returns a normal Logger class even if we set our own we have to ignore it as well. It is something that could be improved with more code if it doesn't work for everyone, but with this we get what we want and it should be safe given how the setLoggerClass()
works
This implementation is a bit different from how the demo (recording exists) that I had August 13th
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.
Looks fine for me. Not a single problem
8e56069
to
c01f078
Compare
c6ea6c2
to
2b64ab9
Compare
75a55dd
to
9ad27b6
Compare
b51f620
to
a9c80df
Compare
a9c80df
to
2c61116
Compare
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.
Awesome refactor @Venefilyn 🥇 . I added the tests-run-sanity label to the PR.
Looks like sanity checks are failing as the test doesn't recognise the convert2rhel module importing |
2c61116
to
ac3a5d5
Compare
@SerCantus good spot. I don't think I should change the integration tests. I changed it back now and will re-trigger tests |
ac3a5d5
to
ab5be1a
Compare
convert2rhel/logger.py
Outdated
new_fmt = fmt_orig if not color or self.color_disabled else colorize(fmt_orig, color) | ||
self._fmt = new_fmt |
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.
What do you think unpacking the if-else one-liner to this?
In my opinion, it makes easier to read when we have a if with more than one statement like the current one.
new_fmt = fmt_orig if not color or self.color_disabled else colorize(fmt_orig, color) | |
self._fmt = new_fmt | |
new_fmt = fmt_orig | |
if color or not self.color_disaled: | |
new_fmt = colorize(fmt_orig, color) | |
self._fmt = new_fmt |
Not a required change, to be honest, just posting in case if you agree to apply.
convert2rhel/logger.py
Outdated
class CustomLogger(logging.Logger): | ||
def __init__(self, name, level=0): |
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.
Can we have a docstring here mentioning why this class exist? Looking at it and understanding the context of the PR is easy to guess, but future people might not get it at first.
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.
Especially if you can include that the critical_no_exit
, task
and file
were moved here to avoid messing up with the parent logger class
/packit test --labels sanity |
ab5be1a
to
01305ea
Compare
This refactor of the usage of our logging is to get away from custom functions that causes attribute errors in editors and IDEs. This will also standarize the usage of logger and the loglevels. In future PRs we can include changes to include prepare, rollback, and final specific message styles.
01305ea
to
11b8e34
Compare
@r0x0d Addressed your comments, WDYT? |
/packit test --labels sanity |
This refactor of the usage of our logging is to get away from custom
functions that causes attribute errors in editors and IDEs. This will
also standarize the usage of logger and the loglevels.
In future PRs we can include changes to include prepare, rollback, and
final specific message styles.
Jira Issues:
Checklist
[RHELC-]
or[HMS-]
is part of the PR titleRelease Pending
if relevant