logging module usage

M

mennis

I am working on a library for controlling various appliances in which
I use the logging module. I'd like some input on the basic structure
of what I've done. Specifically the logging aspect but more general
comments are welcome. I'm convinced I mis-understand something but
I'm not sure what. I've posted a version of the library at github.

(e-mail address removed):mennis/otto.git
http://github.com/mennis/otto
Ian
 
V

Vinay Sajip

I am working on a library for controlling various appliances in which
I use theloggingmodule.  I'd like some input on the basic structure
of what I've done.  Specifically theloggingaspect but more general
comments are welcome.  I'm convinced I mis-understand something but
I'm not sure what.  I've posted a version of the library at github.

(e-mail address removed):mennis/otto.githttp://github.com/mennis/otto
Ian

From a quick glance over your code, looking only at the logging
perspective:

It's fine to use the Django-like approach to provide better
compatibility with Python versions < 2.5.

Your use of an extra level is also OK, but other applications and
tools won't know about your extra level, which could limit
interoperability. If your application is completely self contained,
however, that should be fine.

You don't really need to hold loggers as instance attributes in
objects - they are effectively singletons.

The convention is to use logger = getLogger(__name__), that way you
don't have to change your code to rename loggers if you move modules
around in a package.

Not sure why you are doing logging.disable() in code, this means that
you can't change the verbosity using configuration files.

You don't appear to be using the logger.exception() method in
exception handlers, thereby not putting tracebacks in the log.

You don't add a NullHandler to the root logger of your top-level
package, which you should.

I see you're using Python 2.x, but you may nevertheless find it useful
to look at the logging docs for Python 3.2. These have been split into
reference docs and HOWTOs, rather than the somewhat monolithic
approach taken in the 2.x docs.

Regards,

Vinay Sajip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top