|
|
@ -1,6 +1,6 @@ |
|
|
|
#if defined(ESP8266)
|
|
|
|
#include <Esp.h>
|
|
|
|
#include <WiFiUdp.h>
|
|
|
|
#include "WiFiUdp.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Syslog.hpp"
|
|
|
@ -42,6 +42,7 @@ void Syslog::operator() (Priority prio, const char *format, ...) { |
|
|
|
vsnprintf(buf, sizeof(buf), format, args); |
|
|
|
va_end(args); |
|
|
|
Syslog::prio(prio); |
|
|
|
Syslog::time(); |
|
|
|
Serial.println(buf); |
|
|
|
send(priority(prio), buf); |
|
|
|
} |
|
|
@ -53,6 +54,7 @@ void Syslog::operator() (Priority prio, const __FlashStringHelper *format, ...) |
|
|
|
vsnprintf_P(buf, sizeof(buf), (PGM_P) format, args); |
|
|
|
va_end(args); |
|
|
|
Syslog::prio(prio); |
|
|
|
Syslog::time(); |
|
|
|
Serial.println(buf); |
|
|
|
send(priority(prio), buf); |
|
|
|
} |
|
|
@ -60,6 +62,7 @@ void Syslog::operator() (Priority prio, const __FlashStringHelper *format, ...) |
|
|
|
void Syslog::operator() (Priority prio, String message) { |
|
|
|
if (LOG_PRI(priority(prio)) > mask) return; |
|
|
|
Syslog::prio(prio); |
|
|
|
Syslog::time(); |
|
|
|
Serial.println(message); |
|
|
|
send(priority(prio), message.c_str()); |
|
|
|
} |
|
|
@ -67,6 +70,7 @@ void Syslog::operator() (Priority prio, String message) { |
|
|
|
void Syslog::log(Priority prio, const char *message) { |
|
|
|
if (LOG_PRI(priority(prio)) > mask) return; |
|
|
|
Syslog::prio(prio); |
|
|
|
Syslog::time(); |
|
|
|
Serial.println(message); |
|
|
|
send(priority(prio), message); |
|
|
|
} |
|
|
@ -74,6 +78,7 @@ void Syslog::log(Priority prio, const char *message) { |
|
|
|
void Syslog::log(Priority prio, String message) { |
|
|
|
if (LOG_PRI(priority(prio)) > mask) return; |
|
|
|
Syslog::prio(prio); |
|
|
|
Syslog::time(); |
|
|
|
Serial.println(message); |
|
|
|
send(priority(prio), message.c_str()); |
|
|
|
} |
|
|
@ -85,6 +90,7 @@ void Syslog::logf(Priority prio, const char *format, ...) { |
|
|
|
vsnprintf(buf, sizeof(buf), format, args); |
|
|
|
va_end(args); |
|
|
|
Syslog::prio(prio); |
|
|
|
Syslog::time(); |
|
|
|
Serial.println(buf); |
|
|
|
send(priority(prio), buf); |
|
|
|
} |
|
|
@ -96,6 +102,7 @@ void Syslog::logf(Priority prio, const __FlashStringHelper *format, ...) { |
|
|
|
vsnprintf_P(buf, sizeof(buf), (PGM_P) format, args); |
|
|
|
va_end(args); |
|
|
|
Syslog::prio(prio); |
|
|
|
Syslog::time(); |
|
|
|
Serial.println(buf); |
|
|
|
send(priority(prio), buf); |
|
|
|
} |
|
|
@ -240,3 +247,29 @@ void Syslog::send(uint16_t prio, const __FlashStringHelper *message) { |
|
|
|
client->print(message); |
|
|
|
client->endPacket(); |
|
|
|
} |
|
|
|
|
|
|
|
void Syslog::time() { |
|
|
|
uint32_t epoch = 0; |
|
|
|
if (timeFunc != nullptr) { |
|
|
|
epoch = timeFunc(); |
|
|
|
} |
|
|
|
|
|
|
|
uint32_t h = (epoch % 86400) / 3600; |
|
|
|
uint32_t m = (epoch % 3600) / 60; |
|
|
|
uint32_t s = (epoch % 60); |
|
|
|
if (h < 10) { |
|
|
|
Serial.print('0'); |
|
|
|
} |
|
|
|
Serial.print(h); |
|
|
|
Serial.print(':'); |
|
|
|
if (m < 10) { |
|
|
|
Serial.print('0'); |
|
|
|
} |
|
|
|
Serial.print(m); |
|
|
|
Serial.print(':'); |
|
|
|
if (s < 10) { |
|
|
|
Serial.print('0'); |
|
|
|
} |
|
|
|
Serial.print(s); |
|
|
|
Serial.print(' '); |
|
|
|
} |