Open TheAssassin opened 3 years ago
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.
Makes sense. In all actuality, the whole library actually is already using 2 loggers: mail.log
and mail.debug
. Splitting the "verbose" logging might be a good idea, say into a mail.verbose
logger. (We'll need to think of the name and hierarchy).
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 _handle_client
, might be a good idea to start a different issue.
Sorry to actually start the log level discussion, but I feel like having a logger literally called .debug
with the existence of the .debug
log level seems kinda redundant.
Usually it makes more sense to split logger names by part of the library, most of the times import name aiosmtpd.handlers
, aiosmtpd.server
etc.
That's just my two €0.02 though, as I just stumbled over this library.
Sorry to actually start the log level discussion, but I feel like having a logger literally called
.debug
with the existence of the.debug
log level seems kinda redundant. Usually it makes more sense to split logger names by part of the library, most of the times import nameaiosmtpd.handlers
,aiosmtpd.server
etc.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.