getpelican/pelican — pull request #1412 by avaris (2014-07-22 16:52:54+00:00)
Title: Refactor logging handling

Old system was using manual string formatting for log messages.
This caused issues with common operations like exception logging
because often they need to be handled differently for Py2/Py3
compatibility. In order to unify the effort:

- All logging is changed to `logging.level(msg, arg1, arg2)` style.
- A `SafeLogger` is implemented to auto-decode exceptions properly
in the args (ref #1403).
- Custom formatters were overriding useful logging functionality
like traceback outputing (ref #1402). They are refactored to be
more transparent. Traceback information is provided in `--debug`
mode for `read_file` errors in generators.
- Formatters will now auto-format multiline log messages in order
to make them look related. Similarly, traceback will be formatted in
the same fashion.

*Before:*
```
WARNING: Could not process ./test_page2.rst
'Page' object has no attribute 'not_existing_attr'
```

*Now:*
```
# normal
ERROR: Could not process ./test_page2.rst
| 'Page' object has no attribute 'not_existing_attr'

# --debug
DEBUG: Read file test_page2.rst -> Page
ERROR: Could not process ./test_page2.rst
| 'Page' object has no attribute 'not_existing_attr'
|___
| Traceback (most recent call last):
| File "/home/dturgut/src/pelican/pelican/generators.py", line 600, in generate_context
| context_sender=self)
| File "/home/dturgut/src/pelican/pelican/readers.py", line 476, in read_file
| context=context)
| File "/home/dturgut/src/pelican/pelican/contents.py", line 136, in __init__
| signals.content_object_init.send(self)
| File "build/bdist.linux-x86_64/egg/blinker/base.py", line 267, in send
| for receiver in self.receivers_for(sender)]
| File "/home/extra/workspace/web/test_pelican/dummy_plugin.py", line 4, in f
| print(content.not_existing_attr)
| AttributeError: 'Page' object has no attribute 'not_existing_attr'
```

- `pelican.log.LimitFilter` was (ab)using logging message which
would result in awkward syntax for argumented logging style. This
functionality is moved to `extra` keyword argument.
- Levels for errors that would result skipping a file (`read_file`)
changed from `warning` to `error` in order to make them stand out
among other logs.
- Small consistency changes to log messages (i.e. changing all
to start with an uppercase letter) and quality-of-life improvements
(some log messages were dumping raw object information).

```
DEBUG: read file test_page2.rst -> Page
# changed into
DEBUG: Read file test_page2.rst -> Page
```

and
```
DEBUG: signal .send()
# changed into
DEBUG: Signal page_generator_preread.send(PagesGenerator)
```