syslog settings changeable while running

This commit is contained in:
MichaelDvP
2020-11-10 11:23:18 +01:00
parent 8c62977ad3
commit b210517333
3 changed files with 24 additions and 13 deletions

View File

@@ -237,7 +237,9 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
variant="outlined" variant="outlined"
onChange={handleValueChange('syslog_level')} onChange={handleValueChange('syslog_level')}
margin="normal"> margin="normal">
<MenuItem value={-1}>OFF</MenuItem>
<MenuItem value={3}>ERR</MenuItem> <MenuItem value={3}>ERR</MenuItem>
<MenuItem value={5}>NOTICE</MenuItem>
<MenuItem value={6}>INFO</MenuItem> <MenuItem value={6}>INFO</MenuItem>
<MenuItem value={7}>DEBUG</MenuItem> <MenuItem value={7}>DEBUG</MenuItem>
</SelectValidator> </SelectValidator>
@@ -245,7 +247,7 @@ function EMSESPSettingsControllerForm(props: EMSESPSettingsControllerFormProps)
validators={['required', 'isNumber', 'minNumber:0', 'maxNumber:65535']} validators={['required', 'isNumber', 'minNumber:0', 'maxNumber:65535']}
errorMessages={['Syslog Mark is required', "Must be a number", "Must be 0 or higher", "Max value is 10"]} errorMessages={['Syslog Mark is required', "Must be a number", "Must be 0 or higher", "Max value is 10"]}
name="syslog_mark_interval" name="syslog_mark_interval"
label="Syslog Mark Interval (seconds)" label="Syslog Mark Interval (seconds, 0=off)"
fullWidth fullWidth
variant="outlined" variant="outlined"
value={data.syslog_mark_interval} value={data.syslog_mark_interval}

View File

@@ -39,6 +39,11 @@ uint16_t System::analog_ = 0;
bool System::analog_enabled_ = false; bool System::analog_enabled_ = false;
bool System::syslog_enabled_ = false; bool System::syslog_enabled_ = false;
std::string System::hostname_; std::string System::hostname_;
int8_t System::syslog_level_ = -1;
uint32_t System::syslog_mark_interval_ = 0;
String System::syslog_host_;
// send on/off to a gpio pin // send on/off to a gpio pin
// value: true = HIGH, false = LOW // value: true = HIGH, false = LOW
@@ -120,6 +125,13 @@ void System::syslog_init() {
}); });
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
if (!syslog_enabled_) {
syslog_.log_level((uuid::log::Level)-1);
syslog_.mark_interval(0);
syslog_.destination(0);
return;
}
syslog_.start(); // syslog service re-start syslog_.start(); // syslog service re-start
// configure syslog // configure syslog
@@ -155,9 +167,6 @@ void System::start() {
Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F_(send), System::command_send); Command::add(EMSdevice::DeviceType::SYSTEM, settings.ems_bus_id, F_(send), System::command_send);
Command::add_with_json(EMSdevice::DeviceType::SYSTEM, F_(info), System::command_info); Command::add_with_json(EMSdevice::DeviceType::SYSTEM, F_(info), System::command_info);
Command::add_with_json(EMSdevice::DeviceType::SYSTEM, F_(report), System::command_report); Command::add_with_json(EMSdevice::DeviceType::SYSTEM, F_(report), System::command_report);
if (settings.syslog_enabled) {
syslog_init(); // init SysLog
}
}); });
@@ -172,8 +181,8 @@ void System::init() {
EMSESP::webSettingsService.read([&](WebSettings & settings) { EMSESP::webSettingsService.read([&](WebSettings & settings) {
Helpers::bool_format(settings.bool_format); Helpers::bool_format(settings.bool_format);
analog_enabled_ = settings.analog_enabled; analog_enabled_ = settings.analog_enabled;
syslog_enabled_ = settings.syslog_enabled;
}); });
syslog_init(); // init SysLog
EMSESP::esp8266React.getWiFiSettingsService()->read([&](WiFiSettings & settings) { hostname(settings.hostname.c_str()); }); EMSESP::esp8266React.getWiFiSettingsService()->read([&](WiFiSettings & settings) { hostname(settings.hostname.c_str()); });

View File

@@ -59,9 +59,9 @@ class System {
static void show_mem(const char * note); static void show_mem(const char * note);
static void set_led(); static void set_led();
static void init(); static void init();
static void syslog_init();
bool check_upgrade(); bool check_upgrade();
void syslog_init();
void send_heartbeat(); void send_heartbeat();
static std::string hostname() { static std::string hostname() {
@@ -110,9 +110,9 @@ class System {
// settings // settings
static bool hide_led_; static bool hide_led_;
static bool syslog_enabled_; static bool syslog_enabled_;
uint8_t syslog_level_; static int8_t syslog_level_;
uint32_t syslog_mark_interval_; static uint32_t syslog_mark_interval_;
String syslog_host_; static String syslog_host_;
static uint8_t led_gpio_; static uint8_t led_gpio_;
static bool analog_enabled_; static bool analog_enabled_;
}; };