From 5c82af5dad000b203d6ee2c17112e84c9b081172 Mon Sep 17 00:00:00 2001 From: uhi22 Date: Wed, 24 May 2023 21:05:41 +0200 Subject: [PATCH] Feature: UdpLog configurable. Fix: Avoid overflow error on big udp log messages. --- doc/pyPlc.ini.template | 7 ++++++- udplog.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/pyPlc.ini.template b/doc/pyPlc.ini.template index 5c981cd..a9e6fb9 100644 --- a/doc/pyPlc.ini.template +++ b/doc/pyPlc.ini.template @@ -88,4 +88,9 @@ exit_on_session_end = False # Possible values: # No: No testcases are executed. Normal function as Evse or Pev. # Yes: Testcases are executed. The EvseMode will produce various errors for fault injection tests. -testsuite_enable = Yes +testsuite_enable = No + +# Logging to UDP Syslog messages +# If this is activated, the pyPlc will send all logging messages also to the network interface, +# in form of UDP Syslog messages. For details see in udplog.py. +udp_syslog_enable = Yes diff --git a/udplog.py b/udplog.py index 67e2cf1..1615e43 100755 --- a/udplog.py +++ b/udplog.py @@ -2,6 +2,7 @@ # This module "prints" log messages to UDP broadcasts to port 514. from helpers import prettyMac +from configmodule import getConfigValue, getConfigValueBool class udplog(): def fillMac(self, macbytearray, position=6): # position 6 is the source MAC @@ -18,9 +19,14 @@ class udplog(): # Severity = 7 = "debug" # print("[UDPLOG] Logging " + s) if (purpose==""): - return # here we filter, which kind of infos we want to provide to the UDP logging. + if (not self.isUpdSyslogEnabled): + # If no special purpose, and the logging is disabled, we stop here. + return + # Logging is not suppressed, so continue to construct the message: strLevel="<15>" # The String to be logged. Terminated by 00. + if (len(s)>700): + s = s[0:700] # Limit the length. Too long messages crash the transmit. Todo: Find out the real limit. strMessage=s+"\0" lenPayLoad = 4 + len(strMessage) # length of level is 4 @@ -98,6 +104,11 @@ class udplog(): self.addressManager = addressManager self.ownMac = self.addressManager.getLocalMacAddress() print("udplog started with ownMac " + prettyMac(self.ownMac)) + self.isUpdSyslogEnabled = getConfigValueBool("udp_syslog_enable") + if (self.isUpdSyslogEnabled): + print("logging to UDP Syslog is enabled") + else: + print("logging to UDP Syslog is disabled") def udplog_init(transmitCallback, addressManager): global udplogger