2222import com .google .cloud .logging .Logging .WriteOption ;
2323import com .google .common .collect .ImmutableList ;
2424import com .google .common .collect .ImmutableMap ;
25+ import java .time .Instant ;
2526import java .util .Collections ;
2627import java .util .LinkedList ;
2728import java .util .List ;
4243 * Cloud Logging severities:
4344 *
4445 * <table summary="Mapping of Java logging level to Cloud Logging severities">
45- * <tr><th width="50%">Java Level</th><th>Cloud Logging Severity</th></tr>
46- * <tr><td>SEVERE</td><td>ERROR</td></tr>
47- * <tr><td>WARNING</td><td>WARNING</td></tr>
48- * <tr><td>INFO</td><td>INFO</td></tr>
49- * <tr><td>CONFIG</td><td>INFO</td></tr>
50- * <tr><td>FINE</td><td>DEBUG</td></tr>
51- * <tr><td>FINER</td><td>DEBUG</td></tr>
52- * <tr><td>FINEST</td><td>DEBUG</td></tr>
46+ * <tr>
47+ * <th width="50%">Java Level</th>
48+ * <th>Cloud Logging Severity</th>
49+ * </tr>
50+ * <tr>
51+ * <td>SEVERE</td>
52+ * <td>ERROR</td>
53+ * </tr>
54+ * <tr>
55+ * <td>WARNING</td>
56+ * <td>WARNING</td>
57+ * </tr>
58+ * <tr>
59+ * <td>INFO</td>
60+ * <td>INFO</td>
61+ * </tr>
62+ * <tr>
63+ * <td>CONFIG</td>
64+ * <td>INFO</td>
65+ * </tr>
66+ * <tr>
67+ * <td>FINE</td>
68+ * <td>DEBUG</td>
69+ * </tr>
70+ * <tr>
71+ * <td>FINER</td>
72+ * <td>DEBUG</td>
73+ * </tr>
74+ * <tr>
75+ * <td>FINEST</td>
76+ * <td>DEBUG</td>
77+ * </tr>
5378 * </table>
5479 *
5580 * <p>Original Java logging levels are added as labels (with {@code levelName} and {@code
94119 */
95120public class LoggingHandler extends Handler {
96121
97- private static final String HANDLERS_PROPERTY = "handlers" ;
98- private static final String ROOT_LOGGER_NAME = "" ;
99- private static final String [] NO_HANDLERS = new String [0 ];
100122 private static final String LEVEL_NAME_KEY = "levelName" ;
101123 private static final String LEVEL_VALUE_KEY = "levelValue" ;
102124
@@ -105,8 +127,10 @@ public class LoggingHandler extends Handler {
105127
106128 private volatile Logging logging ;
107129
108- // Logs with the same severity with the base could be more efficiently sent to Cloud.
109- // Defaults to level of the handler or Level.FINEST if the handler is set to Level.ALL.
130+ // Logs with the same severity with the base could be more efficiently sent to
131+ // Cloud.
132+ // Defaults to level of the handler or Level.FINEST if the handler is set to
133+ // Level.ALL.
110134 // Currently there is no way to modify the base level, see
111135 // https://github.com/googleapis/google-cloud-java/issues/1740 .
112136 private final Level baseLevel ;
@@ -204,7 +228,8 @@ public LoggingHandler(
204228
205229 this .enhancers .addAll (enhancersParam );
206230
207- // In the following line getResourceEnhancers() never returns null (@NotNull attribute)
231+ // In the following line getResourceEnhancers() never returns null (@NotNull
232+ // attribute)
208233 List <LoggingEnhancer > loggingEnhancers = MonitoredResourceUtil .getResourceEnhancers ();
209234 this .enhancers .addAll (loggingEnhancers );
210235 } catch (Exception ex ) {
@@ -219,8 +244,10 @@ public void publish(LogRecord record) {
219244 if (!isLoggable (record )) {
220245 return ;
221246 }
222- // HACK warning: this logger doesn't work like normal loggers; the log calls are issued
223- // from another class instead of by itself, so it can't be configured off like normal
247+ // HACK warning: this logger doesn't work like normal loggers; the log calls are
248+ // issued
249+ // from another class instead of by itself, so it can't be configured off like
250+ // normal
224251 // loggers. We have to check the source class name instead.
225252 if ("io.netty.handler.codec.http2.Http2FrameLogger" .equals (record .getSourceClassName ())) {
226253 return ;
@@ -246,7 +273,7 @@ private LogEntry logEntryFor(LogRecord record) throws Exception {
246273 Level level = record .getLevel ();
247274 LogEntry .Builder builder =
248275 LogEntry .newBuilder (Payload .StringPayload .of (payload ))
249- .setTimestamp (record .getMillis ())
276+ .setTimestamp (Instant . ofEpochMilli ( record .getMillis () ))
250277 .setSeverity (severityFor (level ));
251278
252279 if (!baseLevel .equals (level )) {
0 commit comments