Logging of Unicode characters in Tryton 5.0


(Victor) #1

Hi!
We have an application developed using Tryton 4.6.
Recently we tried it in Tryton 5.0 and discovered strange logging behavior.
Namely, strings that contain Unicode characters simply disappear in logs.
But there are no any error messages, these strings disappear “silently”.

For example, such string gets into the log:
logger.info('mama')

But such string does not get into the log:
logger.info('мама') # u'\u043c\u0430\u043c\u0430'

Unicode strings were logging normally in Tryton 4.6 + Python 2.7 environment.
There is no problem with logging of these strings in Python 3.6 without Tryton.
Why are Unicode strings not logging in Tryton 5.0 + Python 3.6 environment?

Thank you.


(Cédric Krier) #2

I tested using your example as login and I can see the logging ERROR trytond.security login failed for 'мама' from '127.0.0.1' on database 'trunk'.
I guess it is the console that does not support the encoding. Did you try to store logs in a file?


(Victor) #3

We use exactly the files for logs (info.log, debug.log, warning.log, error.log, critical.log).
If you run the logger.info() commands listed in our message, then only the result of the first command logger.info('mama') gets into file ‘info.log’:

Wed Feb 06 15:46:49 2019] INFO:trytond.modules.staff.staff_num:mama

But for some reason the result of the second command logger.info('мама') does not get into file ‘info.log’. However, no error message is displayed.


(Cédric Krier) #4

Could you provide the logger configuration?


(Victor) #5

trytond.logconf

[formatters]
keys = simple

[formatter_simple]
format = %(asctime)s] %(levelname)s:%(name)s:%(message)s
datefmt = %a %b %d %H:%M:%S %Y

[loggers]
keys = root

[logger_root]
level = NOTSET
handlers = debug,info,warning,error,critical

[handlers]
keys = debug,info,warning,error,critical

[handler_debug]
class=handlers.TimedRotatingFileHandler
formatter = simple
args = ('/usr/local/lib/python3.6/site-packages/trytond/logs/debug.log', 'midnight', 1, 5)
level = DEBUG

[handler_info]
class = handlers.TimedRotatingFileHandler
formatter = simple
args = ('/usr/local/lib/python3.6/site-packages/trytond/logs/info.log', 'midnight', 1, 5)
level = INFO

[handler_warning]
class=handlers.RotatingFileHandler
formatter = simple
args = ('/usr/local/lib/python3.6/site-packages/trytond/logs/warning.log', 'a', 1048576, 3)
level = WARNING

[handler_error]
class=handlers.RotatingFileHandler
formatter = simple
args = ('/usr/local/lib/python3.6/site-packages/trytond/logs/error.log', 'a', 1048576, 3)
level = ERROR

[handler_critical]
class=handlers.RotatingFileHandler
formatter = simple
args = ('/usr/local/lib/python3.6/site-packages/trytond/logs/critical.log', 'a', 1048576, 3)
level = CRITICAL

(Cédric Krier) #6

It seems to be a python3.6 behavior: https://stackoverflow.com/a/50223407/687601


(Victor) #7

I have just run the test (in Python 3.6 without Tryton):

import logging

logging.basicConfig(filename="info.log", level=logging.INFO)

logger = logging.getLogger(__name__)

logger.info('mama')
logger.info('мама')

And I have got the file “info.log”:

INFO:__main__:mama
INFO:__main__:мама

(Victor) #8

We have solved the problem by adding ‘utf-8’ parameter to the logger configuration.
For example:
args = ('/usr/local/lib/python3.6/site-packages/trytond/logs/info.log', 'midnight', 1, 5, 'utf-8')

@ced Thanks a lot for the useful discussion.

But the question remains:
Why are Unicode strings logging normally in Python 3.6 without Tryton, but they are not logging in Python 3.6 + Tryton 5.0 environment (without parameter ‘utf-8’)?