33
44#include " syslog.h"
55
6- // Comment out but preserve the protocol names
7- /*
8- static const char* const protoNames[] PROGMEM = {
9- PSTR("BSD"),
10- PSTR("RFC5424"),
11- PSTR("RAW"),
12- PSTR("UNKNOWN")
13- };
14- static const uint8_t protoCount = sizeof(protoNames)/sizeof(*protoNames);
15- */
16-
17- // Comment out but preserve facility names
18- /*
19- // We fill invalid entries with PSTR("UNKNOWN") so we can index 0..24 safely
20- static const char* const facilityNames[] PROGMEM = {
21- PSTR("KERN"), PSTR("USER"), PSTR("UNKNOWN"), PSTR("DAEMON"),
22- PSTR("UNKNOWN"),PSTR("SYSLOG"), PSTR("UNKNOWN"), PSTR("UNKNOWN"),
23- PSTR("UNKNOWN"),PSTR("UNKNOWN"),PSTR("UNKNOWN"), PSTR("UNKNOWN"),
24- PSTR("UNKNOWN"),PSTR("UNKNOWN"),PSTR("UNKNOWN"), PSTR("UNKNOWN"),
25- PSTR("LCL0"), PSTR("LCL1"), PSTR("LCL2"), PSTR("LCL3"),
26- PSTR("LCL4"), PSTR("LCL5"), PSTR("LCL6"), PSTR("LCL7"),
27- PSTR("UNKNOWN") // catch-all at index 24
28- };
29- static const uint8_t facCount = sizeof(facilityNames)/sizeof(*facilityNames);
30- */
31-
32- // Comment out but preserve severity names
33- /*
34- static const char* const severityNames[] PROGMEM = {
35- PSTR("EMERG"), PSTR("ALERT"), PSTR("CRIT"), PSTR("ERR"),
36- PSTR("WARN"), PSTR("NOTE"), PSTR("INFO"), PSTR("DEBUG"),
37- PSTR("UNKNOWN")
38- };
39- static const uint8_t sevCount = sizeof(severityNames) / sizeof(*severityNames);
40- */
41-
426SyslogPrinter::SyslogPrinter () :
437 _lastOperationSucceeded(true ),
448 _lastErrorMessage(" " ),
@@ -55,24 +19,6 @@ void SyslogPrinter::begin(const char* host, uint16_t port,
5519 DEBUG_PRINTF_P (PSTR (" Hostname: %s\n " ), host);
5620 DEBUG_PRINTF_P (PSTR (" Cached IP: %s\n " ), syslogHostIP.toString ().c_str ());
5721 DEBUG_PRINTF_P (PSTR (" Port: %u\n " ), (unsigned )port);
58-
59- /*
60- // Protocol
61- uint8_t pidx = protocol < (protoCount - 1) ? protocol : (protoCount - 1);
62- const char* pstr = (const char*)pgm_read_ptr(&protoNames[pidx]);
63- DEBUG_PRINTF_P(PSTR(" Protocol: %u (%s)\n"), (unsigned)protocol, pstr);
64-
65- // — Facility
66- uint8_t fidx = facility < (facCount - 1) ? facility : (facCount - 1);
67- const char* fstr = (const char*)pgm_read_ptr(&facilityNames[fidx]);
68- DEBUG_PRINTF_P(PSTR(" Facility: %u (%s)\n"), (unsigned)facility, fstr);
69-
70- // Severity
71- uint8_t idx = severity < sevCount-1 ? severity : sevCount-1;
72- const char* sevStr = (const char*)pgm_read_ptr(&severityNames[idx]);
73- DEBUG_PRINTF_P(PSTR(" Severity: %u (%s)\n"), (unsigned)severity, sevStr);
74- */
75-
7622 DEBUG_PRINTF_P (PSTR (" ======================================\n " ));
7723
7824 strlcpy (syslogHost, host, sizeof (syslogHost));
@@ -211,76 +157,35 @@ size_t SyslogPrinter::write(const uint8_t *buf, size_t size, uint8_t severity) {
211157 String cleanHostname = String (serverDescription);
212158 cleanHostname.replace (' ' , ' _' );
213159
214- // Handle different syslog protocol formats
215- // Note: Only BSD protocol is currently implemented; RFC5424 and RAW are preserved for future use
216- // switch (_protocol) {
217- // case SYSLOG_PROTO_BSD:
218- // RFC 3164 format: <PRI>TIMESTAMP HOSTNAME APP-NAME: MESSAGE
219- syslogUdp.printf (" <%d>" , pri);
220-
221- if (ntpEnabled && ntpConnected) {
222- // Month abbreviation
223- static const char * const months[] = {
224- " Jan" ," Feb" ," Mar" ," Apr" ," May" ," Jun" ,
225- " Jul" ," Aug" ," Sep" ," Oct" ," Nov" ," Dec"
226- };
227-
228- syslogUdp.printf (" %s %2d %02d:%02d:%02d " ,
229- months[month (localTime) - 1 ],
230- day (localTime),
231- hour (localTime),
232- minute (localTime),
233- second (localTime));
234- } else {
235- // No valid time available
236- syslogUdp.print (F (" Jan 01 00:00:00 " ));
237- }
238-
239- // Add hostname and app name
240- syslogUdp.print (cleanHostname);
241- syslogUdp.print (" " );
242- syslogUdp.print (_appName);
243- syslogUdp.print (" : " );
244-
245- // Add message content
246- size = syslogUdp.write (buf, size);
247- /*
248- break;
249-
250- case SYSLOG_PROTO_RFC5424:
251- // RFC 5424 format: <PRI>VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID STRUCTURED-DATA MSG
252- syslogUdp.printf("<%d>1 ", pri); // Version is always 1
253-
254- if (ntpEnabled && ntpConnected) {
255- syslogUdp.printf("%04d-%02d-%02dT%02d:%02d:%02dZ ",
256- year(localTime),
257- month(localTime),
258- day(localTime),
259- hour(localTime),
260- minute(localTime),
261- second(localTime));
262- } else {
263- // No valid time available
264- syslogUdp.print(F("1970-01-01T00:00:00Z "));
265- }
266-
267- // Add hostname, app name, and other fields (using - for empty fields)
268- syslogUdp.print(cleanHostname);
269- syslogUdp.print(" ");
270- syslogUdp.print(_appName);
271- syslogUdp.print(F(" - - - ")); // PROCID, MSGID, and STRUCTURED-DATA are empty
272-
273- // Add message content
274- size = syslogUdp.write(buf, size);
275- break;
276-
277- case SYSLOG_PROTO_RAW:
278- default:
279- // Just send the raw message (like original NetDebug)
280- size = syslogUdp.write(buf, size);
281- break;
160+ // Note: Only BSD protocol is currently implemented
161+ syslogUdp.printf (" <%d>" , pri);
162+
163+ if (ntpEnabled && ntpConnected) {
164+ // Month abbreviation
165+ static const char * const months[] = {
166+ " Jan" ," Feb" ," Mar" ," Apr" ," May" ," Jun" ,
167+ " Jul" ," Aug" ," Sep" ," Oct" ," Nov" ," Dec"
168+ };
169+
170+ syslogUdp.printf (" %s %2d %02d:%02d:%02d " ,
171+ months[month (localTime) - 1 ],
172+ day (localTime),
173+ hour (localTime),
174+ minute (localTime),
175+ second (localTime));
176+ } else {
177+ // No valid time available
178+ syslogUdp.print (F (" Jan 01 00:00:00 " ));
282179 }
283- */
180+
181+ // Add hostname and app name
182+ syslogUdp.print (cleanHostname);
183+ syslogUdp.print (" " );
184+ syslogUdp.print (_appName);
185+ syslogUdp.print (" : " );
186+
187+ // Add message content
188+ size = syslogUdp.write (buf, size);
284189
285190 syslogUdp.endPacket ();
286191 return size;
0 commit comments