@@ -134,14 +134,6 @@ public class LoggingHandlerTest {
134134 .addLabel ("levelValue" , String .valueOf (LoggingLevel .EMERGENCY .intValue ()))
135135 .setTimestamp (123456789L )
136136 .build ();
137- private static final ImmutableMap <String , String > NATIVE_SEVERITY_MAP =
138- ImmutableMap .of ("levelName" , Level .INFO .getName (), "levelValue" , Level .INFO .intValue () + "" );
139- private static final WriteOption [] DEFAULT_OPTION =
140- new WriteOption [] {
141- WriteOption .logName (LOG_NAME ),
142- WriteOption .resource (DEFAULT_RESOURCE ),
143- WriteOption .labels (NATIVE_SEVERITY_MAP )
144- };
145137 private static final String CONFIG_NAMESPACE = "com.google.cloud.logging.LoggingHandler" ;
146138 private static final ImmutableMap <String , String > CONFIG_MAP =
147139 ImmutableMap .<String , String >builder ()
@@ -155,8 +147,15 @@ public class LoggingHandlerTest {
155147 .put ("resourceType" , "testResourceType" )
156148 .put ("synchronicity" , "SYNC" )
157149 .build ();
150+ private static final ImmutableMap <String , String > NATIVE_SEVERITY_MAP =
151+ ImmutableMap .of (
152+ "levelName" , Level .INFO .getName (), "levelValue" , String .valueOf (Level .INFO .intValue ()));
158153 private static final WriteOption [] DEFAULT_OPTIONS =
159- new WriteOption [] {WriteOption .logName (LOG_NAME ), WriteOption .resource (DEFAULT_RESOURCE )};
154+ new WriteOption [] {
155+ WriteOption .logName (LOG_NAME ),
156+ WriteOption .resource (DEFAULT_RESOURCE ),
157+ WriteOption .labels (NATIVE_SEVERITY_MAP )
158+ };
160159
161160 private static byte [] renderConfig (Map <String , String > config ) {
162161 StringBuilder str = new StringBuilder ();
@@ -220,6 +219,8 @@ private static LogRecord newLogRecord(Level level, String message) {
220219
221220 @ Test
222221 public void testPublishLevels () {
222+ EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
223+ EasyMock .expect (options .getService ()).andReturn (logging );
223224 logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTIONS );
224225 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
225226 logging .writeAsync (ImmutableList .of (FINER_ENTRY ), DEFAULT_OPTIONS );
@@ -411,9 +412,7 @@ public void testSyncWrite() {
411412 .addLabel ("levelValue" , String .valueOf (Level .FINEST .intValue ()))
412413 .setTimestamp (123456789L )
413414 .build ();
414- logging .write (
415- ImmutableList .of (entry ),
416- DEFAULT_OPTIONS );
415+ logging .write (ImmutableList .of (entry ), DEFAULT_OPTIONS );
417416 EasyMock .replay (options , logging );
418417 LoggingHandler handler = new LoggingHandler (LOG_NAME , options );
419418 handler .setLevel (Level .ALL );
@@ -452,8 +451,6 @@ public void testPropertiesFile() throws IOException, InterruptedException {
452451 LogEntry entry =
453452 LogEntry .newBuilder (Payload .StringPayload .of (MESSAGE ))
454453 .setSeverity (Severity .DEBUG )
455- .addLabel ("levelName" , "FINEST" )
456- .addLabel ("levelValue" , String .valueOf (Level .FINEST .intValue ()))
457454 .addLabel ("enhanced" , "true" )
458455 .setTimestamp (123456789L )
459456 .build ();
@@ -462,7 +459,13 @@ public void testPropertiesFile() throws IOException, InterruptedException {
462459 WriteOption .logName ("testLogName" ),
463460 WriteOption .resource (
464461 MonitoredResource .of (
465- "testResourceType" , ImmutableMap .of ("project_id" , PROJECT , "enhanced" , "true" ))));
462+ "testResourceType" , ImmutableMap .of ("project_id" , PROJECT , "enhanced" , "true" ))),
463+ WriteOption .labels (
464+ ImmutableMap .of (
465+ "levelName" ,
466+ Level .FINEST .getName (),
467+ "levelValue" ,
468+ String .valueOf (Level .FINEST .intValue ()))));
466469 EasyMock .replay (options , logging );
467470 LogManager .getLogManager ()
468471 .readConfiguration (new ByteArrayInputStream (renderConfig (CONFIG_MAP )));
0 commit comments