pombreda / xhtml2pdf

Automatically exported from code.google.com/p/xhtml2pdf
GNU General Public License v2.0
0 stars 0 forks source link

no handler could be found for logger "ho.pisa" #64

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Using pisa-3.0.32 on Ubuntu Linux 10.04 x64 with Python 2.6.5 and
Django-1.1.1 makes pisa does not work, raising the following warning when
used from Django source code:
no handler could be found for logger "ho.pisa"
But, if pisa is called outside Django it works e. g. a Python script.

Even though, if using Ubuntu 9.10 x64 with Python 2.6.4 and Django 1.1.1 it
works well.

One more thing to point out is that when pisa works and imports ho.pisa the
following deprecation warning is raised:
/usr/lib/pymodules/python2.6/pyPdf/pdf.py:52: DeprecationWarning: the sets
module is deprecated
  from sets import ImmutableSet

So, I guess that there will be some incompatibility problems because of the
new Python version.

Original issue reported on code.google.com by caum...@gmail.com on 27 May 2010 at 6:24

GoogleCodeExporter commented 9 years ago
Same error on using function "ho.pisa.CreatePDF" from standard Python pisa 
module importing.

"No handlers could be found for logger "ho.pisa""

Original comment by shin...@gmail.com on 26 Jul 2010 at 3:55

GoogleCodeExporter commented 9 years ago
I see this error ( No handlers could be found for logger "ho.pisa"
)  in the error.log but all is working apart from image display.  NOt sure if 
these are related.

Original comment by phoebebr...@gmail.com on 17 Aug 2010 at 10:03

GoogleCodeExporter commented 9 years ago
xhtml2pdf, when used as a standalone binary, uses a Python "Logger" (from 
logging module) to log messages. Each logger outputs to one (or more) "Handler".
When used as a module or in certain conditions, ho.pisa does not create a 
"Handler" for Logger (you would not like a module to create .log files by 
itself), but still uses Logger.

To bypass these nagging messages, ho.pisa have to declare a sort of 
"NullHandler" for its Logger(s) (see 
http://docs.python.org/library/logging.html#library-config).

Anyway, one can bypass nagging "no handler could be found for logger ho.pisa" 
by doing :

import logging
class PisaNullHandler(logging.Handler):
    def emit(self, record):
        pass
logging.getLogger("ho.pisa").addHandler(PisaNullHandler())

Original comment by shin...@gmail.com on 17 Aug 2010 at 10:57

GoogleCodeExporter commented 9 years ago
When this error happened to me no PDFs where created, so it was not just a 
warning. As I explained I used it with Django. I do not know if using the 
"quick and dirty" solution proposed by shinkan would solve the problem. And 
what is more... where should we  put this code when working with the framework 
Django? If it is possible.

Original comment by caum...@gmail.com on 20 Aug 2010 at 10:53

GoogleCodeExporter commented 9 years ago
I had problem with generation too, but I think despite the facts that it was 
not correlated with log warning.
My problem was about encoding : I had to explicitly encode source string to 
iso-... instead of utf-8 (or maybe the other way).

About log warn : this is the responsibility of the module publisher to define 
and use the NullHandler when needed. This "quick and dirty" solution is the one 
given by Python doc before 2.7 (there is a dedicated handler for this situation 
since 2.7).

As caumons says, the "quick and dirty" solution is difficult to properly 
integrate within a framework.

Original comment by shin...@gmail.com on 20 Aug 2010 at 11:51

GoogleCodeExporter commented 9 years ago
Some time ago Pisa AKA XHTML2PDF has been rereleased under the completely free 
Apache License. Since I personally don't have the time and resources to 
continue the project like before I would kindly ask you to fork the project on 
GitHub and add your patches etc. Maybe someone likes to create a new unified 
version and publish it on PyPI. If you need more help on this get in contact 
with me or write to the XHTML2PDF mailing list. Thank you all very much for 
your effort!

Project on GitHub:
http://github.com/holtwick/xhtml2pdf

Original comment by dirk.holtwick on 23 Aug 2010 at 5:27

GoogleCodeExporter commented 9 years ago
Hello. I tried

import logging
class PisaNullHandler(logging.Handler):
    def emit(self, record):
        pass
    log = logging.getLogger("ho.pisa").addHandler(PisaNullHandler())

which I placed in sx/pisa3/pisa_tables.py

Now I get the error:

'NoneType' object has no attribute 'warn'

which references the line

log.warn(c.warning("<table>"), exc_info=1)

As Dirk is not longer supporting this, I am very interested in forking this and 
making sure it stays an active project. 

Original comment by gregco...@gmail.com on 6 Oct 2010 at 5:17

GoogleCodeExporter commented 9 years ago
addHandler may not be returning an object.
Try log = logging.getLogger(...)
log.addHandler(...)

Original comment by shin...@gmail.com on 6 Oct 2010 at 6:03

GoogleCodeExporter commented 9 years ago
That did it. Thanks.

Original comment by gregco...@gmail.com on 6 Oct 2010 at 8:06

GoogleCodeExporter commented 9 years ago
If that fixed the problem... could you share the final solution? And the file 
which has to be modified? Thanks.

Original comment by caum...@gmail.com on 6 Oct 2010 at 8:22

GoogleCodeExporter commented 9 years ago
I edited sx/pisa3/__init__.py

import logging

class PisaNullHandler(logging.Handler):

    def emit(self, record):

        pass

log = logging.getLogger(__name__)
log.addHandler(PisaNullHandler())

I don't think this actually fixed everything there is to fix, but at least now 
most of my reports are working. I get the above pyPDF sets deprecation error, 
but a lot of packages are giving that error these days. For development I'm on 
Django 1.2.1 pisa 3.0.33 - which is the problem child and for production, I am 
on Django 1.2.3 and pisa 3.0.32 which works perfectly.

Original comment by gregco...@gmail.com on 6 Oct 2010 at 11:50

GoogleCodeExporter commented 9 years ago
Following gregcorey's instructions in comment 11 didn't work for me. I had to 
put the code in ho/pisa/__init__.py

Like phoebebright310 I was hoping this would resolve my image issues, but alas, 
it did not.

Original comment by jaredtma...@gmail.com on 5 Nov 2010 at 6:26