Browse Source

debug: use rfc5424 format when adding syslog header (#2315)

mcspr-patch-1
Max Prokhorov 4 years ago
committed by GitHub
parent
commit
1df4a1aaa2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 14 deletions
  1. +31
    -14
      code/espurna/debug.cpp

+ 31
- 14
code/espurna/debug.cpp View File

@ -22,20 +22,19 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#if DEBUG_UDP_SUPPORT #if DEBUG_UDP_SUPPORT
#include <WiFiUdp.h> #include <WiFiUdp.h>
WiFiUDP _udp_debug; WiFiUDP _udp_debug;
#if DEBUG_UDP_PORT == 514
char _udp_syslog_header[40] = {0};
#endif
constexpr bool _udp_syslog_enabled = (514 == DEBUG_UDP_PORT);
char _udp_syslog_header[64];
#endif #endif
bool _debug_enabled = false; bool _debug_enabled = false;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// printf-like debug methods // printf-like debug methods
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
constexpr const int DEBUG_SEND_STRING_BUFFER_SIZE = 128;
constexpr int DEBUG_SEND_STRING_BUFFER_SIZE = 128;
void _debugSendInternal(const char * message, bool add_timestamp = DEBUG_ADD_TIMESTAMP); void _debugSendInternal(const char * message, bool add_timestamp = DEBUG_ADD_TIMESTAMP);
@ -192,9 +191,9 @@ void _debugSendInternal(const char * message, bool add_timestamp) {
if (systemCheck()) { if (systemCheck()) {
#endif #endif
_udp_debug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); _udp_debug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
#if DEBUG_UDP_PORT == 514
if (_udp_syslog_enabled) {
_udp_debug.write(_udp_syslog_header); _udp_debug.write(_udp_syslog_header);
#endif
}
_udp_debug.write(message); _udp_debug.write(message);
pause = _udp_debug.endPacket() > 0; pause = _udp_debug.endPacket() > 0;
#if SYSTEM_CHECK_ENABLED #if SYSTEM_CHECK_ENABLED
@ -245,16 +244,27 @@ void debugWebSetup() {
.onVisible([](JsonObject& root) { root["dbgVisible"] = 1; }) .onVisible([](JsonObject& root) { root["dbgVisible"] = 1; })
.onAction(_debugWebSocketOnAction); .onAction(_debugWebSocketOnAction);
// TODO: if hostname string changes, need to update header too
#if DEBUG_UDP_SUPPORT
#if DEBUG_UDP_PORT == 514
snprintf_P(_udp_syslog_header, sizeof(_udp_syslog_header), PSTR("<%u>%s ESPurna[0]: "), DEBUG_UDP_FAC_PRI, getSetting("hostname").c_str());
#endif
#endif
}
#endif // DEBUG_WEB_SUPPOR
#if DEBUG_UDP_SUPPORT
// We use the syslog header as defined in RFC5424 (The Syslog Protocol), ref:
// - https://tools.ietf.org/html/rfc5424
// - https://github.com/xoseperez/espurna/issues/2312/
void debugUdpSyslogConfigure() {
snprintf_P(
_udp_syslog_header, sizeof(_udp_syslog_header),
PSTR("<%u>1 - %s ESPurna - - - "), DEBUG_UDP_FAC_PRI,
getSetting("hostname", getIdentifier()).c_str()
);
} }
#endif // DEBUG_WEB_SUPPORT
#endif // DEBUG_UDP_SUPPORT
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -264,6 +274,13 @@ void debugSetup() {
DEBUG_PORT.begin(SERIAL_BAUDRATE); DEBUG_PORT.begin(SERIAL_BAUDRATE);
#endif #endif
#if DEBUG_UDP_SUPPORT
if (_udp_syslog_enabled) {
debugUdpSyslogConfigure();
espurnaRegisterReload(debugUdpSyslogConfigure);
}
#endif
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
#if DEBUG_LOG_BUFFER_SUPPORT #if DEBUG_LOG_BUFFER_SUPPORT


Loading…
Cancel
Save