Log template errors to stdout when debugging.

Create a `LoggingUndefined` type that logs to stdout on template errors and passes it to the jinja2 environment if the debug flag is set. Fixes #1006