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)])}
On Jun10, 5:52pm, Hans <
johann.scheibelho...@easytouch-edv.com> wrote:
> WOW Iceberg! That should also work well for me. Thanks for sharing
> your solution idea! I'm going to try it later today.
> And I agree the 'uncomment me if you need app-logging' approach in
> combination with the per-application-log-file seems also to me the
> best (backward compatible, flexible).
>
> Since I'm going to implement that for me anyway I'll send my code when
> its finised...in case you want to improve it and/or Massimo wants to
> incorporate it in future web2py versions.
>
> On Jun 9, 9:02 pm, Iceberg <
iceb...@21cn.com> wrote:
>
> > 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
>
>