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 1
1
package com .sap .hcp .cf .log4j2 .converter ;
2
2
3
+ import java .time .Instant ;
4
+
3
5
import org .apache .logging .log4j .core .LogEvent ;
4
6
import org .apache .logging .log4j .core .config .plugins .Plugin ;
5
7
import org .apache .logging .log4j .core .pattern .ConverterKeys ;
6
8
import org .apache .logging .log4j .core .pattern .LogEventPatternConverter ;
7
9
8
10
@ Plugin (name = "TimestampConverter" , category = "Converter" )
9
11
@ 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
+ */
10
18
public class TimestampConverter extends LogEventPatternConverter {
11
19
12
20
public static final String WORD = "tstamp" ;
@@ -21,7 +29,9 @@ public static TimestampConverter newInstance(final String[] options) {
21
29
22
30
@ Override
23
31
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 );
25
35
}
26
36
27
37
}
Original file line number Diff line number Diff line change 1
1
package com .sap .hcp .cf .logback .converter ;
2
2
3
+ import java .time .Instant ;
4
+
3
5
import ch .qos .logback .classic .pattern .ClassicConverter ;
4
6
import ch .qos .logback .classic .spi .ILoggingEvent ;
5
7
6
8
/**
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.
9
12
*/
10
13
public class TimestampConverter extends ClassicConverter {
11
14
@@ -14,7 +17,9 @@ public class TimestampConverter extends ClassicConverter {
14
17
@ Override
15
18
public String convert (ILoggingEvent event ) {
16
19
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 );
18
23
return appendTo .toString ();
19
24
}
20
25
Original file line number Diff line number Diff line change 177
177
<junit .version>4.13.1</junit .version>
178
178
<mockito .version>1.9.5</mockito .version>
179
179
<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>
181
181
<exec .plugin.version>1.4.0</exec .plugin.version>
182
182
<javadoc .plugin.version>3.1.1</javadoc .plugin.version>
183
183
<gpg .plugin.version>1.6</gpg .plugin.version>
268
268
<configuration >
269
269
<signature >
270
270
<groupId >org.codehaus.mojo.signature</groupId >
271
- <artifactId >java16 </artifactId >
271
+ <artifactId >java18 </artifactId >
272
272
<version >1.0</version >
273
273
</signature >
274
274
</configuration >
You can’t perform that action at this time.
0 commit comments