Repository: getpelican/pelican

Issue:
LOG_FILTER cannot be used with '%s'ed messages
Currently LOG_FILTER doesn’t allow ignoring messages with '%s' placeholders, because `ignore_key` variable in `filter` method of `log` module use 'getMessage()' method of `LogRecord` class, but not `msg` field.

Example which isn’t work:

```
LOG_FILTER = [
    (logging.WARN, 'Empty alt attribute for image %s in %s')
]
```

The problem is that now no way to suppress such warnings. I guess, filtering by `msg` field doesn’t break anything, but allow to more complex filtering.

Or maybe better intruduce another varible, say LOG_FILTER_GROUP, with such functionality.



Discussion:
I noticed this while I was doing the log refactoring, and I think this was intentional. Although I agree this might be useful, it also has a few caveats:
- In order to figure out the `%s` template, one has to dig into pelican's code. This is probably not practical for an average pelican user.
- If you filter by the template, you'll also be suppressing all the future messages as well. This might cause problems (i.e. hide some useful logs) if you're not careful.

Also, warnings that might be too 'nagging' (like your example) usually has a limiter. It'll stop after `5`. I think `5` is hardcoded, but we can make this number configurable. Will that help?

Yes, limit for one group messages is handy feature. But I think problem with unneeded warnings can be solved in more clear way, just like in gcc: there is options for disabling group of warnings (`-Wno-…`). List all is pretty hard, but it's realistic for group of messages, that user likely want to silence.

Second issue that you point is also applicable for that approach, but it’s less error-prone when list maintained in one place, not in user repositories.

…or maybe alt text warnings must be info messages :)

Any thought?

To add to this, empty alt attributes is nothing bad. See this comment how useless alt attributes can add a lot of unnecessary text to screen readers: http://www.456bereastreet.com/archive/200811/writing_good_alt_text/


Resolving patch:
diff --git a/pelican/log.py b/pelican/log.py
--- a/pelican/log.py
+++ b/pelican/log.py
@@ -92,6 +92,7 @@ class LimitFilter(logging.Filter):
     """
 
     _ignore = set()
+    _raised_messages = set()
     _threshold = 5
     _group_count = defaultdict(int)
 
@@ -105,12 +106,18 @@ def filter(self, record):
         group_args = record.__dict__.get('limit_args', ())
 
         # ignore record if it was already raised
-        # use .getMessage() and not .msg for string formatting
-        ignore_key = (record.levelno, record.getMessage())
-        if ignore_key in self._ignore:
+        message_key = (record.levelno, record.getMessage())
+        if message_key in self._raised_messages:
             return False
         else:
-            self._ignore.add(ignore_key)
+            self._raised_messages.add(message_key)
+
+        # ignore LOG_FILTER records by templates when "debug" isn't enabled
+        logger_level = logging.getLogger().getEffectiveLevel()
+        if logger_level > logging.DEBUG:
+            ignore_key = (record.levelno, record.msg)
+            if ignore_key in self._ignore:
+                return False
 
         # check if we went over threshold
         if group:


Test patch: