From 2060dd96617683122e7a530c807734100b80af9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Mon, 16 Apr 2018 09:36:38 +0200 Subject: [PATCH] Initial support for syslog messaging --- code/espurna/config/general.h | 9 +++++++-- code/espurna/config/types.h | 36 +++++++++++++++++++++++++++++++++++ code/espurna/debug.ino | 14 ++++++++++++-- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 17273f29..c26533b6 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +// // //------------------------------------------------------------------------------ // Do not change this file unless you know what you are doing // Configuration settings are in the settings.h file //------------------------------------------------------------------------------ @@ -75,9 +75,14 @@ #endif #ifndef DEBUG_UDP_PORT -#define DEBUG_UDP_PORT 8113 +#define DEBUG_UDP_PORT 514 #endif +// If DEBUG_UDP_PORT is set to 514 syslog format is assumed +// (https://tools.ietf.org/html/rfc3164) +// DEBUG_UDP_FAC_PRI is the facility+priority +#define DEBUG_UDP_FAC_PRI (SYSLOG_LOCAL0 | SYSLOG_DEBUG) + //------------------------------------------------------------------------------ #ifndef DEBUG_TELNET_SUPPORT diff --git a/code/espurna/config/types.h b/code/espurna/config/types.h index 03125aef..d67a0903 100644 --- a/code/espurna/config/types.h +++ b/code/espurna/config/types.h @@ -61,6 +61,42 @@ #define RELAY_PROVIDER_RFBRIDGE 3 #define RELAY_PROVIDER_STM 4 +//------------------------------------------------------------------------------ +// UDP SYSLOG +//------------------------------------------------------------------------------ + +// Priority codes: +#define SYSLOG_EMERG 0 /* system is unusable */ +#define SYSLOG_ALERT 1 /* action must be taken immediately */ +#define SYSLOG_CRIT 2 /* critical conditions */ +#define SYSLOG_ERR 3 /* error conditions */ +#define SYSLOG_WARNING 4 /* warning conditions */ +#define SYSLOG_NOTICE 5 /* normal but significant condition */ +#define SYSLOG_INFO 6 /* informational */ +#define SYSLOG_DEBUG 7 /* debug-level messages */ + +// Facility codes: +#define SYSLOG_KERN (0<<3) /* kernel messages */ +#define SYSLOG_USER (1<<3) /* random user-level messages */ +#define SYSLOG_MAIL (2<<3) /* mail system */ +#define SYSLOG_DAEMON (3<<3) /* system daemons */ +#define SYSLOG_AUTH (4<<3) /* security/authorization messages */ +#define SYSLOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define SYSLOG_LPR (6<<3) /* line printer subsystem */ +#define SYSLOG_NEWS (7<<3) /* network news subsystem */ +#define SYSLOG_UUCP (8<<3) /* UUCP subsystem */ +#define SYSLOG_CRON (9<<3) /* clock daemon */ +#define SYSLOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ +#define SYSLOG_FTP (11<<3) /* ftp daemon */ +#define SYSLOG_LOCAL0 (16<<3) /* reserved for local use */ +#define SYSLOG_LOCAL1 (17<<3) /* reserved for local use */ +#define SYSLOG_LOCAL2 (18<<3) /* reserved for local use */ +#define SYSLOG_LOCAL3 (19<<3) /* reserved for local use */ +#define SYSLOG_LOCAL4 (20<<3) /* reserved for local use */ +#define SYSLOG_LOCAL5 (21<<3) /* reserved for local use */ +#define SYSLOG_LOCAL6 (22<<3) /* reserved for local use */ +#define SYSLOG_LOCAL7 (23<<3) /* reserved for local use */ + //------------------------------------------------------------------------------ // MQTT //------------------------------------------------------------------------------ diff --git a/code/espurna/debug.ino b/code/espurna/debug.ino index 554e3fdc..1456f0c9 100644 --- a/code/espurna/debug.ino +++ b/code/espurna/debug.ino @@ -19,6 +19,9 @@ extern "C" { #if DEBUG_UDP_SUPPORT #include WiFiUDP _udp_debug; +#if DEBUG_UDP_PORT == 514 +char _udp_header[40] = {0}; +#endif #endif void _debugSend(char * message) { @@ -42,8 +45,8 @@ void _debugSend(char * message) { if (systemCheck()) { #endif _udp_debug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); - #if DEBUG_ADD_TIMESTAMP - _udp_debug.write(timestamp); + #if DEBUG_UDP_PORT == 514 + _udp_debug.write(_udp_header); #endif _udp_debug.write(message); _udp_debug.endPacket(); @@ -132,6 +135,13 @@ void debugSetup() { } }); + #if DEBUG_UDP_SUPPORT + #if DEBUG_UDP_PORT == 514 + snprintf_P(_udp_header, sizeof(_udp_header), PSTR("<%u>%s ESPurna[0]: "), DEBUG_UDP_FAC_PRI, getSetting("hostname").c_str()); + #endif + #endif + + } #endif // DEBUG_WEB_SUPPORT