For your information. There is a refined version later. (And that's
why I suggest add it into scaffold welcome app, this way people can
easily get a latest version.)

The new version uses RotatingFileHandler so that you need not worry
the log file grows up unlimitedly, and the log file can be viewed via
WEB even without writing an action for it. Yet it does not support
GAE. But it does not harm anyway if you just put it in yourapp/models
but not using it.

# This model file defines some magic to implement app_wide_log.
def _init_log(): # Does not work on GAE
    import os,logging,logging.handlers
    logger = logging.getLogger(request.application)
    logger.setLevel(logging.DEBUG)
    handler = logging.handlers.RotatingFileHandler(
      os.path.join( # so that it can be served as 
http://.../yourapp/static/applog.txt
        request.folder,'static','applog.txt'),'a',1024*1024,1)
    handler.setLevel(logging.DEBUG)
    handler.setFormatter(logging.Formatter(
      "%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(funcName)s
(): %(message)s"))
    logger.addHandler(handler)
    return logger
app_logging = cache.ram('app_wide_log',lambda:_init_log
(),time_expire=None)


On Sep28, 9:13pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Some time ago Iceberg suggesting adding the following model for
> logging:
>
> Add following codes inside model/log.py:
>
>  def _init_log():
>    import logging
>    logger=logging.getLogger(request.application)
>    logger.setLevel(logging.DEBUG)
>    handler=logging.FileHandler("%s.log"%request.application)
>    handler.setLevel(logging.DEBUG)
>    handler.setFormatter(logging.Formatter(
>      "%(levelname)s %(asctime)s %(funcName)s %(lineno)d %(message)
> s"))
>    logger.addHandler(handler)
>    return logger
>  logging=cache.ram('once',lambda:_init_log(),time_expire=99999999)
>
> On Sep 28, 7:32 am, Roar <roar.skulles...@gmail.com> wrote:
>
>
>
> > I've added the following to the default.py controller:
>
> > import logging
> > LOG_FILENAME = '/tmp/log/log.txt'
> > logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)
>
> > logging.debug('This message should go to the log file, but it does
> > not')
>
> > ...but nothing is being logged. Any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to