An Arduino library for logging to Syslog server via UDP
protocol in
IETF (RFC 5424) and BSD (RFC 3164) message format
How to use, see examples.
This is a fork of brokentoaster/Syslog which was forked from arcao/Syslog. It was forked to:
- Fix crash due serial print debug messages (added trough brokentoaster/Syslog)
- Add a simple cache for messages while esp is offline. When online again it sends all the messages. (the implementation is really bad but works for me) Because for this cache mechanism the SPIFFS is needed. This is not supported by all platforms but by esp8266. Furthermore there is no generic interface to write to a file regardless of SD or SPIFFS.
I have tested with a syslog server from a docker image:
docker run -dit --restart unless-stopped -e SYSLOG_USERNAME=admin -e SYSLOG_PASSWORD=1234 -p 65500:80 -p 65501:514/udp pbertera/syslogserver
65501
is the syslog port and 65500
is a webclient to view the syslog.
So in the code set
#define SYSLOG_SERVER "example.com"
#define SYSLOG_PORT 65501
To check if there is a internet connection the syslog server is connected on port 80. Or if no server-url (but IP) provided google.com is used. It checks connection status for each message currently.
- Supports original Syslog severity level and facility constants
- Supports both Syslog messge formats: IETF (RFC 5424) and BSD (RFC 3164)
- Supports
printf
-like formatting vialogf
methods (usevsnprintf
method inside) - Supports fluent interface, see AdvancedLogging example
- Allows to ignore sending specified severity levels with
logMask
function, see AdvancedLogging example - Independent on underlying network hardware. The network hardware library has
to implement methods of
UDP
astract class only.
The library uses the Arduino UDP Network API (UDP
class) for interacting with
the underlying network hardware. This means it Just Works with a growing number
of boards and shields, including:
- ESP8266 / ESP32
Arduino EthernetArduino Ethernet ShieldArduino YUN – use the includedBridgeUDP
in place ofEthernetUDP
, andbe sure to call aBridge.begin()
firstArduino WiFi ShieldIntel Galileo/EdisonArduino/Genuino MKR1000Arduino module RTL00(RTL8710AF), F11AMIM13 (RTL8711AM)... you tell me!
This library supports both Syslog message formats IETF (RFC 5424) and
BSD (RFC 3164). The newer IETF format is used by default. If you want to use
older "obsolete" BSD format, just specify it with SYSLOG_PROTO_BSD
constant
in a last constructor parameter.
Syslog syslog(udpClient, host, port, device_hostname, app_name, default_priority, SYSLOG_PROTO_BSD);
// or
Syslog syslog(udpClient, ip, port, device_hostname, app_name, default_priority, SYSLOG_PROTO_BSD);
// or
Syslog syslog(udpClient, SYSLOG_PROTO_BSD);
- This library is sending empty timestamp in the syslog messages. For IETF
format it is
NILVALUE
(char-
) inTIMESTAMP
field, for BSD format theTIMESTAMP
field is completely ommited. Syslog server should use a time of receiving message in this case. It is OK in most cases. This issue will be fixed in some of the next releases.