Skip to content

teragrep/rlo_14

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java RFC5424 Syslog Formatter

Description

Java RFC5424 formatter library

Using the Syslog Java Client with Maven

Add the following dependency in your pom.xml:

<dependency>
    <groupId>com.teragrep</groupId>
    <artifactId>rlo_14</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

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();

Contributing

You can involve yourself with our project by opening an issue or submitting a pull request.

Contribution requirements:

  1. 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.

  2. Security checks must pass

  3. Pull requests must align with the principles and values of extreme programming.

  4. Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).

Read more in our Contributing Guideline.

Contributor License Agreement

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.