-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setting system/default timezone in logging configuration
Users should have the ability to use the system timezone in the logging configuration. It allows administrators to take advantage of the operation system/JVM time zone management tools and use the same configuration for Dropwizard applications in different time zones.
- Loading branch information
Showing
8 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
dropwizard-logging/src/test/java/io/dropwizard/logging/AppenderFactoryCustomTimeZone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.dropwizard.logging; | ||
|
||
import com.google.common.io.Resources; | ||
import io.dropwizard.configuration.YamlConfigurationFactory; | ||
import io.dropwizard.jackson.Jackson; | ||
import io.dropwizard.validation.BaseValidator; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.net.URISyntaxException; | ||
import java.util.TimeZone; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AppenderFactoryCustomTimeZone { | ||
|
||
static { | ||
BootstrapLogging.bootstrap(); | ||
} | ||
|
||
private final YamlConfigurationFactory<ConsoleAppenderFactory> factory = new YamlConfigurationFactory<>( | ||
ConsoleAppenderFactory.class, BaseValidator.newValidator(), Jackson.newObjectMapper(), "dw"); | ||
|
||
private static File loadResource(String resourceName) throws URISyntaxException { | ||
return new File(Resources.getResource(resourceName).toURI()); | ||
} | ||
|
||
@Test | ||
public void testLoadAppenderWithCustomTimeZone() throws Exception { | ||
final ConsoleAppenderFactory appender = factory.build(loadResource("yaml/appender_with_custom_time_zone.yml")); | ||
assertThat(appender.getTimeZone().getID()).isEqualTo("CET"); | ||
} | ||
|
||
@Test | ||
public void testLoadAppenderWithNoTimeZone() throws Exception { | ||
final ConsoleAppenderFactory appender = factory.build(loadResource("yaml/appender_with_no_time_zone.yml")); | ||
assertThat(appender.getTimeZone().getID()).isEqualTo("UTC"); | ||
} | ||
|
||
@Test | ||
public void testLoadAppenderWithUtcTimeZone() throws Exception { | ||
final ConsoleAppenderFactory appender = factory.build(loadResource("yaml/appender_with_utc_time_zone.yml")); | ||
assertThat(appender.getTimeZone().getID()).isEqualTo("UTC"); | ||
} | ||
|
||
@Test | ||
public void testLoadAppenderWithWrongTimeZone() throws Exception { | ||
final ConsoleAppenderFactory appender = factory.build(loadResource("yaml/appender_with_wrong_time_zone.yml")); | ||
assertThat(appender.getTimeZone().getID()).isEqualTo("UTC"); | ||
} | ||
|
||
@Test | ||
public void testLoadAppenderWithSystemTimeZone() throws Exception { | ||
final ConsoleAppenderFactory appender = factory.build(loadResource("yaml/appender_with_system_time_zone.yml")); | ||
assertThat(appender.getTimeZone()).isEqualTo(TimeZone.getDefault()); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
dropwizard-logging/src/test/resources/yaml/appender_with_custom_time_zone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type: console | ||
timeZone: CET |
1 change: 1 addition & 0 deletions
1
dropwizard-logging/src/test/resources/yaml/appender_with_no_time_zone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type: console |
2 changes: 2 additions & 0 deletions
2
dropwizard-logging/src/test/resources/yaml/appender_with_system_time_zone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type: console | ||
timeZone: system |
2 changes: 2 additions & 0 deletions
2
dropwizard-logging/src/test/resources/yaml/appender_with_utc_time_zone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type: console | ||
timeZone: UTC |
2 changes: 2 additions & 0 deletions
2
dropwizard-logging/src/test/resources/yaml/appender_with_wrong_time_zone.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
type: console | ||
timeZone: Narnia |