On Sep1, 2:00am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> It seems to me the scaffolding app is already too heavy. Somebody has
> proposed having multiple scaffolding apps.
>
> If you make an app with this model and a controller for reading/
> searching the logs, I will post it (for now) on appliances as an
> example.
>
> Massimo

I like lightweight solution too. So, to keep things simple and stupid,
I modified the log_model.py as below, so that user can read logs
WITHOUT dedicated controller or action, and user can search log by
browser's search function.

And I think the following log_model.py is small enough (811 bytes) to
be included in the scaffolding app. Just drop it into any app, then it
will work. On the contrary, make it a sample app on applicances or
just mention it in AlterEgo, won't get enough attention.

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

--~--~---------~--~----~------------~-------~--~----~
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