From: norbert on
Hello,

I want to send error messages with SMTPHandler logging. But
SMTPHandler does not seem to be unicode aware. Is there something
doable without playing with sys.setdefaultencoding ?

import logging,logging.handlers
smtpHandler =
logging.handlers.SMTPHandler(mailhost=("smtp.example.com",25),
fromaddr="toto(a)example.com", toaddrs="toto(a)example.com",
subject=u"error message")

LOG = logging.getLogger()
LOG.addHandler(smtpHandler)

LOG.error(u"sans accent")
LOG.error(u"accentu\u00E9")

gives : UnicodeEncodeError: 'ascii' codec can't encode character
u'\xe9' in position 117: ordinal not in range(128)

Thank you !
From: Chris Withers on
norbert wrote:
> I want to send error messages with SMTPHandler logging. But
> SMTPHandler does not seem to be unicode aware. Is there something
> doable without playing with sys.setdefaultencoding ?

try MailingLogger:

http://www.simplistix.co.uk/software/python/mailinglogger

If you have unicode problems with that, I'd be interested in fixing them!

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
From: norbert on
On 5 juil, 13:17, Chris Withers <ch...(a)simplistix.co.uk> wrote:
> try MailingLogger:
>
> If you have unicode problems with that, I'd be interested in fixing them!

Your package has the same unicode problem :
import logging,logging.handlers
from mailinglogger.MailingLogger import MailingLogger
mailingLogger = MailingLogger(mailhost=('smtp.example.com',
25),fromaddr='toto(a)example.com',toaddrs=('toto(a)example.com',))
LOG = logging.getLogger()
LOG.addHandler(mailingLogger)
LOG.error(u"sans accent")
LOG.error(u"accentu\u00E9")

--> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9'
in position 7: ordinal not in range(128)
From: Chris Withers on
norbert wrote:
> Your package has the same unicode problem :
> import logging,logging.handlers
> from mailinglogger.MailingLogger import MailingLogger
> mailingLogger = MailingLogger(mailhost=('smtp.example.com',
> 25),fromaddr='toto(a)example.com',toaddrs=('toto(a)example.com',))
> LOG = logging.getLogger()
> LOG.addHandler(mailingLogger)
> LOG.error(u"sans accent")
> LOG.error(u"accentu\u00E9")
>
> --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9'
> in position 7: ordinal not in range(128)

Interesting, I don't know what the logging framework's position is on
unicode...

What happens when you try the same logging with just a FileHandler
registered? What encoding does the log file use?

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
From: norbert on
On 5 juil, 14:32, Chris Withers <ch...(a)simplistix.co.uk> wrote:
> norbert wrote:
> > Your package has the same unicode problem :
> > import logging,logging.handlers
> > from mailinglogger.MailingLogger import MailingLogger
> > mailingLogger = MailingLogger(mailhost=('smtp.example.com',
> > 25),fromaddr='t...(a)example.com',toaddrs=('t...(a)example.com',))
> > LOG = logging.getLogger()
> > LOG.addHandler(mailingLogger)
> > LOG.error(u"sans accent")
> > LOG.error(u"accentu\u00E9")
>
> > --> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9'
> > in position 7: ordinal not in range(128)
>
> Interesting, I don't know what the logging framework's position is on
> unicode...
>
> What happens when you try the same logging with just a FileHandler
> registered? What encoding does the log file use?
>

a FileHandler works as expected, the log file being UTF-8 encoded. The
SMTPHandler is the only logger I know with this problem, maybe
connected to SMTPLib implementation ?