|
16 | 16 | */
|
17 | 17 | package org.apache.logging.log4j.core.layout;
|
18 | 18 |
|
19 |
| -import static org.apache.logging.log4j.core.time.internal.format.FixedDateFormat.FixedFormat; |
20 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
21 | 20 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
22 | 21 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
23 | 22 |
|
24 | 23 | import java.lang.management.ManagementFactory;
|
25 | 24 | import java.nio.charset.StandardCharsets;
|
26 |
| -import java.text.MessageFormat; |
27 |
| -import java.time.ZoneId; |
28 |
| -import java.time.ZonedDateTime; |
29 |
| -import java.time.format.DateTimeFormatter; |
30 | 25 | import java.util.Calendar;
|
31 | 26 | import java.util.List;
|
32 |
| -import java.util.Locale; |
33 | 27 | import java.util.Map;
|
34 | 28 | import org.apache.logging.log4j.Level;
|
35 | 29 | import org.apache.logging.log4j.ThreadContext;
|
36 | 30 | import org.apache.logging.log4j.core.AbstractLogEvent;
|
37 | 31 | import org.apache.logging.log4j.core.Appender;
|
38 |
| -import org.apache.logging.log4j.core.LogEvent; |
39 | 32 | import org.apache.logging.log4j.core.Logger;
|
40 | 33 | import org.apache.logging.log4j.core.LoggerContext;
|
41 | 34 | import org.apache.logging.log4j.core.config.Configuration;
|
|
45 | 38 | import org.apache.logging.log4j.core.test.junit.ConfigurationFactoryType;
|
46 | 39 | import org.apache.logging.log4j.core.time.Instant;
|
47 | 40 | import org.apache.logging.log4j.core.time.MutableInstant;
|
48 |
| -import org.apache.logging.log4j.core.time.internal.format.FixedDateFormat; |
49 | 41 | import org.apache.logging.log4j.message.Message;
|
50 | 42 | import org.apache.logging.log4j.message.SimpleMessage;
|
51 | 43 | import org.apache.logging.log4j.test.junit.UsingAnyThreadContext;
|
@@ -243,68 +235,7 @@ public void testLayoutWithDatePatternUnixMillis() {
|
243 | 235 | assertEquals("<td>" + event.getTimeMillis() + "</td>", actual, "Incorrect date:" + actual);
|
244 | 236 | }
|
245 | 237 |
|
246 |
| - @Test |
247 |
| - public void testLayoutWithDatePatternFixedFormat() { |
248 |
| - for (final String timeZone : new String[] {"GMT+8", "GMT+0530", "UTC", null}) { |
249 |
| - for (final FixedDateFormat.FixedFormat format : FixedDateFormat.FixedFormat.values()) { |
250 |
| - testLayoutWithDatePatternFixedFormat(format, timeZone); |
251 |
| - } |
252 |
| - } |
253 |
| - } |
254 |
| - |
255 | 238 | private String getDateLine(final String logEventString) {
|
256 | 239 | return logEventString.split(System.lineSeparator())[2];
|
257 | 240 | }
|
258 |
| - |
259 |
| - private void testLayoutWithDatePatternFixedFormat(final FixedFormat format, final String timezone) { |
260 |
| - final HtmlLayout layout = HtmlLayout.newBuilder() |
261 |
| - .setConfiguration(new DefaultConfiguration()) |
262 |
| - .setDatePattern(format.name()) |
263 |
| - .setTimezone(timezone) |
264 |
| - .build(); |
265 |
| - |
266 |
| - final LogEvent event = new MyLogEvent(); |
267 |
| - final String actual = getDateLine(layout.toSerializable(event)); |
268 |
| - |
269 |
| - // build expected date string |
270 |
| - final java.time.Instant instant = java.time.Instant.ofEpochSecond( |
271 |
| - event.getInstant().getEpochSecond(), event.getInstant().getNanoOfSecond()); |
272 |
| - ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); |
273 |
| - if (timezone != null) { |
274 |
| - zonedDateTime = zonedDateTime.withZoneSameInstant(ZoneId.of(timezone)); |
275 |
| - } |
276 |
| - |
277 |
| - // LOG4J2-3019 HtmlLayoutTest.testLayoutWithDatePatternFixedFormat test fails on windows |
278 |
| - // https://issues.apache.org/jira/browse/LOG4J2-3019 |
279 |
| - // java.time.format.DateTimeFormatterBuilder.toFormatter() defaults to using |
280 |
| - // Locale.getDefault(Locale.Category.FORMAT) |
281 |
| - final Locale formatLocale = Locale.getDefault(Locale.Category.FORMAT); |
282 |
| - final Locale locale = Locale.getDefault().equals(formatLocale) ? formatLocale : Locale.getDefault(); |
283 |
| - |
284 |
| - // For DateTimeFormatter of jdk, |
285 |
| - // Pattern letter 'S' means fraction-of-second, 'n' means nano-of-second. Log4j2 needs S. |
286 |
| - // Pattern letter 'X' (upper case) will output 'Z' when the offset to be output would be zero, |
287 |
| - // whereas pattern letter 'x' (lower case) will output '+00', '+0000', or '+00:00'. Log4j2 needs x. |
288 |
| - final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern( |
289 |
| - format.getPattern().replace('n', 'S').replace('X', 'x'), locale); |
290 |
| - String expected = zonedDateTime.format(dateTimeFormatter); |
291 |
| - |
292 |
| - final String offset = zonedDateTime.getOffset().toString(); |
293 |
| - |
294 |
| - // Truncate minutes if timeZone format is HH and timeZone has minutes. This is required because according to |
295 |
| - // DateTimeFormatter, |
296 |
| - // One letter outputs just the hour, such as '+01', unless the minute is non-zero in which case the minute is |
297 |
| - // also output, such as '+0130' |
298 |
| - // ref : https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html |
299 |
| - if (FixedDateFormat.FixedTimeZoneFormat.HH.equals(format.getTimeZoneFormat()) |
300 |
| - && offset.contains(":") |
301 |
| - && !"00".equals(offset.split(":")[1])) { |
302 |
| - expected = expected.substring(0, expected.length() - 2); |
303 |
| - } |
304 |
| - |
305 |
| - assertEquals( |
306 |
| - "<td>" + expected + "</td>", |
307 |
| - actual, |
308 |
| - MessageFormat.format("Incorrect date={0}, format={1}, timezone={2}", actual, format.name(), timezone)); |
309 |
| - } |
310 | 241 | }
|
0 commit comments