mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Fix syslog messages #285
This commit is contained in:
parent
80b9f0641a
commit
f28d99d8e3
@ -383,9 +383,6 @@ static void debugPrintLvglMemory(int level, Print* _logOutput)
|
|||||||
|
|
||||||
static void debugPrintPriority(int level, Print* _logOutput)
|
static void debugPrintPriority(int level, Print* _logOutput)
|
||||||
{
|
{
|
||||||
// if(_logOutput == &syslogClient) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
switch(level) {
|
switch(level) {
|
||||||
case LOG_LEVEL_FATAL ... LOG_LEVEL_ERROR:
|
case LOG_LEVEL_FATAL ... LOG_LEVEL_ERROR:
|
||||||
debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput);
|
debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput);
|
||||||
@ -414,35 +411,12 @@ static void debugPrintPriority(int level, Print* _logOutput)
|
|||||||
void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput)
|
void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput)
|
||||||
{
|
{
|
||||||
char buffer[10];
|
char buffer[10];
|
||||||
|
debug_get_tag(tag, buffer);
|
||||||
|
|
||||||
#if 0 && HASP_USE_SYSLOG > 0
|
#if HASP_USE_SYSLOG > 0
|
||||||
|
if(debugSyslogPrefix(tag, level, _logOutput, buffer)) {
|
||||||
if(_logOutput == syslogClient && syslogClient) {
|
debugPrintHaspMemory(level, _logOutput);
|
||||||
if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) {
|
debugPrintLvglMemory(level, _logOutput);
|
||||||
|
|
||||||
// IETF Doc: https://tools.ietf.org/html/rfc5424 - The Syslog Protocol
|
|
||||||
// BSD Doc: https://tools.ietf.org/html/rfc3164 - The BSD syslog Protocol
|
|
||||||
|
|
||||||
syslogClient->print(F("<"));
|
|
||||||
syslogClient->print((16 + debugSyslogFacility) * 8 + level);
|
|
||||||
syslogClient->print(F(">"));
|
|
||||||
|
|
||||||
if(debugSyslogProtocol == SYSLOG_PROTO_IETF) {
|
|
||||||
syslogClient->print(F("1 - "));
|
|
||||||
}
|
|
||||||
|
|
||||||
debug_get_tag(tag, buffer);
|
|
||||||
syslogClient->print(F("%s %s"), haspDevice.get_hostname(), buffer);
|
|
||||||
|
|
||||||
if(debugSyslogProtocol == SYSLOG_PROTO_IETF) {
|
|
||||||
syslogClient->print(F(" - - - \xEF\xBB\xBF")); // include UTF-8 BOM
|
|
||||||
} else {
|
|
||||||
syslogClient->print(F(": "));
|
|
||||||
}
|
|
||||||
|
|
||||||
debugPrintHaspMemory(level, _logOutput);
|
|
||||||
debugPrintLvglMemory(level, _logOutput);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif // HASP_USE_SYSLOG
|
#endif // HASP_USE_SYSLOG
|
||||||
@ -460,7 +434,6 @@ void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput)
|
|||||||
debugPrintPriority(level, _logOutput);
|
debugPrintPriority(level, _logOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_get_tag(tag, buffer);
|
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
_logOutput->printf(PSTR(" %s: "), buffer);
|
_logOutput->printf(PSTR(" %s: "), buffer);
|
||||||
#else
|
#else
|
||||||
|
@ -143,6 +143,7 @@ void debugStop(void);
|
|||||||
void debugPrintHaspHeader(Print* output);
|
void debugPrintHaspHeader(Print* output);
|
||||||
void debugPrintTag(uint8_t tag, Print* _logOutput);
|
void debugPrintTag(uint8_t tag, Print* _logOutput);
|
||||||
void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput);
|
void debugPrintPrefix(uint8_t tag, int level, Print* _logOutput);
|
||||||
|
bool debugSyslogPrefix(uint8_t tag, int level, Print* _logOutput, const char* processname);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ uint8_t debugSyslogFacility = 0;
|
|||||||
uint8_t debugSyslogProtocol = 0;
|
uint8_t debugSyslogProtocol = 0;
|
||||||
|
|
||||||
// A UDP instance to let us send and receive packets over UDP
|
// A UDP instance to let us send and receive packets over UDP
|
||||||
WiFiUDP* syslogClient;
|
WiFiUDP* syslogClient = NULL;
|
||||||
#define SYSLOG_PROTO_IETF 0
|
#define SYSLOG_PROTO_IETF 0
|
||||||
|
|
||||||
// Create a new syslog instance with LOG_KERN facility
|
// Create a new syslog instance with LOG_KERN facility
|
||||||
@ -268,10 +268,62 @@ void debugGetHistoryLine(size_t num)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool debugSyslogPrefix(uint8_t tag, int level, Print* _logOutput, const char* processname)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if HASP_USE_SYSLOG > 0
|
||||||
|
|
||||||
|
if(syslogClient && _logOutput == syslogClient) {
|
||||||
|
if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) {
|
||||||
|
|
||||||
|
// IETF Doc: https://tools.ietf.org/html/rfc5424 - The Syslog Protocol
|
||||||
|
// BSD Doc: https://tools.ietf.org/html/rfc3164 - The BSD syslog Protocol
|
||||||
|
char buffer[32 + STR_LEN_HOSTNAME];
|
||||||
|
int len;
|
||||||
|
uint priority = (16 + debugSyslogFacility) * 8 + level;
|
||||||
|
|
||||||
|
if(debugSyslogProtocol == SYSLOG_PROTO_IETF) {
|
||||||
|
len = snprintf_P(buffer, sizeof(buffer), PSTR("<%d>1 - %s %s - - \xEF\xBB\xBF"), priority,
|
||||||
|
haspDevice.get_hostname(), processname);
|
||||||
|
} else {
|
||||||
|
len = snprintf_P(buffer, sizeof(buffer), PSTR("<%d>%s %s: "), priority, haspDevice.get_hostname(),
|
||||||
|
processname);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(len > 0) syslogClient->write((uint8_t*)buffer, len);
|
||||||
|
|
||||||
|
// syslogClient->print(F("<"));
|
||||||
|
// syslogClient->print((16 + debugSyslogFacility) * 8 + level);
|
||||||
|
// syslogClient->print(F(">"));
|
||||||
|
|
||||||
|
// if(debugSyslogProtocol == SYSLOG_PROTO_IETF) {
|
||||||
|
// syslogClient->print(F("1 - "));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // debug_get_tag(tag, buffer);
|
||||||
|
// char buffer[10];
|
||||||
|
// syslogClient->print(F("%s %s"), haspDevice.get_hostname(), buffer);
|
||||||
|
|
||||||
|
// if(debugSyslogProtocol == SYSLOG_PROTO_IETF) {
|
||||||
|
// syslogClient->print(F(" - - - \xEF\xBB\xBF")); // include UTF-8 BOM
|
||||||
|
// } else {
|
||||||
|
// syslogClient->print(F(": "));
|
||||||
|
// }
|
||||||
|
|
||||||
|
// debugPrintHaspMemory(level, _logOutput);
|
||||||
|
// debugPrintLvglMemory(level, _logOutput);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif // HASP_USE_SYSLOG
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput)
|
void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput)
|
||||||
{
|
{
|
||||||
#if HASP_USE_SYSLOG > 0
|
#if HASP_USE_SYSLOG > 0
|
||||||
if(_logOutput == syslogClient && syslogClient) {
|
if(syslogClient && _logOutput == syslogClient) {
|
||||||
syslogClient->endPacket();
|
syslogClient->endPacket();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user