mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
syslog: timestamp to local, add appname
This commit is contained in:
@@ -199,7 +199,6 @@ SyslogService::QueuedLogMessage::QueuedLogMessage(unsigned long id, std::shared_
|
|||||||
time_.tv_sec = time(nullptr);
|
time_.tv_sec = time(nullptr);
|
||||||
time_.tv_usec = 0;
|
time_.tv_usec = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (time_.tv_sec >= 0 && time_.tv_sec < 18140 * 86400) {
|
if (time_.tv_sec >= 0 && time_.tv_sec < 18140 * 86400) {
|
||||||
time_.tv_sec = (time_t)-1;
|
time_.tv_sec = (time_t)-1;
|
||||||
}
|
}
|
||||||
@@ -386,15 +385,20 @@ bool SyslogService::can_transmit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SyslogService::transmit(const QueuedLogMessage & message) {
|
bool SyslogService::transmit(const QueuedLogMessage & message) {
|
||||||
/*
|
|
||||||
// modifications by Proddy. From https://github.com/emsesp/EMS-ESP/issues/395#issuecomment-640053528
|
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
|
int8_t tzh = 0;
|
||||||
|
int8_t tzm = 0;
|
||||||
|
|
||||||
tm.tm_year = 0;
|
tm.tm_year = 0;
|
||||||
if (message.time_.tv_sec != (time_t)-1) {
|
if (message.time_.tv_sec != (time_t)-1) {
|
||||||
gmtime_r(&message.time_.tv_sec, &tm);
|
struct tm utc;
|
||||||
|
gmtime_r(&message.time_.tv_sec, &utc);
|
||||||
|
localtime_r(&message.time_.tv_sec, &tm);
|
||||||
|
int16_t diff = 60 * (tm.tm_hour - utc.tm_hour) + tm.tm_min - utc.tm_min;
|
||||||
|
diff = diff > 720 ? diff - 1440 : diff < -720 ? diff + 1440 : diff;
|
||||||
|
tzh = diff / 60;
|
||||||
|
tzm = diff < 0 ? (0 - diff) % 60 : diff % 60;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
if (udp_.beginPacket(host_, port_) != 1) {
|
if (udp_.beginPacket(host_, port_) != 1) {
|
||||||
last_transmit_ = uuid::get_uptime_ms();
|
last_transmit_ = uuid::get_uptime_ms();
|
||||||
@@ -402,30 +406,24 @@ bool SyslogService::transmit(const QueuedLogMessage & message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
udp_.printf_P(PSTR("<%u>1 "), ((unsigned int)message.content_->facility * 8) + std::min(7U, (unsigned int)message.content_->level));
|
udp_.printf_P(PSTR("<%u>1 "), ((unsigned int)message.content_->facility * 8) + std::min(7U, (unsigned int)message.content_->level));
|
||||||
|
|
||||||
/*
|
|
||||||
if (tm.tm_year != 0) {
|
if (tm.tm_year != 0) {
|
||||||
udp_.printf_P(PSTR("%04u-%02u-%02uT%02u:%02u:%02u.%06luZ"),
|
udp_.printf_P(PSTR("%04u-%02u-%02uT%02u:%02u:%02u.%06u%+02d:%02d"),
|
||||||
tm.tm_year + 1900,
|
tm.tm_year + 1900,
|
||||||
tm.tm_mon + 1,
|
tm.tm_mon + 1,
|
||||||
tm.tm_mday,
|
tm.tm_mday,
|
||||||
tm.tm_hour,
|
tm.tm_hour,
|
||||||
tm.tm_min,
|
tm.tm_min,
|
||||||
tm.tm_sec,
|
tm.tm_sec,
|
||||||
(uint32_t)message.time_.tv_usec);
|
(uint32_t)message.time_.tv_usec,
|
||||||
|
tzh, tzm);
|
||||||
} else {
|
} else {
|
||||||
udp_.print('-');
|
udp_.print('-');
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
udp_.print('-');
|
udp_.printf_P(PSTR(" %s %s - - - \xEF\xBB\xBF"), hostname_.c_str(), uuid::read_flash_string(message.content_->name).c_str());
|
||||||
udp_.printf_P(PSTR(" %s - - - - \xEF\xBB\xBF"), hostname_.c_str());
|
|
||||||
udp_.print(uuid::log::format_timestamp_ms(message.content_->uptime_ms, 3).c_str());
|
udp_.print(uuid::log::format_timestamp_ms(message.content_->uptime_ms, 3).c_str());
|
||||||
|
udp_.printf_P(PSTR(" %c %lu: "), uuid::log::format_level_char(message.content_->level), message.id_);
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Wformat"
|
|
||||||
udp_.printf_P(PSTR(" %c %lu: [%S] "), uuid::log::format_level_char(message.content_->level), message.id_, message.content_->name);
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
udp_.print(message.content_->text.c_str());
|
udp_.print(message.content_->text.c_str());
|
||||||
bool ok = (udp_.endPacket() == 1);
|
bool ok = (udp_.endPacket() == 1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user