NopeCharon opened a new pull request, #820: URL: https://github.com/apache/logging-log4cxx/pull/820
Fixes #390 ## Problem `SyslogAppender` sends each message to a remote syslog daemon as the priority followed by the formatted message, as in BSD syslog (RFC 3164). Collectors that expect the syslog protocol ([RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424)) cannot get a timestamp, host name, application name or process identifier from these messages. ## Change A new `Format` option (`BSD`, the default, or `RFC5424`). With `RFC5424`, each packet sent over the network starts with the RFC 5424 header: ``` <PRI>1 TIMESTAMP HOSTNAME APP-NAME PROCID MSGID - message ``` | Field | Value | | --- | --- | | TIMESTAMP | event time in UTC with microsecond precision, e.g. `2026-11-11T14:04:35.965104Z` | | HOSTNAME | local host name (`apr_gethostname`) | | APP-NAME | new `AppName` option | | PROCID | current process identifier | | MSGID | new `MessageId` option | | STRUCTURED-DATA | nil value | - An empty field is sent as the nil value (`-`). - `AppName` and `MessageId` values are made valid header fields: characters that are not printable US-ASCII (including spaces) are replaced by `_`, and the value is truncated to the RFC 5424 maximum length (48 and 32). A warning is written to the internal debugging output when a value is changed. - The option names match the Log4j 2 `SyslogAppender` attributes (`format`, `appName`, `messageId`). - `MaxMessageLength` still limits the formatted message, and every packet of a split message gets the full header. `FacilityPrinting` still adds the facility name to the start of the message. - Messages sent using the system function `syslog` on the local host do not change, because the C library adds the header there. The class documentation says this. - The default (`BSD`) output is byte-for-byte the same as before. Example configuration: ```properties log4j.appender.S=org.apache.log4j.net.SyslogAppender log4j.appender.S.SyslogHost=loghost:514 log4j.appender.S.Facility=LOCAL3 log4j.appender.S.Format=RFC5424 log4j.appender.S.AppName=myapp log4j.appender.S.MessageId=ID47 ``` The header is built by `detail::appendRfc5424Header`, next to the existing `detail::splitSyslogPackets`, so it can be unit tested. The reference documentation (`setOption` table, setters, class description) and the 2.0.0 change log are updated. ## Testing New `SyslogAppenderTestCase` tests: - `testFormatOption`: case-insensitive values, and an unknown value is ignored - `testRfc5424FieldOptions`: replacing characters and truncating `AppName` and `MessageId` - `testRfc5424Header`: exact header for a fixed timestamp (`2003-10-11T22:14:15.003210Z`) - `testRfc5424HeaderNilValues`: nil values for empty fields On Ubuntu 24.04 (GCC 13), the full `ctest` suite passes (70/70). `syslogappendertestcase` also builds and passes with `-DCMAKE_CXX_STANDARD=11 -DLOG4CXX_CHAR=wchar_t`. End to end: a program configured with the properties above (`SyslogHost=127.0.0.1:5514`, `AppName=my e2e app`, `MaxMessageLength=100`) sent its messages to a UDP listener. The listener checked every packet against the RFC 5424 section 6 ABNF, and all of them matched: ``` <158>1 2026-11-11T14:04:35.965104Z bf67f5125a05 my_e2e_app 14 ID47 - Hello world <155>1 2026-11-11T14:04:35.965205Z bf67f5125a05 my_e2e_app 14 ID47 - An error <156>1 2026-11-11T14:04:35.965213Z bf67f5125a05 my_e2e_app 14 ID47 - xxxx…xxxx(1/2) <156>1 2026-11-11T14:04:35.965213Z bf67f5125a05 my_e2e_app 14 ID47 - xxxx…xxxx(2/2) ``` Without `Format`, the same program still sends `<158>Hello world`, as before. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
