mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
syslog replacing event log - https://github.com/proddy/EMS-ESP/issues/242
This commit is contained in:
@@ -46,7 +46,7 @@ MyESP::MyESP() {
|
|||||||
_ota_post_callback_f = nullptr;
|
_ota_post_callback_f = nullptr;
|
||||||
_load_average = 100; // calculated load average
|
_load_average = 100; // calculated load average
|
||||||
_general_serial = true; // serial is set to on as default
|
_general_serial = true; // serial is set to on as default
|
||||||
_general_log_events = true; // all logs are sent to syslog
|
_general_log_events = false; // all logs are not sent to syslog by default
|
||||||
_general_log_ip = nullptr;
|
_general_log_ip = nullptr;
|
||||||
_have_ntp_time = false;
|
_have_ntp_time = false;
|
||||||
|
|
||||||
@@ -1729,7 +1729,7 @@ bool MyESP::_fs_loadConfig() {
|
|||||||
_general_password = strdup(general["password"] | MYESP_HTTP_PASSWORD);
|
_general_password = strdup(general["password"] | MYESP_HTTP_PASSWORD);
|
||||||
_ws->setAuthentication("admin", _general_password);
|
_ws->setAuthentication("admin", _general_password);
|
||||||
_general_hostname = strdup(general["hostname"]);
|
_general_hostname = strdup(general["hostname"]);
|
||||||
_general_log_events = general["log_events"];
|
_general_log_events = general["log_events"] | false;
|
||||||
_general_log_ip = strdup(general["log_ip"] | "");
|
_general_log_ip = strdup(general["log_ip"] | "");
|
||||||
|
|
||||||
// serial is only on when booting
|
// serial is only on when booting
|
||||||
@@ -1880,7 +1880,7 @@ bool MyESP::fs_saveCustomConfig(JsonObject root) {
|
|||||||
configFile.close();
|
configFile.close();
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
_writeLogEvent(MYESP_SYSLOG_INFO, "Custom config stored in the SPIFFS");
|
writeLogEvent(MYESP_SYSLOG_INFO, "Custom config stored in the SPIFFS");
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1913,7 +1913,7 @@ bool MyESP::fs_saveConfig(JsonObject root) {
|
|||||||
configFile.close();
|
configFile.close();
|
||||||
|
|
||||||
if (n) {
|
if (n) {
|
||||||
_writeLogEvent(MYESP_SYSLOG_INFO, "System config stored in the SPIFFS");
|
writeLogEvent(MYESP_SYSLOG_INFO, "System config stored in the SPIFFS");
|
||||||
ok = true;
|
ok = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2257,7 +2257,7 @@ void MyESP::crashInfo() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// write a log entry to SysLog via UDP
|
// write a log entry to SysLog via UDP
|
||||||
void MyESP::_writeLogEvent(const uint8_t type, const char * msg) {
|
void MyESP::writeLogEvent(const uint8_t type, const char * msg) {
|
||||||
if (!_general_log_events) {
|
if (!_general_log_events) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2781,7 +2781,7 @@ void MyESP::_bootupSequence() {
|
|||||||
if (boot_status == MYESP_BOOTSTATUS_BOOTED) {
|
if (boot_status == MYESP_BOOTSTATUS_BOOTED) {
|
||||||
if ((_ntp_enabled) && (now() > 10000) && !_have_ntp_time) {
|
if ((_ntp_enabled) && (now() > 10000) && !_have_ntp_time) {
|
||||||
_have_ntp_time = true;
|
_have_ntp_time = true;
|
||||||
_writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
|
writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2811,7 +2811,7 @@ void MyESP::_bootupSequence() {
|
|||||||
|
|
||||||
// write a log message if we're not using NTP, otherwise wait for the internet time to arrive
|
// write a log message if we're not using NTP, otherwise wait for the internet time to arrive
|
||||||
if (!_ntp_enabled) {
|
if (!_ntp_enabled) {
|
||||||
_writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
|
writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2831,10 +2831,12 @@ void MyESP::_syslog_setup() {
|
|||||||
syslog.mark_interval(3600);
|
syslog.mark_interval(3600);
|
||||||
|
|
||||||
IPAddress syslog_ip;
|
IPAddress syslog_ip;
|
||||||
syslog.destination(syslog_ip.fromString(_general_log_ip));
|
syslog_ip.fromString("192.168.1.4");
|
||||||
|
syslog.destination(syslog_ip);
|
||||||
|
|
||||||
|
logger.info(F("Application started"));
|
||||||
|
|
||||||
myDebug_P(PSTR("[SYSLOG] System event logging enabled"));
|
myDebug_P(PSTR("[SYSLOG] System event logging enabled"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup MyESP
|
// setup MyESP
|
||||||
@@ -2857,8 +2859,6 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
|
|||||||
// print a welcome message
|
// print a welcome message
|
||||||
myDebug_P(PSTR("\n\n* %s version %s"), _app_name, _app_version);
|
myDebug_P(PSTR("\n\n* %s version %s"), _app_name, _app_version);
|
||||||
|
|
||||||
_syslog_setup(); // SysLog
|
|
||||||
|
|
||||||
// set up onboard LED
|
// set up onboard LED
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
@@ -2870,6 +2870,7 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
|
|||||||
_wifi_setup(); // WIFI setup
|
_wifi_setup(); // WIFI setup
|
||||||
_mqtt_setup(); // MQTT setup
|
_mqtt_setup(); // MQTT setup
|
||||||
_ota_setup(); // init OTA
|
_ota_setup(); // init OTA
|
||||||
|
_syslog_setup(); // SysLog
|
||||||
_webserver_setup(); // init web server
|
_webserver_setup(); // init web server
|
||||||
|
|
||||||
_setSystemCheck(false); // reset system check
|
_setSystemCheck(false); // reset system check
|
||||||
@@ -2918,7 +2919,7 @@ void MyESP::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_shouldRestart) {
|
if (_shouldRestart) {
|
||||||
_writeLogEvent(MYESP_SYSLOG_INFO, "System is restarting");
|
writeLogEvent(MYESP_SYSLOG_INFO, "System is restarting");
|
||||||
myDebug("[SYSTEM] Restarting...");
|
myDebug("[SYSTEM] Restarting...");
|
||||||
_deferredReset(500, CUSTOM_RESET_TERMINAL);
|
_deferredReset(500, CUSTOM_RESET_TERMINAL);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ class MyESP {
|
|||||||
void setUseSerial(bool toggle);
|
void setUseSerial(bool toggle);
|
||||||
|
|
||||||
// syslog
|
// syslog
|
||||||
void _writeLogEvent(const uint8_t type, const char * msg);
|
void writeLogEvent(const uint8_t type, const char * msg);
|
||||||
|
|
||||||
// FS
|
// FS
|
||||||
void setSettings(fs_loadsave_callback_f loadsave, fs_setlist_callback_f setlist, bool useSerial = true);
|
void setSettings(fs_loadsave_callback_f loadsave, fs_setlist_callback_f setlist, bool useSerial = true);
|
||||||
|
|||||||
14
src/ems.cpp
14
src/ems.cpp
@@ -531,6 +531,8 @@ void _debugPrintTelegram(const char * prefix, _EMS_RxTelegram * EMS_RxTelegram,
|
|||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(output_str, "(", sizeof(output_str));
|
strlcpy(output_str, "(", sizeof(output_str));
|
||||||
|
|
||||||
|
if (!raw)
|
||||||
strlcat(output_str, COLOR_CYAN, sizeof(output_str));
|
strlcat(output_str, COLOR_CYAN, sizeof(output_str));
|
||||||
|
|
||||||
strlcat(output_str, _smallitoa(t_hour, buffer), sizeof(output_str));
|
strlcat(output_str, _smallitoa(t_hour, buffer), sizeof(output_str));
|
||||||
@@ -545,9 +547,14 @@ void _debugPrintTelegram(const char * prefix, _EMS_RxTelegram * EMS_RxTelegram,
|
|||||||
strlcat(output_str, _smallitoa3(t_msec, buffer), sizeof(output_str));
|
strlcat(output_str, _smallitoa3(t_msec, buffer), sizeof(output_str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!raw)
|
||||||
strlcat(output_str, COLOR_RESET, sizeof(output_str));
|
strlcat(output_str, COLOR_RESET, sizeof(output_str));
|
||||||
|
|
||||||
strlcat(output_str, ") ", sizeof(output_str));
|
strlcat(output_str, ") ", sizeof(output_str));
|
||||||
|
|
||||||
|
if (!raw)
|
||||||
strlcat(output_str, color, sizeof(output_str));
|
strlcat(output_str, color, sizeof(output_str));
|
||||||
|
|
||||||
strlcat(output_str, prefix, sizeof(output_str));
|
strlcat(output_str, prefix, sizeof(output_str));
|
||||||
|
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
@@ -569,9 +576,12 @@ void _debugPrintTelegram(const char * prefix, _EMS_RxTelegram * EMS_RxTelegram,
|
|||||||
strlcat(output_str, " #data=", sizeof(output_str));
|
strlcat(output_str, " #data=", sizeof(output_str));
|
||||||
strlcat(output_str, itoa(data_len, buffer, 10), sizeof(output_str));
|
strlcat(output_str, itoa(data_len, buffer, 10), sizeof(output_str));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
strlcat(output_str, COLOR_RESET, sizeof(output_str));
|
strlcat(output_str, COLOR_RESET, sizeof(output_str));
|
||||||
|
} else {
|
||||||
|
// send it the SysLog
|
||||||
|
myESP.writeLogEvent(MYESP_SYSLOG_INFO, output_str);
|
||||||
|
}
|
||||||
|
|
||||||
myDebug(output_str);
|
myDebug(output_str);
|
||||||
}
|
}
|
||||||
@@ -910,7 +920,7 @@ void ems_parseTelegram(uint8_t * telegram, uint8_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we are in raw logging mode then just print out the telegram as it is
|
// if we are in raw logging mode then just print out the telegram as it is
|
||||||
// or if we're watching a specific type ID show it
|
// else if we're watching a specific type ID show it and also log an event to the SysLog
|
||||||
// but still continue to process it
|
// but still continue to process it
|
||||||
if ((EMS_Sys_Status.emsLogging == EMS_SYS_LOGGING_RAW)) {
|
if ((EMS_Sys_Status.emsLogging == EMS_SYS_LOGGING_RAW)) {
|
||||||
_debugPrintTelegram("", &EMS_RxTelegram, COLOR_WHITE, true);
|
_debugPrintTelegram("", &EMS_RxTelegram, COLOR_WHITE, true);
|
||||||
|
|||||||
@@ -130,7 +130,7 @@
|
|||||||
<div class="row form-group">
|
<div class="row form-group">
|
||||||
<label class="col-xs-3">Event Log Server IP<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
|
<label class="col-xs-3">Event Log Server IP<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
|
||||||
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
|
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
|
||||||
data-content="IP address of the SysLog server"></i></label>
|
data-content="IP address of the SysLog server running on UDP port 514"></i></label>
|
||||||
<span class="col-xs-9">
|
<span class="col-xs-9">
|
||||||
<input class="form-control input-sm" value="" style="display:inline;max-width:185px" id="log_ip"
|
<input class="form-control input-sm" value="" style="display:inline;max-width:185px" id="log_ip"
|
||||||
type="text">
|
type="text">
|
||||||
|
|||||||
Reference in New Issue
Block a user