Usage

#include <uuid/syslog.h>

Create a uuid::syslog::SyslogService and call start(). Then set the destination host, log level and optional local hostname.

The default log level is uuid::log::Level::ALL so it can capture messages logged during startup before any configuration is read.

Call loop() regularly and when WiFi connectivity is available the queued messages will be sent.

On ESP8266 and ESP32 platforms an ARP query will be made every second until a route to the destination host is available, before sending messages at a rate of 100 per second. On other platforms messages will be sent at a rate of 10 per second to allow time for ARP lookups to complete and avoid dropping messages.

Whenever possible, the current system time is included in the outgoing syslog message.

Example

#include <Arduino.h>
#ifdef ARDUINO_ARCH_ESP8266
# include <ESP8266WiFi.h>
#else
# include <WiFi.h>
#endif
#include <uuid/common.h>
#include <uuid/log.h>
#include <uuid/syslog.h>

static uuid::syslog::SyslogService syslog;

void setup() {
	static uuid::log::Logger logger{F("setup")};

	syslog.start();
	/* Retrieve settings after calling start()
	 * in case the settings read process logs
	 * some messages.
	 */
	syslog.hostname("example");
	syslog.log_level(uuid::log::DEBUG);
	syslog.mark_interval(3600);
	syslog.destination(IPAddress(192, 0, 2, 1));

	WiFi.persistent(false);
	WiFi.mode(WIFI_STA);
	WiFi.begin("SSID", "password");

	Serial.begin(115200);

	logger.info(F("Application started"));
}

void loop() {
	static uuid::log::Logger logger{F("loop")};
	static unsigned int i = 0;

	uuid::loop();
	syslog.loop();

	logger.debug(F("Hello %u World!"), i++);

	delay(1000);
}

Output

UDP -> [192.0.2.1]:514 <46>1 - example - - - - 000+00:00:00.000 I 0: [syslog] Log level set to DEBUG
UDP -> [192.0.2.1]:514 <134>1 - example - - - - 000+00:00:00.000 I 1: [setup] Application started
UDP -> [192.0.2.1]:514 <135>1 - example - - - - 000+00:00:00.000 D 2: [loop] Hello 0 World!
UDP -> [192.0.2.1]:514 <135>1 - example - - - - 000+00:00:01.000 D 3: [loop] Hello 1 World!
UDP -> [192.0.2.1]:514 <135>1 - example - - - - 000+00:00:02.000 D 4: [loop] Hello 2 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:00.000000Z example - - - - 000+00:00:03.000 D 5: [loop] Hello 3 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:01.000000Z example - - - - 000+00:00:04.000 D 6: [loop] Hello 4 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:02.000000Z example - - - - 000+00:00:05.000 D 7: [loop] Hello 5 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:03.000000Z example - - - - 000+00:00:06.000 D 8: [loop] Hello 6 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:04.000000Z example - - - - 000+00:00:07.000 D 9: [loop] Hello 7 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:05.000000Z example - - - - 000+00:00:08.000 D 10: [loop] Hello 8 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:06.000000Z example - - - - 000+00:00:09.000 D 11: [loop] Hello 9 World!
UDP -> [192.0.2.1]:514 <135>1 2020-01-01T00:00:07.000000Z example - - - - 000+00:00:10.000 D 12: [loop] Hello 10 World!