How to encode a log file?

My code is:

logging.warning('FASE VALIDACIÓN TITULOS DE COLUMNAS DE DATOS NO SUPERADA. compruebe los nombres de los títulos de las columnas en datos.csv)')

Output to the .log file:

WARNING:root:FASE VALIDACI N TITULOS DE COLUMNAS DE DATOS NO SUPERADA. compruebe los nombres de los t tulos de las columnas en datos.csv)

Then I tried this:

logging.basicConfig(filename=nombreFicheroLog, encoding="utf-8", level=logging.DEBUG)

But that will not work. Then I tried the following:

logging.warning(u'FASE VALIDACIÓN TITULOS DE COLUMNAS DE DATOS NO SUPERADA. compruebe los nombres de los títulos de las columnas en datos.csv)')

But the result is the same.

How can I encode a .log file to support UTF-8?

PS I am using Python3.

+4
source share
1 answer

basicConfigdoes not accept an argument encoding, but in Python 3.3 you can do this instead:

logging.basicConfig(handlers=[logging.FileHandler(nombreFicheroLog, 'w', 'utf-8')], 
                    level=logging.DEBUG)

For older Python, see this question .

+9
source

Source: https://habr.com/ru/post/1524035/


All Articles