fix for syslog

This commit is contained in:
folkert van heusden 2024-04-27 21:39:13 +02:00
parent 801dbee4e1
commit ff1da92dc8
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
3 changed files with 13 additions and 6 deletions

View file

@ -942,7 +942,10 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
}
#endif
else if (parts[0] == "setsl" && parts.size() == 3) {
setloghost(parts.at(1).c_str(), parse_ll(parts[2]));
if (setloghost(parts.at(1).c_str(), parse_ll(parts[2])) == false)
cnsl->put_string_lf("Failed parsing IP address");
else
send_syslog(info, "Hello, world!");
continue;
}
@ -1011,7 +1014,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
"ser - serialize state to a file",
// "dser - deserialize state from a file",
#endif
"dp - stop panel",
"dp - disable panel",
#if defined(ESP32)
"cfgnet - configure network (e.g. WiFi)",
"startnet - start network",

View file

@ -54,9 +54,10 @@ void setlogfile(const char *const lf, const log_level_t ll_file, const log_level
atexit(closelog);
}
void setloghost(const char *const host, const log_level_t ll)
bool setloghost(const char *const host, const log_level_t ll)
{
inet_aton(host, &syslog_ip_addr.sin_addr);
syslog_ip_addr.sin_family = AF_INET;
bool ok = inet_aton(host, &syslog_ip_addr.sin_addr) == 1;
syslog_ip_addr.sin_port = htons(514);
is_file = false;
@ -64,6 +65,8 @@ void setloghost(const char *const host, const log_level_t ll)
log_level_file = ll;
l_timestamp = false;
return ok;
}
void setll(const log_level_t ll_screen, const log_level_t ll_file)

3
log.h
View file

@ -12,9 +12,10 @@ typedef enum { ll_emerg = 0, ll_alert, ll_critical, ll_error, warning, notice, i
log_level_t parse_ll(const std::string & str);
void setlogfile(const char *const lf, const log_level_t ll_file, const log_level_t ll_screen, const bool l_timestamp);
void setloghost(const char *const host, const log_level_t ll);
bool setloghost(const char *const host, const log_level_t ll);
void setll(const log_level_t ll_screen, const log_level_t ll_file);
void setloguid(const int uid, const int gid);
void send_syslog(const int ll, const std::string & what);
void closelog();
void dolog(const log_level_t ll, const char *fmt, ...);