Catches/logs UnicodeDecodeError.

def _log_unicode_errors(logger, log_level):
    """
    Catches/logs UnicodeDecodeError.
    """
    def log_debug_render(*args, **kwargs):
        try:
            return debug_variable_node_render(*args, **kwargs)
        except UnicodeDecodeError:
            logger.log(
                log_level,
                "UnicodeDecodeError in template rendering",
                exc_info=True)
        return ''

    def log_render(*args, **kwargs):
        try:
            return variable_node_render(*args, **kwargs)
        except UnicodeDecodeError:
            logger.log(
                log_level,
                "UnicodeDecodeError in template rendering",
                exc_info=True)
        return ''

    patch_base = patch.object(VariableNode, 'render', log_render)
    patch_all = patch_base
    if django.VERSION < (1, 9):
        from django.template.debug import DebugVariableNode
        patch_debug = patch.object(DebugVariableNode, 'render',
                                   log_debug_render)
        patch_all = _compose(patch_all, patch_debug)
    return lambda f: patch_all(f)