<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def log_template_errors(logger, log_level=logging.ERROR):
 """ Decorator to log template errors to the specified logger. @log_template_errors(logging.getLogger('mylogger'), logging.INFO) def my_view(*args):
 pass Will log template errors at INFO. The default log level is ERROR. """

    if not (isinstance(log_level, int) and
            log_level in logging._levelNames):
        raise ValueError('Invalid log level %s' % log_level)

    decorators = [
        _log_template_string_if_invalid(logger, log_level),
        _log_unicode_errors(logger, log_level),
        _always_strict_resolve,
    ]
    if django.VERSION < (1, 8):
        decorators.append(_patch_invalid_var_format_string)

    @decorator
    def function(f, *args, **kwargs):
        return reduce(__apply, decorators, f)(*args, **kwargs)

    return function