Issues with Notification Bus and Log File Configuration in Tryton

Hi,

I’m facing a couple of issues I hope someone can help me with:

  • Notification Bus Not Working
    I have configured allow_subscribe = True in the conf file, and I am using the notify() method to send notifications. Here’s how I’m calling it:
    body = f’Label “{form.label_name}” Sample Request Created’
    notify(‘New Sample Request’, body, priority=1, user=1)

  • Logging Configuration Not Writing to Log File
    I have configured logging in my conf file as it was written in the documentation:

[logging]
allow_subscribe = True

[formatters]
keys = simple

[handlers]
keys = rotate, console

[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 = ('D:/Projects/Tryton/log', 'D', 1, 30)
formatter = simple

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

[logger_root]
level = INFO
handlers = rotate, console

Any help or guidance would be greatly appreciated!

Thank you in advance.

Hi,
Can you show which part of the documentation are you looking at?, as I understand, trytond config file and logging file are 2 different files, and the bus should be activated in the trytond.conf file, under the bus section with allow_subscribe = True.

Oh yeah sorry I mentioned allow_subscribe in the logger section in this topic but is correct in my code, it is supposed to go in the bus section, I know they are two separate things logging and notify. So starting from scratch:
For notify:

  • Added this in the conf [bus] allow_subscribe = True but notify isn’t working,
  • I’ve step debugged it, it is correctly going in the notify function in the class class LongPollingBus: , but I don’t see the notification on the client/sao. Am I missing something here?

For logging:

  • I’ve added these from the documentation
[formatters]
keys=simple

[handlers]
keys=rotate,console

[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=('D:/Projects/Tryton/log', 'D', 1, 30)
formatter=simple

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

[logger_root]
level=INFO
handlers=rotate,console

I found it here → Logging configuration — Tryton server

Apologies for mentioning this

[logging]
allow_subscribe = True

Did you start your tryton server with the logging configuration file ?

trytond -c tryton.conf --logconf yourlogconf.conf -d database

Ah I missed that bit of critical information, added this --logconf yourlogconf.conf

[Fri Jun 13 06:32:40 2025] INFO:trytond.modules:stock_package_shipping_sendcloud import
[Fri Jun 13 06:32:40 2025] INFO:trytond.modules:stock_package_shipping_ups import
[Fri Jun 13 06:32:40 2025] INFO:trytond.modules:web_shop_shopify import
[Fri Jun 13 06:32:40 2025] INFO:trytond.modules:carrier_carriage import
[Fri Jun 13 06:32:40 2025] INFO:trytond.modules:account_stock_eu import
[Fri Jun 13 06:32:40 2025] INFO:trytond.modules:carrier_subdivision import

I can see the logs now in the log file as well as in the console, but the requests (GET/POST) are missing now

Maybe you could switch to another level in your logconf.conf:

level=DEBUG

you could also start your trytond server in verbose mode:

trytond -c tryton.conf --logconf yourlogconf.conf -d database -vvv

Thank you so much! Logging works but can you guide me with the notify function? I’ve added the allow_subscribe = True in the bus section, but the notify function isn’t working.

You should check if there are in the logs request to the bus (the URL ends with bus). This means that the client subscribed to the bus.

Then when you run the server when logging on the DEBUG level you should have a log message saying something like publish "{'type': notification', …}" to 'client:whatever' on 'database'. This means that the notification was sent from your code, received by the thread listening to notifications and dispatched to the client waiting for notifications.

And on the client side you should see the notification (but I don’t recall if the notifications work with Tryton on windows as I remember that there was an issue).

Do I have to explicitly use subscribe function in my code in some setup function? Or does it work out-of-the-box and notifies if I mention user:1 it send the notification to admin.

You have to send notifications from your code indeed. The simplest is probably something like that:

from trytond.bus import notify
…
class MyCoolModel:

 @classmethod
 def write(cls, *args):
   notify("Write", "You wrote something!")
   return super().write(*args)

Of course you can put the notification anywhere you see fit.
If you don’t specify the user or the client then the code will infer the right one from the context of the Transaction.

I used the notify function like this
notify('New Sample Request', body, priority=1, user=1)
but it does not seem to work, and I do have the allow_subscribe = True in my conf

Do you have anything in the log?
(Beware that DEBUG is very verbose).

Did you check that there was a request on the bus URL?

Try first without specifying the user and the priority.

I checked the logs and I found the notify being logged

[Fri Jun 13 16:26:31 2025] DEBUG:trytond.backend.postgresql.database:b'NOTIFY "bus", \'{"channel":"user:1","message":{"type":"notification","title":"New Sample Request","body":"Label \\"Century Label\\" Sample Request Created","priority":1,"message_id":"25401bee-336f-4001-b632-6c9aaa98af78"}}\''
[Fri Jun 13 16:26:31 2025] DEBUG:trytond.bus:publish {'type': 'notification', 'title': 'New Sample Request', 'body': 'Label "Century Label" Sample Request Created', 'priority': 1, 'message_id': '25401bee-336f-4001-b632-6c9aaa98af78'} to 'user:1' on 'adihitech'

Then the issue lies probably on the client that do not show you the notification.

Which client are you using?

Are you connecting to a remote host? We had a case recently with someone using foo.local as the hostname (that resolved to 127.0.0.1) and the notification where not allowed because it was an unsecure request to a non authorized host (there is a whitelist in chrome-based browsers that allow notifications on unsecure connections to localhost and 127.0.0.x but not to names resolving to those addresses IIRC).

I’m using the latest sao client. sao-7.6
I also see invalid WSGI environment right after the logging of the notify

[Fri Jun 13 17:11:41 2025] DEBUG:trytond.bus:Bus: {'message': {'type': 'notification', 'title': 'New Sample Request', 'body': 'Label "Century Label" Sample Request Created', 'priority': 1, 'message_id': '97e03ff4-d65e-4118-b563-42bfe377c980'}, 'channel': 'user:1'}
[Fri Jun 13 17:11:41 2025] DEBUG:trytond.bus:Bus: {'message': {'type': 'notification', 'title': 'New Sample Request', 'body': 'Label "Century Label" Sample Request Created', 'priority': 1, 'message_id': '97e03ff4-d65e-4118-b563-42bfe377c980'}, 'channel': 'user:1'}
[Fri Jun 13 17:11:41 2025] INFO:trytond.wsgi:<JSONRequest 1@127.0.0.1 'http://localhost:9006/xxxxxxx/bus' [POST] (invalid WSGI environ)> in 47344 ms

It didn’t work on Chrome too.
In the dev tools console I also noticed this

An exception occured while connection to the bus. Sleeping for 1 seconds <empty string> tryton-sao.js:237:24
    _log http://localhost:9006/dist/tryton-sao.js:237
    error http://localhost:9006/dist/tryton-sao.js:250
    listen http://localhost:9006/dist/tryton-sao.js:29268
    jQuery 6
    listen http://localhost:9006/dist/tryton-sao.js:29229
    listen http://localhost:9006/dist/tryton-sao.js:29255
    jQuery 6
    listen http://localhost:9006/dist/tryton-sao.js:29229
    login http://localhost:9006/dist/tryton-sao.js:689
    jQuery 32

I tried this too, notify('New Sample Request', 'Sample Created'), still didn’t work, anyway I just wanted to see how the notification looks

Did you allow the web application to send notification? It should have asked the first time you use it but if you denied it, you must explicitly change the permission in your browser (usually a it is an icon next to the address bar).