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)