RemoteLogRK
Public Member Functions | Protected Attributes
RemoteLogSyslogUDP Class Reference

Log server module for writing to a syslog server over UDP. More...

#include <RemoteLogRK.h>

Inheritance diagram for RemoteLogSyslogUDP:
RemoteLogServer

Public Member Functions

 RemoteLogSyslogUDP (size_t bufLen=256)
 Constructor. More...
 
 RemoteLogSyslogUDP (const char *hostname, uint16_t port, size_t bufLen=256)
 Constructor. More...
 
virtual ~RemoteLogSyslogUDP ()
 Destructor. More...
 
RemoteLogSyslogUDPwithHostnameAndPort (const char *hostname, uint16_t port)
 Sets the hostname and port of the UDP syslog server. More...
 
RemoteLogSyslogUDPwithDeviceNameCallback (std::function< bool(String &)> deviceNameCallback)
 Sets the callback to get the device name, used in the syslog packet. More...
 
RemoteLogSyslogUDPwithMinSendPeriodMs (unsigned long valueMs)
 Sets the minimum period between UDP sends (default: 100 milliseconds) More...
 
void loop (size_t &readIndex)
 Perform loop time operations such as reading and writing sockets.
 
- Public Member Functions inherited from RemoteLogServer
 RemoteLogServer ()
 Base class constructor. Doesn't do anything.
 
virtual ~RemoteLogServer ()
 This class is not typically deleted, because you can't unregister one.
 
virtual void setup ()
 Perform setup operations. More...
 
virtual void reset ()
 Reset is about to occur, do things like disconnect sockets. More...
 

Protected Attributes

unsigned long minSendPeriodMs = 100
 UDP send rate limit (milliseconds) More...
 
unsigned long lastSendMs = 0
 The millis value of the last send used for rate limiting.
 
String hostname
 The hostname to send to. More...
 
IPAddress remoteAddr
 The IPv4 address of the remote host.
 
uint16_t port = 0
 The UDP port to send to.
 
std::function< bool(String &)> deviceNameCallback = 0
 The function to call to find the name of this device set using withDeviceNameCallback.
 
UDP udp
 The Wiring UDP object used to send UDP data.
 
bool networkReady = false
 true if Celluar.ready() or WiFi.ready() is true
 
uint8_t * buf
 The packet buffer. Allocated in the constructor.
 
size_t bufLen
 The size of the packet buffer. Set in the constructor.
 

Additional Inherited Members

- Protected Member Functions inherited from RemoteLogServer
 RemoteLogServer (const RemoteLogServer &)=delete
 This class is not copyable.
 
RemoteLogServeroperator= (const RemoteLogServer &)=delete
 This class is not copyable.
 

Detailed Description

Log server module for writing to a syslog server over UDP.

The syslog server can be on your local network, or cloud-hosted, like Solarwinds Papertrail.

Constructor & Destructor Documentation

◆ RemoteLogSyslogUDP() [1/2]

RemoteLogSyslogUDP::RemoteLogSyslogUDP ( size_t  bufLen = 256)

Constructor.

Parameters
bufLenThe maximum UDP packet size. Default is 256. It should not be smaller than this, because the first 128 bytes of is used as temporary storage for formatting the syslog data before the actual event date is shifted in the buffer.

If you use this constructor you must set the hostname and port using

◆ RemoteLogSyslogUDP() [2/2]

RemoteLogSyslogUDP::RemoteLogSyslogUDP ( const char *  hostname,
uint16_t  port,
size_t  bufLen = 256 
)

Constructor.

Parameters
hostnameThe UDP hostname to send to.
portThe UDP port to send to.
bufLenThe maximum UDP packet size. Default is 256. It should not be smaller than this, because the first 128 bytes of is used as temporary storage for formatting the syslog data before the actual event date is shifted in the buffer.

◆ ~RemoteLogSyslogUDP()

RemoteLogSyslogUDP::~RemoteLogSyslogUDP ( )
virtual

Destructor.

This object is not typically deleted as you can't unregister a server, so deleting it would cause a dangling pointer.

Member Function Documentation

◆ withDeviceNameCallback()

RemoteLogSyslogUDP& RemoteLogSyslogUDP::withDeviceNameCallback ( std::function< bool(String &)>  deviceNameCallback)
inline

Sets the callback to get the device name, used in the syslog packet.

Parameters
deviceNameCallbackThe callback function or C++11 lambda.

The callback function or C++ lambda should have the prototype:

bool callback(String &deviceName);

The deviceName should be filled in, if known, and return true. If the device name is not yet known, then return false. This will prevent syslog messages from going out, however, so you may want to return some default value and return true instead.

◆ withHostnameAndPort()

RemoteLogSyslogUDP & RemoteLogSyslogUDP::withHostnameAndPort ( const char *  hostname,
uint16_t  port 
)

Sets the hostname and port of the UDP syslog server.

Parameters
hostnameThe UDP hostname to send to.
portThe UDP port to send to.

◆ withMinSendPeriodMs()

RemoteLogSyslogUDP& RemoteLogSyslogUDP::withMinSendPeriodMs ( unsigned long  valueMs)
inline

Sets the minimum period between UDP sends (default: 100 milliseconds)

It's possible to overload the UDP stack causing packets to be dropped. Checking the return value from UDP.sendPacket would help, however there is no good way to put the data back into the buffer after removing it.

Adding rate limiting can also help slow down transmission if runaway recursion occurs. The value could be make even higher (1000 ms) to help protect against this on cellular devices in particular.

Parameters
valueMsthe value in milliseconds to set the sendPeriodMs to.

Field Documentation

◆ hostname

String RemoteLogSyslogUDP::hostname
protected

The hostname to send to.

This is resolved by DNS once at startup, then the cached address is used. If you specify a dotted decimal IPv4 address in hostname (10.1.2.3, for example), it's parsed directly without network access.

◆ minSendPeriodMs

unsigned long RemoteLogSyslogUDP::minSendPeriodMs = 100
protected

UDP send rate limit (milliseconds)

This is a safety net to avoid sending data too quickly. Since UDP data is not acknowledged, there's no way to know if it's been discarded. This can be set to 0 for no rate limiting.


The documentation for this class was generated from the following files: