[Grok-dev] switching off grok warnings on startup

Christian Klinger cklinger at novareto.de
Fri May 21 08:39:23 EDT 2010


Hey Uli,

that sounds like a very cool solution.

+1

Christian

  Uli Fouquet:
> Hi there,
>
> 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::
>
>    import logging
>    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::
>
>    [loggers]
>    keys = root, wsgi, grok
>
> and add a new section like this::
>
>    [logger_grok]
>    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
> grokproject?
>
> Best regards,
>
>
>
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev




More information about the Grok-dev mailing list