Log template errors to stdout when debugging.

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