mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-02 18:59:56 +00:00
hook up additional rsyslog output if debug printing is active
This commit is contained in:
parent
d34f6d0f68
commit
090d399843
@ -92,21 +92,6 @@ bool Syslog::isEnabled()
|
|||||||
return this->_enabled;
|
return this->_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::log(uint16_t pri, const __FlashStringHelper *message)
|
|
||||||
{
|
|
||||||
return this->_sendLog(pri, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Syslog::log(uint16_t pri, const String &message)
|
|
||||||
{
|
|
||||||
return this->_sendLog(pri, message.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Syslog::log(uint16_t pri, const char *message)
|
|
||||||
{
|
|
||||||
return this->_sendLog(pri, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args)
|
bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args)
|
||||||
{
|
{
|
||||||
char *message;
|
char *message;
|
||||||
@ -132,17 +117,6 @@ bool Syslog::vlogf(uint16_t pri, const char *fmt, va_list args)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Syslog::logf(uint16_t pri, const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
bool result;
|
|
||||||
|
|
||||||
va_start(args, fmt);
|
|
||||||
result = this->vlogf(pri, fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool Syslog::_sendLog(uint16_t pri, const char *message)
|
inline bool Syslog::_sendLog(uint16_t pri, const char *message)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
@ -184,44 +158,4 @@ inline bool Syslog::_sendLog(uint16_t pri, const char *message)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Syslog::_sendLog(uint16_t pri, const __FlashStringHelper *message)
|
|
||||||
{
|
|
||||||
int result;
|
|
||||||
|
|
||||||
if (!this->_enabled)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if ((this->_server == NULL && this->_ip == INADDR_NONE) || this->_port == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Check priority against priMask values.
|
|
||||||
if ((LOG_MASK(LOG_PRI(pri)) & this->_priMask) == 0)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Set default facility if none specified.
|
|
||||||
if ((pri & LOG_FACMASK) == 0)
|
|
||||||
pri = LOG_MAKEPRI(LOG_FAC(this->_priDefault), pri);
|
|
||||||
|
|
||||||
if (this->_server != NULL) {
|
|
||||||
result = this->_client->beginPacket(this->_server, this->_port);
|
|
||||||
} else {
|
|
||||||
result = this->_client->beginPacket(this->_ip, this->_port);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != 1)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
this->_client->print('<');
|
|
||||||
this->_client->print(pri);
|
|
||||||
this->_client->print(F(">1 - "));
|
|
||||||
this->_client->print(this->_deviceHostname);
|
|
||||||
this->_client->print(' ');
|
|
||||||
this->_client->print(this->_appName);
|
|
||||||
this->_client->print(F(" - - - \xEF\xBB\xBF"));
|
|
||||||
this->_client->print(message);
|
|
||||||
this->_client->endPacket();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -132,7 +132,6 @@ class Syslog
|
|||||||
bool _enabled = false;
|
bool _enabled = false;
|
||||||
|
|
||||||
bool _sendLog(uint16_t pri, const char *message);
|
bool _sendLog(uint16_t pri, const char *message);
|
||||||
bool _sendLog(uint16_t pri, const __FlashStringHelper *message);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Syslog(UDP &client);
|
explicit Syslog(UDP &client);
|
||||||
@ -148,13 +147,7 @@ class Syslog
|
|||||||
void disable();
|
void disable();
|
||||||
bool isEnabled();
|
bool isEnabled();
|
||||||
|
|
||||||
bool log(uint16_t pri, const __FlashStringHelper *message);
|
|
||||||
bool log(uint16_t pri, const String &message);
|
|
||||||
bool log(uint16_t pri, const char *message);
|
|
||||||
|
|
||||||
bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0)));
|
bool vlogf(uint16_t pri, const char *fmt, va_list args) __attribute__((format(printf, 3, 0)));
|
||||||
|
|
||||||
bool logf(uint16_t pri, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // HAS_ETHERNET || HAS_WIFI
|
#endif // HAS_ETHERNET || HAS_WIFI
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
*/
|
*/
|
||||||
NoopPrint noopPrint;
|
NoopPrint noopPrint;
|
||||||
|
|
||||||
|
extern Syslog syslog;
|
||||||
|
|
||||||
void RedirectablePrint::setDestination(Print *_dest)
|
void RedirectablePrint::setDestination(Print *_dest)
|
||||||
{
|
{
|
||||||
assert(_dest);
|
assert(_dest);
|
||||||
@ -96,6 +98,32 @@ size_t RedirectablePrint::log(const char *logLevel, const char *format, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
r += vprintf(format, arg);
|
r += vprintf(format, arg);
|
||||||
|
|
||||||
|
// if syslog is in use, collect the log messages and send them to syslog
|
||||||
|
if (syslog.isEnabled()) {
|
||||||
|
int ll = 0;
|
||||||
|
switch (logLevel[0]) {
|
||||||
|
case 'D':
|
||||||
|
ll = SYSLOG_DEBUG;
|
||||||
|
break;
|
||||||
|
case 'I':
|
||||||
|
ll = SYSLOG_INFO;
|
||||||
|
break;
|
||||||
|
case 'W':
|
||||||
|
ll = SYSLOG_WARN;
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
ll = SYSLOG_ERR;
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
ll = SYSLOG_CRIT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ll = 0;
|
||||||
|
}
|
||||||
|
syslog.vlogf(ll, format, arg);
|
||||||
|
}
|
||||||
|
|
||||||
va_end(arg);
|
va_end(arg);
|
||||||
|
|
||||||
isContinuationMessage = !hasNewline;
|
isContinuationMessage = !hasNewline;
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include "mqtt/JSON.h"
|
#include "mqtt/JSON.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
const int reconnectMax = 5;
|
||||||
|
|
||||||
MQTT *mqtt;
|
MQTT *mqtt;
|
||||||
|
|
||||||
String statusTopic = "msh/2/stat/";
|
String statusTopic = "msh/2/stat/";
|
||||||
@ -218,15 +220,13 @@ void MQTT::reconnect()
|
|||||||
sendSubscriptions();
|
sendSubscriptions();
|
||||||
} else {
|
} else {
|
||||||
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
||||||
LOG_ERROR("Failed to contact MQTT server (%d/5)...\n", reconnectCount + 1);
|
reconnectCount++;
|
||||||
if (reconnectCount >= 4) {
|
LOG_ERROR("Failed to contact MQTT server (%d/%d)...\n", reconnectCount, reconnectMax);
|
||||||
|
if (reconnectCount >= reconnectMax) {
|
||||||
needReconnect = true;
|
needReconnect = true;
|
||||||
wifiReconnect->setIntervalFromNow(0);
|
wifiReconnect->setIntervalFromNow(0);
|
||||||
reconnectCount = 0;
|
reconnectCount = 0;
|
||||||
} else {
|
|
||||||
reconnectCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user