-
-
Notifications
You must be signed in to change notification settings - Fork 402
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
[core] Rework logging #1678
[core] Rework logging #1678
Conversation
@dgw once we agree on these changes, I'll update the documentation accordingly. I think this deserve some explanation for end-users, and for plugin developers. |
Hmmmm. This is a massive rewrite just to tweak some log levels for #1337. 😛 Can you implement 01feeae in a separate PR, and we can, ahem, bikeshed this overhaul without blocking that? I have some design questions. Like, why remove Rotating log files is a nice idea, but I don't see where old files will be deleted. Of course, Sopel's current logging setup doesn't prune itself either, but… that's something I should have opened an issue for long ago. It's bad to have logs stick around forever. My first look at this was split over multiple sessions, and I hope I didn't forget any big questions. Nitpicks were deliberately excluded, though. Don't worry, the usual "dgw edits Exirel's English" will happen later! I just didn't want either of us to spend time on it just yet. |
A Nice Conversation Starter
I could, but I think I wouldn't like it - neither would you. I've two main concerns about the current implementation: the force redirect output, and the manual writing in a file. First, the force redirect output. This is a bad developer solution to a 100% ops problem. As a result, properly using logs become a nightmare, because you would think that all we do is log to the console... but that's not true at all! Beside, the The proper way to solve that, is to use logging where it's relevant, and to use the good old fashioned Second, manually writing into log files. I think it was produced by the best intention in the world. Here, make sure we log everything critical. Also the folder creation might fail, that's only fair that we protect us from that! Sure thing... yet logging already does that, in a much better and efficient way than we do. Except that it won't work properly if you redirect the output, and of course there is always the possibility to mess-up the configuration. But again, it looks like a huge risky change, yet it's replaced with fewer lines of code (i.e. easier to read), using battle tested Python built-in. There are lot I don't like with the logging system in Python (I even made a talk at a Python French Conference about how ugly its documentation is), yet it's a standard, and it does its job wonderfully: it's steady, functional, and quite simple to reuse all over the place (in core, plugins, etc.). As a result, changing the log level wouldn't do us any good, but create lots of unintended side effects that would inevitably lead us to... replace everything with logging. I Have Some Design Questions.
|
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.
Almost an hour since I reviewed #1680, and nearly the entire time was spent directly on this. It's a big patch! But the more I thought about your arguments, and the more I looked at the changes themselves, the more convinced I became that this is necessary, and that sopel.logger.get_logger
is indeed a kludge at best.
This completes (for now) my list of "Awaiting your review" PRs. I expect it will have more entries in 12-24 hours at most, since the bulk of the PRs I reviewed were yours and you have a lot of free time coming up. 😁
Edit: Forgot to mention this before submitting the review, but what if we just moved sopel.logger
to sopel.logging
? It would make a lot more sense being named that, since it isn't a "logger" at all, but the "logging" machinery.
2098e26
to
6b193a1
Compare
ea2bdf6
to
bafe757
Compare
The live test for Google Translate is broken. Of course it is. |
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.
One easy English nitpick, and a logic question that might or might not be relevant depending on how bad my quick-glance code comprehension is. 😹
From an unrelated IRC question, I found Line 218 in c752b10
Can you change that in this PR so we don't need to open a separate one? 😸 |
bafe757
to
da5a0ab
Compare
da5a0ab
to
173ebf7
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.
I had some conflicting ideas about get_logger
vs. get_plugin_logger
. Obviously, not all of them were good: Good ideas don't conflict with each other. (Just kidding; sometimes they do.) But here are the ones that didn't conflict and seemed good enough to share.
One part of me wants to keep the simple name get_logger
going forward, since the new function does basically the same thing when passed a name (the only supported use now). Since we only supported get_logger()
with no argument in core, and third parties always should have used get_logger('name_here')
, would we invite catastrophe by keeping the old name around?
Another part of me thinks that get_plugin_logger
belongs somewhere in sopel.tools
, and/or that sopel.logger
should really be named sopel.logging
(potential for import name clashes with stdlib notwithstanding—i.e. from sopel import logging
and import logging
in the same file). Any thoughts?
You'll find the usual grammatical tweaks attached. 😛
My main concern is that its docstring promoted
What about |
fa69c4a
to
d0b47ae
Compare
@dgw I made the changes I suggested above. I think it's a sane approach, and I'm glad you made me reconsider this. 😃 With that, internal plugins will have to use: # in sopel/modules/clock.py
import logging
LOGGER = logging.getLogger(__name__) And it'll be under the For an external plugin, such as # in modsopelunker.py
from sopel import plugins
LOGGER = plugins.get_logger('sopelunker') Which will log everything with the |
It was a nice idea, having a shortcut to get a logger. However, logging is a python built-in, a de-facto standard since ages, so let's use it instead. Beside, the docstring is bonkers. Do not use `get_logger(__name__)`! Inside a python module `__name__` is its python dotted path. So for example in `sopel.modules.ip`, using `get_logger(__name__)` would mean using the logger `sopel.modules.sopel.modules.ip`... which is kind of dumb. For external plugins, it's best to provide a good "how to configure logging for your plugin" instead of using a bad shortcut function that doesn't do what you would expect.
And also fix my English grammar, but it fits nicely with the theme of "fixing messages". Co-Authored-By: dgw <dgw@technobabbl.es>
As per usual... ;-) Co-Authored-By: dgw <dgw@technobabbl.es>
@dgw I moved |
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.
Some of these were left over from an interrupted review a little while back, and some are new. Basically all of them are nitpicking. I wanna get this merged today! 🚀
Co-Authored-By: dgw <dgw@technobabbl.es>
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.
Quick, before I notice any more grammar to tweak!
(RIP "Conversation [69]", sorry @Exirel 😆)
🎉 |
This argument was already nonfunctional in 7.x anyway, due to #1678 and related logging changes. Seems like no one was using it anyway. Instead of this, users who need Sopel to run without printing to the terminal can use the usual shell trick: command >> /dev/null 2>&1
This argument was already nonfunctional in 7.x anyway, due to #1678 and related logging changes. (Seems like no one was using it, since we never got a report/complaint that it was broken.) Instead of this, users who need Sopel to run without printing to the terminal can use the usual shell trick: command >> /dev/null 2>&1
Fix #1337
Python built-in logging package makes a lot of thing way easier: no more raw log manually added to a file, no more a scaffold of try/except because opening a log file could be a problem... everything better now.
Of course, this isn't 100% ISO-functionnal, because that's not the point. And I'm also sure we could spend a ridiculous amount of time to make sure we have a 100% perfectly consistent logging system everywhere.
But I believe it's a good first step. Something that we can be proud of, and build upon. It's still better quality code than it was!