Hello,<div><br></div><div>I am trying to write a UDP based logging server.  </div><div><br></div><div>Generically speaking it looks somewhat like syslog except I needed a bit more flexibility that syslog can provide (or at least that I think it can provide).</div>
<div><br></div><div>What I&#39;m trying to accomplish is:</div><div>-- receive UDP packet </div><div>-- parse UDP packet</div><div>-- write output to a log file</div><div>-- have the log files rotated on a periodic basis</div>
<div><br></div><div>So far I have a &quot;working&quot; implementation ... but I&#39;m noticing that if I do the following:</div><div>-- log when a message is received</div><div>-- that for that message it &quot;might&quot; show up in the file a pretty lengthy period of time later</div>
<div><br></div><div>The actual UDP protocol:</div><div><br></div><div><div>class VocsLogger(DatagramProtocol):</div><div>    def datagramReceived(self, data, (host, port)):</div><div>        _proc_msg(self.transport, data, (host, port))._new_msg().addCallback(handler)</div>
</div><div><br></div><div>The _proc_msg class:</div><div><br></div><div><div>class _proc_msg:</div><div>    def __init__(self, sck, data, (host, port)):</div><div>        self._sck = sck</div><div>        self._data = data</div>
<div>        self._host = host</div><div>        self._port = port</div><div><br></div><div>    def _new_msg(self):</div><div>        d, _ = LogMsg().ParseSocketMsg(self._data)</div><div>        if d.type.upper() == DISKINFO[0]:</div>
<div>            DISKINFO[1].write(d.ToString() + &quot;\n%s\n&quot; % (LOG_DELIM))</div><div>        elif d.type.upper() == LOADAVG[0]:</div><div>            LOADAVG[1].write(d.ToString() + &quot;\n%s\n&quot; % (LOG_DELIM))</div>
<div>        elif d.type.upper() == MEMINFO[0]:</div><div>            MEMINFO[1].write(d.ToString() + &quot;\n%s\n&quot; % (LOG_DELIM))</div><div>        elif d.type.upper() == NETDEV[0]:</div><div>            NETDEV[1].write(d.ToString() + &quot;\n%s\n&quot; % (LOG_DELIM))</div>
<div>        elif d.type.upper() == PSAUX[0]:</div><div>            PSAUX[1].write(d.ToString() + &quot;\n%s\n&quot; % (LOG_DELIM))</div><div>        elif d.type.upper() == WHOINFO[0]:</div><div>            WHOINFO[1].write(d.ToString() + &quot;\n%s\n&quot; % (LOG_DELIM)) </div>
<div>        else:</div><div>            DEFAULT[1].write(d.ToString() + &quot;\n%s\n&quot; % (LOG_DELIM))</div></div><div><br></div><div>And I have a log rotate service that looks like this:</div><div><br></div><div><div>
class LogRotateService(TimerService):</div><div>    def __init__(self):</div><div>        TimerService.__init__(self, 60 * 5, LogRotate)</div></div><div><br></div><div>And then I&#39;m using twistd to actually make it work:</div>
<div><br></div><div><div>LogRotate()</div><div>application = service.Application(&quot;vocs-logger&quot;)</div><div>rotateLogService = LogRotateService()</div><div>rotateLogService.setServiceParent(application)</div><div>
loggerService = internet.UDPServer(int(config[&#39;port&#39;]), VocsLogger(), interface=config[&#39;host&#39;])</div><div>loggerService.setServiceParent(application)</div></div><div><br></div><div><br></div><div>I&#39;m probably approaching this the wrong way and not sure if I sure really worry about deferring the actual process of writing to the log file or if there was a better way altogether.</div>
<div><br></div><div>Thanks for any guidance.</div><div><br></div><div>SDR</div>