This commit is contained in:
Paul
2019-11-20 22:40:04 +01:00
parent e26aaf3d1a
commit 01504729d8
4 changed files with 34 additions and 23 deletions

View File

@@ -46,7 +46,7 @@ MyESP::MyESP() {
_ota_post_callback_f = nullptr;
_load_average = 100; // calculated load average
_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;
_have_ntp_time = false;
@@ -1729,7 +1729,7 @@ bool MyESP::_fs_loadConfig() {
_general_password = strdup(general["password"] | MYESP_HTTP_PASSWORD);
_ws->setAuthentication("admin", _general_password);
_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"] | "");
// serial is only on when booting
@@ -1880,7 +1880,7 @@ bool MyESP::fs_saveCustomConfig(JsonObject root) {
configFile.close();
if (n) {
_writeLogEvent(MYESP_SYSLOG_INFO, "Custom config stored in the SPIFFS");
writeLogEvent(MYESP_SYSLOG_INFO, "Custom config stored in the SPIFFS");
ok = true;
}
}
@@ -1913,7 +1913,7 @@ bool MyESP::fs_saveConfig(JsonObject root) {
configFile.close();
if (n) {
_writeLogEvent(MYESP_SYSLOG_INFO, "System config stored in the SPIFFS");
writeLogEvent(MYESP_SYSLOG_INFO, "System config stored in the SPIFFS");
ok = true;
}
@@ -2257,7 +2257,7 @@ void MyESP::crashInfo() {
#endif
// 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) {
return;
}
@@ -2781,7 +2781,7 @@ void MyESP::_bootupSequence() {
if (boot_status == MYESP_BOOTSTATUS_BOOTED) {
if ((_ntp_enabled) && (now() > 10000) && !_have_ntp_time) {
_have_ntp_time = true;
_writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
}
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
if (!_ntp_enabled) {
_writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
writeLogEvent(MYESP_SYSLOG_INFO, "System booted");
}
}
}
@@ -2819,7 +2819,7 @@ void MyESP::_bootupSequence() {
// set up SysLog
void MyESP::_syslog_setup() {
// if not enabled or IP is empty, don't bother
if ( (!_hasValue(_general_log_ip)) || (!_general_log_events) ) {
if ((!_hasValue(_general_log_ip)) || (!_general_log_events)) {
return;
}
@@ -2831,10 +2831,12 @@ void MyESP::_syslog_setup() {
syslog.mark_interval(3600);
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"));
}
// setup MyESP
@@ -2857,8 +2859,6 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
// print a welcome message
myDebug_P(PSTR("\n\n* %s version %s"), _app_name, _app_version);
_syslog_setup(); // SysLog
// set up onboard LED
pinMode(LED_BUILTIN, OUTPUT);
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
_mqtt_setup(); // MQTT setup
_ota_setup(); // init OTA
_syslog_setup(); // SysLog
_webserver_setup(); // init web server
_setSystemCheck(false); // reset system check
@@ -2918,7 +2919,7 @@ void MyESP::loop() {
}
if (_shouldRestart) {
_writeLogEvent(MYESP_SYSLOG_INFO, "System is restarting");
writeLogEvent(MYESP_SYSLOG_INFO, "System is restarting");
myDebug("[SYSTEM] Restarting...");
_deferredReset(500, CUSTOM_RESET_TERMINAL);
ESP.restart();

View File

@@ -298,7 +298,7 @@ class MyESP {
void setUseSerial(bool toggle);
// syslog
void _writeLogEvent(const uint8_t type, const char * msg);
void writeLogEvent(const uint8_t type, const char * msg);
// FS
void setSettings(fs_loadsave_callback_f loadsave, fs_setlist_callback_f setlist, bool useSerial = true);

View File

@@ -531,6 +531,8 @@ void _debugPrintTelegram(const char * prefix, _EMS_RxTelegram * EMS_RxTelegram,
}
strlcpy(output_str, "(", sizeof(output_str));
if (!raw)
strlcat(output_str, COLOR_CYAN, 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));
}
if (!raw)
strlcat(output_str, COLOR_RESET, sizeof(output_str));
strlcat(output_str, ") ", sizeof(output_str));
if (!raw)
strlcat(output_str, color, sizeof(output_str));
strlcat(output_str, prefix, sizeof(output_str));
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, itoa(data_len, buffer, 10), 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);
}
@@ -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
// 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
if ((EMS_Sys_Status.emsLogging == EMS_SYS_LOGGING_RAW)) {
_debugPrintTelegram("", &EMS_RxTelegram, COLOR_WHITE, true);

View File

@@ -130,7 +130,7 @@
<div class="row form-group">
<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"
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">
<input class="form-control input-sm" value="" style="display:inline;max-width:185px" id="log_ip"
type="text">