Not at all. The cache.ram in log.py is to make sure the logger is inited only once, otherwise we will see more and more duplicate log appearing in the log file as Hans mentioned in his earlier posts. The only downside is that you need to restart web2py if you change (but usually you don't need to) log definition.
As to the "OPTIONAL in controller" part, you can ignore it. They are just a rough demo and not necessary. On Jun11, 3:17am, mdipierro <mdipie...@cs.depaul.edu> wrote: > Why do you need to cache the logging module? Is this only for speed? > > On Jun 10, 1:44 pm, Iceberg <iceb...@21cn.com> wrote: > > > After changing from FileHandler to RotatingFileHandler, now I think > > the per-app log can be turned on by default (otherwise new comers > > won't notice this good feature). > > > The only thing I am still not sure is whether one can use logging and > > its FileHander (or RotatingFileHander) on GAE's readonly filesystem. > > Tests are welcome. > > > Anyway, this is my latest code. Maybe it can help you. > > > import logging > > def _init_log(level=logging.DEBUG): > > import os,logging.handlers > > logger=logging.getLogger(request.application) > > logger.setLevel(level) > > if request.env.web2py_runtime_gae: # if running on Google App > > Engine > > handler=logging.handlers.HTTPHandler( > > request.env.http_host,URL(r=request,f='log')) # assuming there > > is an optional log action > > else: > > handler=logging.handlers.RotatingFileHandler( > > os.path.join > > (request.folder,'app.log'),maxBytes=1024*1024,backupCount=2) > > handler.setLevel(level) > > handler.setFormatter(logging.Formatter( > > "%(asctime)s %(levelname)s %(funcName)s():%(lineno)d %(message) > > s")) > > logger.addHandler(handler) > > return logger > > logging=cache.ram('mylog',lambda:_init_log(),time_expire=99999999) > > > OPTIONAL in controller: > > > def log(): > > if request.vars: # append > > history=cache.ram('log_in_cache',lambda:[],time_expire=99999999) > > history.append(request.vars) > > cache.ram('log_in_cache',lambda h=history:h,time_expire=0)#set > > else: # show > > return {'':TABLE(*[TR(item) for item in > > cache.ram('log_in_cache',lambda:None,time_expire=99999999)])} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" 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 -~----------~----~----~----~------~----~------~--~---