-
Notifications
You must be signed in to change notification settings - Fork 96
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
Introduce different loggers for different purposes #239
Comments
Makes sense. In all actuality, the whole library actually is already using 2 loggers: That said, such changes will definitely not go into the 1.x series, as it will be breaking. I'll mark the idea in #229 for inclusion in 2.x As for the other suggestion you have, namely separating |
Sorry to actually start the log level discussion, but I feel like having a logger literally called That's just my two €0.02 though, as I just stumbled over this library. |
For SMTP related stuff, traditionally we go with at least the "mail" part as it will map to syslog facility of "mail" (though practically whatever the log is named, Python can map it to any syslog facility.) The current name of "mail.log" and "mail.debug" is currently considered legacy and not changeable due to the possibility of breaking with users of this library. We'll rethink how best to tidy up the logging problems in 2.0. |
I've recently come across this library, and am in the process of implementing some tools using it. However, I find the logging a bit too verbose for production use:
All I'm interested in is basically "client connected" and "client disconnected". The rest is logged in my handler anyway. However, I have no chance of filtering these messages.
In Python, we have two dimensions that can be used to filter log messages: logger name and loglevel. Now, one can argue very much about what kind of log level to choose for different types of messages. I personally think these "info" messages that print every single message sent and received would better suit a "verbose" (which doesn't exist in Python by default) or "debug" level, as the average user doesn't usually need to see them unless they're debugging.
However, I'd rather not start a discussion on log levels but suggest to use different loggers for different purposes. Instead of a
mail.log
that shall fit all purposes, one could havemail.smtp
logger for theSMTP
class that prints theconnection made
andconnection lost
messages, etc. See https://docs.python.org/3/library/logging.html#logger-objects and https://docs.python.org/3/library/logging.html#logging.Logger.getChild for more information on logger hierarchy.Right now, it's not really viable to implement such a change by just adding class-specific loggers, as the majority of the logic is contained in
SMTP
. Therefore, it might make more sense to just add purpose-specific loggers likemail.connection
ormail.auth
.I think this might also be a chance to refactor the (very large and complex) SMTP class, e.g., by extracting
_handle_client
into something like aClientHandler
to implement separation of concerns and split responsibilities better. This eliminates the need forSMTP
to know about any of these implementations, and maybe even swap the implementations via DOI to also make testing easier. In fact, there are already some classes likeSession
into which the algorithms might be moved, but right now they're merely used to track state, whereas the business logic remains inSMTP
. I guess this discussion should be moved into another issue, though.The text was updated successfully, but these errors were encountered: