logging of strings with broken encoding

Thomas Guettler hv at tbz-pariv.de
Thu Jul 2 11:53:14 EDT 2009


My quick fix is this:

class MyFormatter(logging.Formatter):
    def format(self, record):
        msg=logging.Formatter.format(self, record)
        if isinstance(msg, str):
            msg=msg.decode('utf8', 'replace')
        return msg

But I still think handling of non-ascii byte strings should be better.
A broken logging message is better than none.

And, if there is a UnicodeError, handleError() should not send the message
to sys.stderr, but it should use emit() of the current handler.

In my case sys.stderr gets discarded. Its very hard to debug, if you don't
see any logging messages.

  Thomas

Thomas Guettler schrieb:
> Hi,
> 
> I have bug in my code, which results in the same error has this one:
>  ...

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de



More information about the Python-list mailing list