author | dfuchs |
Wed, 25 Feb 2015 18:41:07 +0100 | |
changeset 29117 | 7956b5dc0eac |
permissions | -rw-r--r-- |
29117
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
1 |
/* |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
4 |
* |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
8 |
* |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
14 |
* |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
18 |
* |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
22 |
*/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
23 |
import java.time.Instant; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
24 |
import java.time.ZoneId; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
25 |
import java.time.ZonedDateTime; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
26 |
import java.util.Locale; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
27 |
import java.util.logging.Level; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
28 |
import java.util.logging.LogRecord; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
29 |
import java.util.logging.SimpleFormatter; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
30 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
31 |
/** |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
32 |
* @test |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
33 |
* @bug 8072645 |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
34 |
* @summary tests that SimpleFormatter can print out dates with the new |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
35 |
* nanosecond precision. |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
36 |
* @run main/othervm SimpleFormatterNanos |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
37 |
* @author danielfuchs |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
38 |
*/ |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
39 |
public class SimpleFormatterNanos { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
40 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
41 |
static final int MILLIS_IN_SECOND = 1000; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
42 |
static final int NANOS_IN_MILLI = 1000_000; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
43 |
static final int NANOS_IN_MICRO = 1000; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
44 |
static final int NANOS_IN_SECOND = 1000_000_000; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
45 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
46 |
static final boolean verbose = true; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
47 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
48 |
static final class TestAssertException extends RuntimeException { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
49 |
TestAssertException(String msg) { super(msg); } |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
50 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
51 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
52 |
private static void assertEquals(long expected, long received, String msg) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
53 |
if (expected != received) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
54 |
throw new TestAssertException("Unexpected result for " + msg |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
55 |
+ ".\n\texpected: " + expected |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
56 |
+ "\n\tactual: " + received); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
57 |
} else if (verbose) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
58 |
System.out.println("Got expected " + msg + ": " + received); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
59 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
60 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
61 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
62 |
static int getNanoAdjustment(LogRecord record) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
63 |
return record.getInstant().getNano() % NANOS_IN_MILLI; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
64 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
65 |
static void setNanoAdjustment(LogRecord record, int nanos) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
66 |
record.setInstant(Instant.ofEpochSecond(record.getInstant().getEpochSecond(), |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
67 |
(record.getInstant().getNano() / NANOS_IN_MILLI) * NANOS_IN_MILLI + nanos)); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
68 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
69 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
70 |
public static void main(String[] args) throws Exception { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
71 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
72 |
Locale.setDefault(Locale.ENGLISH); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
73 |
LogRecord record = new LogRecord(Level.INFO, "Java Version: {0}"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
74 |
record.setLoggerName("test"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
75 |
record.setParameters(new Object[] {System.getProperty("java.version")}); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
76 |
int nanos = getNanoAdjustment(record); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
77 |
long millis = record.getMillis(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
78 |
// make sure we don't have leading zeros when printing below |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
79 |
// the second precision |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
80 |
if (millis % MILLIS_IN_SECOND < 100) millis = millis + 100; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
81 |
// make sure we have some nanos |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
82 |
if (nanos % NANOS_IN_MICRO == 0) nanos = nanos + 999; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
83 |
record.setMillis(millis); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
84 |
setNanoAdjustment(record, nanos); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
85 |
final Instant instant = record.getInstant(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
86 |
if (nanos < 0) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
87 |
throw new RuntimeException("Unexpected negative nano adjustment: " |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
88 |
+ getNanoAdjustment(record)); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
89 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
90 |
if (nanos >= NANOS_IN_MILLI) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
91 |
throw new RuntimeException("Nano adjustment exceeds 1ms: " |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
92 |
+ getNanoAdjustment(record)); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
93 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
94 |
if (millis != record.getMillis()) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
95 |
throw new RuntimeException("Unexpected millis: " + millis + " != " |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
96 |
+ record.getMillis()); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
97 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
98 |
if (millis != record.getInstant().toEpochMilli()) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
99 |
throw new RuntimeException("Unexpected millis: " |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
100 |
+ record.getInstant().toEpochMilli()); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
101 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
102 |
ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault()); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
103 |
int zdtNanos = zdt.getNano(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
104 |
long expectedNanos = (millis % MILLIS_IN_SECOND) * NANOS_IN_MILLI + nanos; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
105 |
assertEquals(expectedNanos, instant.getNano(), "Instant.getNano()"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
106 |
assertEquals(expectedNanos, zdtNanos, "ZonedDateTime.getNano()"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
107 |
String match = "."+expectedNanos+" "; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
108 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
109 |
System.out.println("Testing with default format..."); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
110 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
111 |
SimpleFormatter formatter = new SimpleFormatter(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
112 |
String str = formatter.format(record); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
113 |
if (str.contains(match)) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
114 |
throw new RuntimeException("SimpleFormatter.format()" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
115 |
+ " string contains unexpected nanos: " |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
116 |
+ "\n\tdid not expect match for: '" + match + "'" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
117 |
+ "\n\tin: " + str); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
118 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
119 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
120 |
System.out.println("Nanos omitted as expected: no '"+match+"' in "+str); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
121 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
122 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
123 |
System.out.println("Changing format to print nanos..."); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
124 |
System.setProperty("java.util.logging.SimpleFormatter.format", |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
125 |
"%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS.%1$tN %1$Tp %2$s%n%4$s: %5$s%6$s%n"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
126 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
127 |
SimpleFormatter formatter2 = new SimpleFormatter(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
128 |
str = formatter2.format(record); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
129 |
if (!str.contains(match)) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
130 |
throw new RuntimeException("SimpleFormatter.format()" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
131 |
+ " string does not contain expected nanos: " |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
132 |
+ "\n\texpected match for: '" + match + "'" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
133 |
+ "\n\tin: " + str); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
134 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
135 |
System.out.println("Found expected match for '"+match+"' in "+str); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
136 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
137 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
138 |
System.out.println("Changing format to omit nanos..."); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
139 |
System.setProperty("java.util.logging.SimpleFormatter.format", |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
140 |
"%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%6$s%n"); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
141 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
142 |
SimpleFormatter formatter3 = new SimpleFormatter(); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
143 |
str = formatter3.format(record); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
144 |
String notMatch = match; |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
145 |
if (str.contains(notMatch)) { |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
146 |
throw new RuntimeException("SimpleFormatter.format()" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
147 |
+ " string contains unexpected nanos: " |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
148 |
+ "\n\tdid not expect match for: '" + notMatch + "'" |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
149 |
+ "\n\tin: " + str); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
150 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
151 |
System.out.println("Nanos omitted as expected: no '"+notMatch+"' in "+str); |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
152 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
153 |
} |
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
154 |
|
7956b5dc0eac
8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents:
diff
changeset
|
155 |
} |