mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-10 01:05:42 +00:00
Feature: UdpLog configurable. Fix: Avoid overflow error on big udp log messages.
This commit is contained in:
parent
8cef89595b
commit
5c82af5dad
2 changed files with 18 additions and 2 deletions
|
@ -88,4 +88,9 @@ exit_on_session_end = False
|
||||||
# Possible values:
|
# Possible values:
|
||||||
# No: No testcases are executed. Normal function as Evse or Pev.
|
# 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.
|
# 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
|
||||||
|
|
13
udplog.py
13
udplog.py
|
@ -2,6 +2,7 @@
|
||||||
# This module "prints" log messages to UDP broadcasts to port 514.
|
# This module "prints" log messages to UDP broadcasts to port 514.
|
||||||
|
|
||||||
from helpers import prettyMac
|
from helpers import prettyMac
|
||||||
|
from configmodule import getConfigValue, getConfigValueBool
|
||||||
|
|
||||||
class udplog():
|
class udplog():
|
||||||
def fillMac(self, macbytearray, position=6): # position 6 is the source MAC
|
def fillMac(self, macbytearray, position=6): # position 6 is the source MAC
|
||||||
|
@ -18,9 +19,14 @@ class udplog():
|
||||||
# Severity = 7 = "debug"
|
# Severity = 7 = "debug"
|
||||||
# print("[UDPLOG] Logging " + s)
|
# print("[UDPLOG] Logging " + s)
|
||||||
if (purpose==""):
|
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>"
|
strLevel="<15>"
|
||||||
# The String to be logged. Terminated by 00.
|
# 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"
|
strMessage=s+"\0"
|
||||||
|
|
||||||
lenPayLoad = 4 + len(strMessage) # length of level is 4
|
lenPayLoad = 4 + len(strMessage) # length of level is 4
|
||||||
|
@ -98,6 +104,11 @@ class udplog():
|
||||||
self.addressManager = addressManager
|
self.addressManager = addressManager
|
||||||
self.ownMac = self.addressManager.getLocalMacAddress()
|
self.ownMac = self.addressManager.getLocalMacAddress()
|
||||||
print("udplog started with ownMac " + prettyMac(self.ownMac))
|
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):
|
def udplog_init(transmitCallback, addressManager):
|
||||||
global udplogger
|
global udplogger
|
||||||
|
|
Loading…
Reference in a new issue