[Grok-dev] switching off grok warnings on startup
uli at gnufix.de
Fri May 21 08:33:18 EDT 2010
Martijn Faassen wrote:
> Uli Fouquet wrote:
> > Or are there any other ideas how to tell 'the system' (not) to emit
> > warnings?
> Hm, I wasn't sure whether this would be easy, that's why it needed
> looking into. :)
> I assume you've looked into the logging module's facilities for warning
> levels? Whatever we do to get the information in, we should probably use
> it to configure the warning levels the user is interested in.
No, I admit I didn't consider the logging module. But this is an obvious
and excellent idea, exactly, what I was looking for :-)
I changed grokcore.view to emit log messages of level `logging.WARNING`
to a standard lib logger named ``grokcore.view``. This logger is
initialized by grokcore.view to log messages of level `logging.ERROR`.
In result by default there are no warnings emitted anymore.
The logger is _not_ initialized, if it detects that:
- the logger already provides a handler or
- the logger's level was already set
This means, that you can reenable warnings simply by setting up a logger
named ``grokcore.view`` with loglevel set to something different from
`logging.NOTSET` before the actual grokking is done.
This can be done in pure Python::
logger = logging.getLogger('grokcore.view')
logger.level = logging.INFO
or for instance in the .ini files of a regular grokproject like this:
Change the [loggers] section of debug.ini to read::
keys = root, wsgi, grok
and add a new section like this::
level = INFO
handlers = console
qualname = grokcore.view
propagate = 0
and voila, you get the template registry warnings back.
Using the .ini files you can now also let the warnings appear in regular
logfiles if you want, so they won't get lost and forgotten.
I'd propose to add appropriate sections in the generated .ini files of
grokproject from now on (with warning messages enabled in debug.ini,
disabled in deploy.ini). Maybe we can include this in the 2.0 release of
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20100521/e5dff777/attachment.bin
More information about the Grok-dev