Mmm, even after this log.py goes into models/log.py, I think the line: logging=cache.ram(...) should be replaced by: import logging # logging=cache.ram(...) # Uncomment me if you need app-logging
Because: 1. My log.py will cause the an incremental system.log which will eventually cram up your disk, hence it is not good for production site, unless you use RotatingFileHandler instead. 2. On GAE, you can not write to disk anyway, unless you use SMTPHandler or HTTPHandler etc. You get the idea. //shrug On Jun10, 2:45am, Iceberg <iceb...@21cn.com> wrote: > I am glad you like it. So every new app will have a models/log.py > soon? > > BTW, I personally prefer this formatter, hope you do: > "%(asctime)s %(levelname)s %(funcName)s():%(lineno)d %(message)s" > > On Jun10, 2:22am, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > I think you nailed it! I would change the file name so that it resides > > inside the applicaitons folder: > > > handler=logging.FileHandler(os.path.join(request.folder,"system.log")) > > > we could also add a line in the admin to peek the log (like with > > sql.log). > > > On Jun 9, 12:18 pm, Iceberg <iceb...@21cn.com> wrote: > > > > request.log(message) would be nice, but all the advantages of standard > > > logging are too good to let go. So I came up with this little trick. > > > > 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) > > > > Then, in any of your controller, you can just do the usual: > > > logging.warn('blah blah') > > > The only tricky point is you can not do this inside your controller: > > > import logging > > > otherwise you lose the magic. ;-) > > > > Besides, thanks for Hans for bringing up all the issue, which inspires > > > me to find the solution (at least for me) for this problem haunting me > > > for long time. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---