找不到记录器“xhtml2pdf”的处理程序 [英] No handlers could be found for logger "xhtml2pdf"

查看:180
本文介绍了找不到记录器“xhtml2pdf”的处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xhtmltopdf.pisa从HTML模板生成pdf。代码正常工作。

I'm using xhtmltopdf.pisa for generating pdf from html template. The code was working fine.

pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), dest=result, link_callback=fetch_resources, default_css=open(pdf_css_path, 'r').read())

但有时我注意到,上面的代码不工作。错误是找不到记录器xhtml2pdf的处理程序。只有一段时间,我可以找到这个错误,但其他时间只是工作正常。

But some times I noticed that, the above code is not working. The error threw was No handlers could be found for logger "xhtml2pdf". Only some times I can find this error, but other times just works fine.

任何帮助都不胜感激。

Any help is appreciated.

推荐答案

错误的原因是,比萨模块有一段时间使用Python的日志记录模块来记录警告或错误。默认情况下,它尝试访问名为 xhtml2pdf 的记录器。所以你需要在你的设置文件中定义一个 xhtml2pdf 的处理程序。

The reason for the error is that, the pisa module some time uses the Python's logging module to log warnings or errors. By default it is trying to access a logger named xhtml2pdf. So you need to define a handler for xhtml2pdf on your settings file.

Django的日志记录设置看起来像这样,

Django's logging settings would look like this,

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
    'standard': {
        'format': "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
        'datefmt': "%d/%b/%Y %H:%M:%S"
        },
    },
    'handlers': {
        'logfile': {
            'level': 'DEBUG',
            'filename': BASE_DIR + "/Log/info.log"
        },
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
            'formatter': 'standard'
        },
    },
    'loggers': {
        'django': {
            'handlers': ['console'],
            'propagate': True,
            'level': 'WARN',
        },
        'xhtml2pdf': {
            'handlers': ['logfile'],
            'level': 'DEBUG'
       },
   }
}

这个错误不一致的原因是bacause,比萨可能不会一直使用记录器。

The reason for this error's inconsistacy is bacause, pisa maynot use logger all the time.

这篇关于找不到记录器“xhtml2pdf”的处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆