More debug logging in weewx version 4

57 views
Skip to first unread message

Lucas Heijst

unread,
Mar 14, 2020, 12:34:41 PM3/14/20
to weewx-development
Tom,

I have written a weewx device driver which collects data from a modbus energy meter.

=======
from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.compat import iteritems
from collections import OrderedDict

from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadDecoder
from pymodbus.payload import BinaryPayloadBuilder
from pymodbus.compat import iteritems
from collections import OrderedDict
=======


In version 3.9.2 I got only weewx debug messages in the syslog file when debug was set to 1.

In version 4.0.0b14 I also get the pymodbus logging, see snippet below. 
This logging is HUGE: 20,500 lines per minute!!

====================
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: Running transaction 2184
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: SEND: 0x1 0x4 0x0 0x52 0x0 0x2 0xd0 0x1a
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.framer.rtu_framer: Changing state to IDLE - Last Frame End - 1584184619.972779, Current Time stamp - 1584184620.01192
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.client.sync: New Transaction state 'SENDING'
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: Changing transaction state from 'SENDING' to 'WAITING FOR REPLY'
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: Changing transaction state from 'WAITING FOR REPLY' to 'PROCESSING REPLY'
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: RECV: 0x1 0x4 0x4 0x47 0x12 0xdc 0xa6 0x97 0x8f
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.framer.rtu_framer: Getting Frame - 0x4 0x4 0x47 0x12 0xdc 0xa6
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.factory: Factory Response[ReadInputRegistersResponse: 4]
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.framer.rtu_framer: Frame advanced, resetting header!!
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: Adding transaction 1
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: Getting transaction 1
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.transaction: Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE'
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.payload: [18194, 56486]
Mar 14 08:17:00 pi31 mben[1835] DEBUG pymodbus.payload: [b'G\x12', b'\xdc\xa6']
Mar 14 08:17:00 pi31 
====================

As a workaround I have set the folowing line in file/etc/rsyslog.conf.

:msg, contains, "DEBUG pymodbus" stop


which suppresses the log lines in the syslog file.


But I wonder: is there a better way?


Luc

Thomas Keffer

unread,
Mar 14, 2020, 12:59:17 PM3/14/20
to weewx-development
Yes. Two methods come to mind:

1. You can suppress the debug messages in the driver. See Throttling logging events.

2. Or, you can add a [Logging] section to weewx.conf to do the same.

[Logging]
  [[loggers]]
    [[[weewx.drivers.pymodbus]]]
      level = INFO

Once we get the hang of it, I think we'll find the Python logging module much more flexible. See the white paper Weewx V4 and logging for details.

-tk


--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-development/fcd18609-1408-4d4d-b93c-ae2d410e101e%40googlegroups.com.

Vince Skahan

unread,
Mar 14, 2020, 2:17:52 PM3/14/20
to weewx-development
Tom - I updated the driver I'm fiddling with per your wiki, and noticed that there's no backward compatibility example for the "In main programs" example at the top of the wiki page. Does this look right as a potential addition to the wiki ?

Tests out ok on python3 / weewx4 FWIW....

if __name__ == "__main__":
    usage = """%prog [options] [--help]"""

    def main():
        try:
            import logging
            import weeutil.logger
            log = logging.getLogger(__name__)
            weeutil.logger.setup('mydrivername', {} )
        except:
            import syslog
            syslog.openlog('mydrivername', syslog.LOG_PID | syslog.LOG_CONS)


 

Thomas Keffer

unread,
Mar 14, 2020, 2:33:25 PM3/14/20
to Vince Skahan, weewx-development
Yes, that will work (although the exception should be limited to just catching ImportError).

Or, just use old-style "syslog" logging. It will work fine, but you'll get a mix of new- and old-style logging formats.

-tk



--
You received this message because you are subscribed to the Google Groups "weewx-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-developm...@googlegroups.com.

Lucas Heijst

unread,
Mar 14, 2020, 4:51:03 PM3/14/20
to weewx-development
Thanks Tom,

The second option won't work for me, because I do want weewx debug messages printed, but not those of the modbus data collecting section.
So, the following won't ,work for me:
Adding in weewx.conf:

======
[Logging]
  [[loggers]]
    [[[user.modbusenergy]]]
      level = INFO
======

The first option worked like a charm!

=====
    ...
    # Temporarily disable logging for events at or below DEBUG
    logging.disable(logging.DEBUG)

    # collect the modbus data
    ...

    # Remove the temporary restriction
    logging.disable(logging.NOTSET)

    # let weewx handle the modbus data
    ...
=====

Luc
Reply all
Reply to author
Forward
0 new messages