I am currently working on the 1.0a pyftpdlib release. In this new release, some lagging incompatible changes will be made in that some APIs will no longer accept bytes, but unicode. While I am in this, as part of this burden, I have been thinking about being able to get rid of my registration functions, which currently use print, and use the logging module instead.
Pyftpdlib is currently delegating an entry into 3 functions:
def log(s): """Log messages intended for the end user.""" print s def logline(s): """Log commands and responses passing through the command channel.""" print s def logerror(s): """Log traceback outputs occurring in case of errors.""" print >> sys.stderr, s
A user who wants to configure the logs (for example, write them to a file) should simply overwrite these 3 functions, as in:
>>> from pyftpdlib import ftpserver >>> >>> def log2file(s): ... open('ftpd.log', 'a').write(s) ... >>> ftpserver.log = ftpserver.logline = ftpserver.logerror = log2file
Now I'm wondering: what benefits would it mean to get rid of this approach and use the logging module instead? From the perspective of the module provider, how exactly should I open the registration functions in my module? I must do it:
import logging logger = logging.getLogger("pyftpdlib")
... and indicate in my document that the “registrar” is the object that is supposed to be used if the user wants to configure the behavior of the logs? Is deliberate assignment of a predetermined output format legal, as in:
FORMAT = '[%(asctime)] %(message)s' logging.basicConfig(format=FORMAT) logger = logging.getLogger('pyftpdlib')
...
Can you think of a third-party module, I can take signals from where the logging functions are open and integrated as part of a public API?
Thanks in advance.
Giampaolo rodolà
source share