No logging for trytond cron

I found that for the cron job, it do not read the logging configuration file.
I had set the using rotate and sentry as handler. However, it do not log neither File or sentry, but it is still shown in the console.

May I know is it correct?

trytond-cron has a --logconf option which is handle the same way as for other programs.

I used --logconf but if neither write to file or sentry.

below is my configuration, is it anything wrong?

[formatters]
keys=simple,color

[handlers]
keys=console,rotate,sentry

[loggers]
keys=root

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

[handler_rotate]
class=handlers.TimedRotatingFileHandler
args=('/var/lib/trytond/logs/trytond.log', 'D', 1, 30)
formatter=simple

[handler_console]
class=StreamHandler
formatter=color
args=(sys.stdout,)

[formatter_color]
class=colorlog.ColoredFormatter
format=%(fg_thin_cyan)s[%(asctime)s] %(log_color)s%(levelname)s%(reset)s:%(fg_bold_purple)s%(name)s:%(fg_thin_white)s%(message)s
datefmt=%m-%d %H:%M:%S

[logger_root]
level=DEBUG
handlers=console,rotate
propagate=False

[handler_sentry]
level=ERROR
class=sentry_tryton.SentryTrytonHandler
args=('http://c2572865bb714e8aa776d9d408f59dc8@172.18.0.16:9000/2', 'An error have been occurred.\nOur support team have been reported.', 'Use "{event_id}" to reference this error.',)

Maybe there is nothing to write.

No, there something to write. Because i testing using

def test():
    G = 1/0

If i run at scheduler “run once”, it does log the error.

IMHO I think you need to create a separate file for logging trytond-cron from that of the Trytond server; for example trytond_cron.log and trytond.log. If you use the same log file which may be defined by the same logconf file used in trytond, then the first process may block write access to the log file (the Trytond server) from the other processes (trytond-cron).

Another thing to note is the priority of the handlers in your config. You want to send the output to the log file first before to the console. Then you should put

[handlers]
keys=rotate,console,sentry

The other thing to check is whether you gave write access to the user running trytond-cron to the file /var/lib/trytond/logs/trytond.log

Last, it is advised not to set the root logger at DEBUG level, since it will produce a lot of debug information, specially all the SQL statements. You may want to create an additional logger to print debug information just from a specific module or classes you are interested. For example:

[logger_root]
level=ERROR
handlers=rotate

[logger_product]
level=DEBUG
handlers=rotate
propagate=0
qualname=trytond.modules.product

[logger_sale]
level=DEBUG
handlers=rotate
propagate=0
qualname=trytond.modules.sale

I hope this helps.

1 Like