File tree Expand file tree Collapse file tree 3 files changed +21
-6
lines changed
cf-java-logging-support-log4j2/src/main/java/com/sap/hcp/cf/log4j2/converter
cf-java-logging-support-logback/src/main/java/com/sap/hcp/cf/logback/converter Expand file tree Collapse file tree 3 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 11package com .sap .hcp .cf .log4j2 .converter ;
22
3+ import java .time .Instant ;
4+
35import org .apache .logging .log4j .core .LogEvent ;
46import org .apache .logging .log4j .core .config .plugins .Plugin ;
57import org .apache .logging .log4j .core .pattern .ConverterKeys ;
68import org .apache .logging .log4j .core .pattern .LogEventPatternConverter ;
79
810@ Plugin (name = "TimestampConverter" , category = "Converter" )
911@ ConverterKeys ({ "tstamp" })
12+ /**
13+ * This is a simple {@link LogEventPatternConverter} implementation that prints
14+ * the timestamp as a long in nano second resolution. Note: nano second
15+ * precision is only available from Java 9 or newer. Java 8 will only have milli
16+ * seconds.
17+ */
1018public class TimestampConverter extends LogEventPatternConverter {
1119
1220 public static final String WORD = "tstamp" ;
@@ -21,7 +29,9 @@ public static TimestampConverter newInstance(final String[] options) {
2129
2230 @ Override
2331 public void format (LogEvent event , StringBuilder toAppendTo ) {
24- toAppendTo .append (System .currentTimeMillis () * 1000000 );
32+ Instant now = Instant .now ();
33+ long timestamp = now .getEpochSecond () * 1_000_000_000L + now .getNano ();
34+ toAppendTo .append (timestamp );
2535 }
2636
2737}
Original file line number Diff line number Diff line change 11package com .sap .hcp .cf .logback .converter ;
22
3+ import java .time .Instant ;
4+
35import ch .qos .logback .classic .pattern .ClassicConverter ;
46import ch .qos .logback .classic .spi .ILoggingEvent ;
57
68/**
7- * This is a simple {@link ClassicConverter} implementation that print the
8- * timestamp as a long in nano second resolution.
9+ * This is a simple {@link ClassicConverter} implementation that prints the
10+ * timestamp as a long in nano second resolution. Note: nano second precision is
11+ * only available from Java 9 or newer. Java 8 will only have milli seconds.
912 */
1013public class TimestampConverter extends ClassicConverter {
1114
@@ -14,7 +17,9 @@ public class TimestampConverter extends ClassicConverter {
1417 @ Override
1518 public String convert (ILoggingEvent event ) {
1619 StringBuilder appendTo = new StringBuilder ();
17- appendTo .append (System .currentTimeMillis () * 1000000 );
20+ Instant now = Instant .now ();
21+ long timestamp = now .getEpochSecond () * 1_000_000_000L + now .getNano ();
22+ appendTo .append (timestamp );
1823 return appendTo .toString ();
1924 }
2025
Original file line number Diff line number Diff line change 177177 <junit .version>4.13.1</junit .version>
178178 <mockito .version>1.9.5</mockito .version>
179179 <surefire .plugin.version>2.18.1</surefire .plugin.version>
180- <animal .sniffer.version>1.18 </animal .sniffer.version>
180+ <animal .sniffer.version>1.19 </animal .sniffer.version>
181181 <exec .plugin.version>1.4.0</exec .plugin.version>
182182 <javadoc .plugin.version>3.1.1</javadoc .plugin.version>
183183 <gpg .plugin.version>1.6</gpg .plugin.version>
268268 <configuration >
269269 <signature >
270270 <groupId >org.codehaus.mojo.signature</groupId >
271- <artifactId >java16 </artifactId >
271+ <artifactId >java18 </artifactId >
272272 <version >1.0</version >
273273 </signature >
274274 </configuration >
You can’t perform that action at this time.
0 commit comments