Add the following dependency in your pom.xml:
<dependency>
<groupId>com.teragrep</groupId>
<artifactId>rlo_14</artifactId>
<version>1.0.0</version>
</dependency>
Sourcing timestamp from long
Instant time = Instant.now();
SyslogMessage message = new SyslogMessage()
.withTimestamp(time.toEpochMilli())
.withAppName("my_app")
.withHostname("localhost")
.withFacility(Facility.USER)
.withSeverity(Severity.INFORMATIONAL)
.withMsg("a syslog message");
String actual = message.toRfc5424SyslogMessage();
Sourcing timestamp from Instant
Instant time = Instant.now();
SyslogMessage message = new SyslogMessage()
.withTimestamp(time)
.withAppName("my_app")
.withHostname("localhost")
.withFacility(Facility.USER)
.withSeverity(Severity.INFORMATIONAL)
.withMsg("a syslog message");
String actual = message.toRfc5424SyslogMessage();
Sourcing timestamp from string (parsed and validated)
SyslogMessage message = new SyslogMessage()
.withTimestamp("2023-06-14T16:37:00.000Z")
.withAppName("my_app")
.withHostname("localhost")
.withFacility(Facility.USER)
.withSeverity(Severity.INFORMATIONAL)
.withMsg("a syslog message");
String actual = message.toRfc5424SyslogMessage();
Sourcing timestamp from string (no validation, useful when you know you have correct format)
SyslogMessage message = new SyslogMessage()
.withTimestamp("2023-06-14T16:37:00.000Z", true)
.withAppName("my_app")
.withHostname("localhost")
.withFacility(Facility.USER)
.withSeverity(Severity.INFORMATIONAL)
.withMsg("a syslog message");
String actual = message.toRfc5424SyslogMessage();
Adding structured data
SyslogMessage message = new SyslogMessage()
.withTimestamp("2023-06-14T16:37:00.000Z")
.withAppName("my_app")
.withHostname("localhost")
.withFacility(Facility.USER)
.withSeverity(Severity.INFORMATIONAL)
.withMsg("a syslog message")
.withSDElement(
new SDElement(
"event_version@48577",
new SDParam("major", "1"),
new SDParam("minor", "0"),
new SDParam("version_source", "source")
)
);
String actual = message.toRfc5424SyslogMessage();
You can involve yourself with our project by opening an issue or submitting a pull request.
Contribution requirements:
-
All changes must be accompanied by a new or changed test. If you think testing is not required in your pull request, include a sufficient explanation as why you think so.
-
Security checks must pass
-
Pull requests must align with the principles and values of extreme programming.
-
Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).
Read more in our Contributing Guideline.
Contributors must sign Teragrep Contributor License Agreement before a pull request is accepted to organization’s repositories.
You need to submit the CLA only once. After submitting the CLA you can contribute to all Teragrep’s repositories.