limitations of current logging package

vjshield-widgets at yahoo.com vjshield-widgets at yahoo.com
Sun Oct 3 05:15:22 EDT 2004


Couple of questions/comments:

1. I found easylog pretty useful and easy to use.

http://sourceforge.net/projects/easylog/

But it was pretty slow and added a significant amount
of overhead to my application. I have long running
processes in my application. 

2. I then used the following (please see attached
code) to handle logging in my application. I read the
logging properties from a ZConfig file. I moved part
of the application to mod_python, and now my log
entres go to the apache log file. How can I force log
messages generated in my application go to my log
files?

class LoggingBase(object):
    def __init__(self, config):
        if (config.logconfig.logging):
            format          = config.logconfig.format
            dateformat      =
config.logconfig.dateformat
            level           = config.logconfig.level
            loggingdir      =
config.logconfig.loggingdir
            loggingfilepath =
loggingdir+config.logconfig.loggingfile
            formatter       =
logging.Formatter(format, dateformat)
            handler         =
logging.FileHandler(loggingfilepath)
            handler.setFormatter(formatter)
            log = logging.getLogger("")
            log.setLevel(LogLevel().convert(level))
            log.addHandler(handler)
            log.info("logging initialized; and turned
on. Logs will be created in (%s)" % loggingfilepath)
        else:
            log = logging.getLogger("")
            log.handlers = []
            log.info("logging initialized; and turned
off")
        self.logger = logging.getLogger("")
        self.logger.info("logging initialized")


class LogLevel:
    def convert(self, value):
          _levels = {
              "fatal": 50,
              "error": 40,
              "warn": 30,
              "info": 20,
              "debug": 10,
              "all": 0,
              }

          s = str(value).lower()
          if _levels.has_key(s):
              return _levels[s]
          else:
              v = int(s)
              if not (0 <= v <= 50):
                  raise ValueError("log level not in
range: " + `v`)
              return v



More information about the Python-list mailing list