1414 * limitations under the License.
1515 */
1616
17- package com .google .cloud .logging ;
17+ package com .google .cloud .logging . logback ;
1818
1919import static org .mockito .ArgumentMatchers .any ;
2020import static org .mockito .Mockito .doReturn ;
2828import ch .qos .logback .classic .spi .LoggingEvent ;
2929import com .google .cloud .MonitoredResource ;
3030import com .google .cloud .Timestamp ;
31+ import com .google .cloud .logging .LogEntry ;
32+ import com .google .cloud .logging .Logging ;
3133import com .google .cloud .logging .Logging .WriteOption ;
34+ import com .google .cloud .logging .Payload ;
35+ import com .google .cloud .logging .Severity ;
3236import com .google .common .collect .ImmutableMap ;
3337import org .junit .Before ;
3438import org .junit .Test ;
3842import java .util .Collections ;
3943
4044@ RunWith (MockitoJUnitRunner .class )
41- public class LogbackAppenderTest {
45+ public class LoggingAppenderTest {
4246
4347 private final String projectId = "test-project" ;
4448
45- private final LogbackAppender logbackAppender = spy (LogbackAppender .class );
49+ private final LoggingAppender loggingAppender = spy (LoggingAppender .class );
4650 private final Logging logging = mock (Logging .class );
4751 private final WriteOption [] defaultWriteOptions = new WriteOption [] {
4852 WriteOption .logName ("java.log" ),
@@ -54,19 +58,19 @@ public class LogbackAppenderTest {
5458
5559 @ Before
5660 public void setUp () {
57- doReturn (logging ).when (logbackAppender ).getLogging ();
58- doReturn ("test-project" ).when (logbackAppender ).getProjectId ();
59- logbackAppender .start ();
61+ doReturn (logging ).when (loggingAppender ).getLogging ();
62+ doReturn ("test-project" ).when (loggingAppender ).getProjectId ();
63+ loggingAppender .start ();
6064 }
6165
6266 @ Test
6367 public void testFlushLevelConfigUpdatesLoggingFlushSeverity () {
6468 Timestamp timestamp = Timestamp .ofTimeSecondsAndNanos (100000 , 0 );
6569 LoggingEvent loggingEvent = createLoggingEvent (Level .WARN , timestamp .getSeconds ());
6670 // error is the default, updating to debug for test
67- logbackAppender .setFlushLevel (Level .WARN );
68- logbackAppender .start (); // reloading config
69- logbackAppender .doAppend (loggingEvent );
71+ loggingAppender .setFlushLevel (Level .WARN );
72+ loggingAppender .start (); // reloading config
73+ loggingAppender .doAppend (loggingEvent );
7074 verify (logging , times (1 )).setFlushSeverity (Severity .WARNING );
7175 }
7276
@@ -78,22 +82,22 @@ public void testFilterLogsOnlyLogsAtOrAboveLogLevel() {
7882 ThresholdFilter thresholdFilter = new ThresholdFilter ();
7983 thresholdFilter .setLevel ("ERROR" );
8084 thresholdFilter .start ();
81- logbackAppender .addFilter (thresholdFilter );
82- logbackAppender .doAppend (loggingEvent1 );
85+ loggingAppender .addFilter (thresholdFilter );
86+ loggingAppender .doAppend (loggingEvent1 );
8387 verify (logging , times (0 )).write (any (Iterable .class ), any (WriteOption .class ));
8488 LoggingEvent loggingEvent2 = createLoggingEvent (Level .ERROR , timestamp .getSeconds ());
85- logbackAppender .doAppend (loggingEvent2 );
89+ loggingAppender .doAppend (loggingEvent2 );
8690 verify (logging , times (1 )).write (any (Iterable .class ), any (WriteOption .class ));
8791 }
8892
8993 @ Test
9094 public void testEnhancersAddCorrectLabelsToLogEntries () {
91- logbackAppender .setEnhancers ("com.example.enhancers.TestLoggingEnhancer," +
95+ loggingAppender .setEnhancers ("com.example.enhancers.TestLoggingEnhancer," +
9296 "com.example.enhancers.AnotherTestLoggingEnhancer" );
93- logbackAppender .start ();
97+ loggingAppender .start ();
9498 Timestamp timestamp = Timestamp .ofTimeSecondsAndNanos (100000 , 0 );
9599 LoggingEvent loggingEvent = createLoggingEvent (Level .WARN , timestamp .getSeconds ());
96- logbackAppender .doAppend (loggingEvent );
100+ loggingAppender .doAppend (loggingEvent );
97101 verify (logging , times (1 )).write (
98102 Collections .singleton (
99103 LogEntry .newBuilder (Payload .StringPayload .of ("this is a test" ))
@@ -112,7 +116,7 @@ public void testEnhancersAddCorrectLabelsToLogEntries() {
112116 public void testLogEntryLevelAndLabelsAreAsExpected () {
113117 Timestamp timestamp = Timestamp .ofTimeSecondsAndNanos (100000 , 0 );
114118 LoggingEvent loggingEvent = createLoggingEvent (Level .ERROR , timestamp .getSeconds ());
115- logbackAppender .doAppend (loggingEvent );
119+ loggingAppender .doAppend (loggingEvent );
116120 verify (logging ).write (
117121 Collections .singleton (
118122 LogEntry .newBuilder (Payload .StringPayload .of ("this is a test" ))
0 commit comments