From 7afa1558e3b894003e0dbf8e980760073eca3446 Mon Sep 17 00:00:00 2001 From: Dave Dash Date: Thu, 1 Apr 2010 12:24:14 -0700 Subject: [PATCH] Filterable log settings. --- docs/topics/logging.rst | 10 ++++++++++ log_settings.py | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/topics/logging.rst b/docs/topics/logging.rst index 1f5cc3d64a..2c6ef6c942 100644 --- a/docs/topics/logging.rst +++ b/docs/topics/logging.rst @@ -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 diff --git a/log_settings.py b/log_settings.py index 2184f1ba03..15f604136f 100644 --- a/log_settings.py +++ b/log_settings.py @@ -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)