On Tue, 27 Apr 2010 09:31:50 -0700 (PDT), minkto...@gmail.com said:

> I'd be interested in a step by step guide to setting up this kind of
> logging.

I found some older posts that helped in the end. I now have a
modules/logging.py file that looks like:

def _init_log():
    """
    From http://article.gmane.org/gmane.comp.python.web2py/11091
    """

    import logging
    from logging.handlers import SysLogHandler

    logger = logging.getLogger(request.application)
    logger.setLevel(logging.DEBUG)
    handler = SysLogHandler(address='/dev/log')
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(logging.Formatter(
        '%s' % request.application + '[%(process)d]: %(levelname)s:
    %(filename)s at line %(lineno)d: %(message)s'))
    logger.addHandler(handler) return logger

logging=cache.ram('once',lambda:_init_log(),time_expire=99999999)

Then, when I want to log something, I do:

logging.debug("blah")

".debug" can be the other standard values including ".exception",
".error", ".info", etc

I don't claim originality for the above: I adapted it slightly from the
URL quoted.

Given the unexpected challenges in implementing this in web2py, I think it
would make sense to include it in the scaffolding (but I'm probably wrong).


-- 
Subscription settings: http://groups.google.com/group/web2py/subscribe?hl=en

Reply via email to