Filterable log settings.
This commit is contained in:
Родитель
637aabd255
Коммит
7afa1558e3
|
@ -27,6 +27,16 @@ tree. It sets up sensible defaults, but you can twiddle with these settings:
|
|||
import logging
|
||||
LOG_LEVEL = logging.WARN
|
||||
|
||||
``LOG_FILTERS``
|
||||
If this optional setting is set to a tuple, only log items matching strings
|
||||
in said tuple will be displayed.
|
||||
|
||||
For example::
|
||||
|
||||
LOG_FILTERS = ('z.sphinx.', )
|
||||
|
||||
This will show you messages **only** that start with ``z.sphinx``.
|
||||
|
||||
``LOG_FORMAT``
|
||||
This string controls what gets printed out for each log message. See the
|
||||
default in ``log_settings.py``. The complete list of formatting options is
|
||||
|
|
|
@ -11,7 +11,8 @@ log = logging.getLogger('z')
|
|||
level = settings.LOG_LEVEL
|
||||
|
||||
if settings.DEBUG:
|
||||
fmt = '%(asctime)s %(name)s:%(levelname)s %(message)s :%(pathname)s:%(lineno)s'
|
||||
fmt = ('%(asctime)s %(name)s:%(levelname)s %(message)s '
|
||||
':%(pathname)s:%(lineno)s')
|
||||
fmt = getattr(settings, 'LOG_FORMAT', fmt)
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter(fmt, datefmt='%H:%M:%S')
|
||||
|
@ -26,4 +27,8 @@ else:
|
|||
log.setLevel(level)
|
||||
handler.setLevel(level)
|
||||
handler.setFormatter(formatter)
|
||||
|
||||
for f in getattr(settings, 'LOG_FILTERS', []):
|
||||
handler.addFilter(logging.Filter(f))
|
||||
|
||||
log.addHandler(handler)
|
||||
|
|
Загрузка…
Ссылка в новой задаче