Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Use timestamp format from logging.properties for JUL Handler if it pr…
Browse files Browse the repository at this point in the history
…esents there #140

Original pull request: #141.
  • Loading branch information
stankevichevg authored and mp911de committed Jun 5, 2018
1 parent 52a0ded commit 2ba70ce
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public void initialize(PropertyProvider propertyProvider) {
if (messageSize != null) {
maximumMessageSize = Integer.parseInt(messageSize);
}

String timestampPattern = propertyProvider.getProperty(PropertyProvider.PROPERTY_TIMESTAMP_PATTERN);
if (timestampPattern != null && !"".equals(timestampPattern)) {
this.timestampPattern = timestampPattern;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface PropertyProvider {
String PROPERTY_ADDITIONAL_FIELD_TYPE = "additionalFieldType.";
String PROPERTY_ADDITIONAL_FIELDS = "additionalFields";
String PROPERTY_ADDITIONAL_FIELD_TYPES = "additionalFieldTypes";
String PROPERTY_TIMESTAMP_PATTERN = "timestampPattern";

String PROPERTY_FILTER = "filter";
String PROPERTY_LEVEL = "level";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class GelfLogHandlerUnitTests {
private static final String HOST = "host";
private static final int GRAYLOG_PORT = 1;
private static final int MAXIMUM_MESSAGE_SIZE = 1234;
private static final String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss,SSSS";
private static final String TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

@Test
public void testSameFieldsGelfLogHandler() {
Expand All @@ -27,6 +27,7 @@ public void testSameFieldsGelfLogHandler() {
sut.setGraylogHost(HOST);
sut.setGraylogPort(GRAYLOG_PORT);
sut.setMaximumMessageSize(MAXIMUM_MESSAGE_SIZE);
sut.setTimestampPattern(TIMESTAMP_PATTERN);

sut.flush();

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/jul/test-logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ biz.paluch.logging.gelf.jul.GelfLogHandler.facility=java-test
biz.paluch.logging.gelf.jul.GelfLogHandler.version=1.1
biz.paluch.logging.gelf.jul.GelfLogHandler.extractStackTrace=true
biz.paluch.logging.gelf.jul.GelfLogHandler.filterStackTrace=true
biz.paluch.logging.gelf.jul.GelfLogHandler.timestampPattern=yyyy-MM-dd HH:mm:ss,SSSS
biz.paluch.logging.gelf.jul.GelfLogHandler.timestampPattern=yyyy-MM-dd'T'HH:mm:ss.SSSZ
biz.paluch.logging.gelf.jul.GelfLogHandler.maximumMessageSize=8192
biz.paluch.logging.gelf.jul.GelfLogHandler.additionalFields=fieldName1=fieldValue1,fieldName2=fieldValue2
biz.paluch.logging.gelf.jul.GelfLogHandler.additionalField.0=fieldName3=fieldValue3
Expand Down

0 comments on commit 2ba70ce

Please sign in to comment.