-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug that default logger is changed for LoggingService and Loggi…
…ngClient (#5056) Motivation I changed the default logger of `LoggingService` from `com.linecorp.armeria.server.logging.LoggingService` to `com.linecorp.armeria.common.logging.DefaultLogWriter` in #4943. This caused a breaking change to logging system if you are using the class name with a logger. This also applies to the `LoggingClient`. We should fix it. Modification - Reverted to use `com.linecorp.armeria.server.logging.LoggingService` logger for `LoggingService` when `LogWriter` isn't set. - Reverted to use `com.linecorp.armeria.client.logging.LoggingClient` logger for `LoggingClient` when `LogWriter` isn't set. Result - As in versions prior to 1.24.0, the default logger for `LoggingService` is now `com.linecorp.armeria.server.logging.LoggingService`. - The default logger for `LoggingClient` is also `com.linecorp.armeria.client.logging.LoggingClient`.
- Loading branch information
Showing
12 changed files
with
186 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
core/src/test/java/com/linecorp/armeria/client/logging/LoggingClientDefaultLoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linecorp.armeria.client.logging; | ||
|
||
import static com.linecorp.armeria.client.logging.LoggingClientTest.delegate; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Spy; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.linecorp.armeria.client.ClientRequestContext; | ||
import com.linecorp.armeria.common.HttpMethod; | ||
import com.linecorp.armeria.common.HttpRequest; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
|
||
class LoggingClientDefaultLoggerTest { | ||
|
||
@Spy | ||
final ListAppender<ILoggingEvent> logAppender = new ListAppender<>(); | ||
final Logger defaultLogger = (Logger) LoggerFactory.getLogger(LoggingClient.class); | ||
|
||
@BeforeEach | ||
public void attachAppender() { | ||
logAppender.start(); | ||
defaultLogger.addAppender(logAppender); | ||
} | ||
|
||
@AfterEach | ||
public void detachAppender() { | ||
defaultLogger.detachAppender(logAppender); | ||
logAppender.list.clear(); | ||
} | ||
|
||
@Test | ||
void defaultLoggerUsedIfLogWriterNotSet() throws Exception { | ||
final ClientRequestContext ctx = ClientRequestContext.of(HttpRequest.of(HttpMethod.GET, "/")); | ||
final LoggingClient client = LoggingClient.newDecorator().apply(delegate); | ||
client.execute(ctx, ctx.request()); | ||
assertThat(logAppender.list).hasSize(2); | ||
logAppender.list.forEach(iLoggingEvent -> { | ||
assertThat(iLoggingEvent.getFormattedMessage()).contains(ctx.toString()); | ||
assertThat(iLoggingEvent.getLoggerName()).isEqualTo( | ||
"com.linecorp.armeria.client.logging.LoggingClient"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
core/src/test/java/com/linecorp/armeria/server/logging/LoggingServiceDefaultLoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you under the Apache License, | ||
* version 2.0 (the "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at: | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package com.linecorp.armeria.server.logging; | ||
|
||
import static com.linecorp.armeria.server.logging.LoggingServiceTest.delegate; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Spy; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.linecorp.armeria.common.HttpMethod; | ||
import com.linecorp.armeria.common.HttpRequest; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
|
||
class LoggingServiceDefaultLoggerTest { | ||
|
||
@Spy | ||
final ListAppender<ILoggingEvent> logAppender = new ListAppender<>(); | ||
final Logger defaultLogger = (Logger) LoggerFactory.getLogger(LoggingService.class); | ||
|
||
@BeforeEach | ||
public void attachAppender() { | ||
logAppender.start(); | ||
defaultLogger.addAppender(logAppender); | ||
} | ||
|
||
@AfterEach | ||
public void detachAppender() { | ||
defaultLogger.detachAppender(logAppender); | ||
logAppender.list.clear(); | ||
} | ||
|
||
@Test | ||
void defaultLoggerUsedIfLogWriterNotSet() throws Exception { | ||
final ServiceRequestContext ctx = ServiceRequestContext.of(HttpRequest.of(HttpMethod.GET, "/")); | ||
final LoggingService service = LoggingService.newDecorator().apply(delegate); | ||
service.serve(ctx, ctx.request()); | ||
assertThat(logAppender.list).hasSize(2); | ||
logAppender.list.forEach(iLoggingEvent -> { | ||
assertThat(iLoggingEvent.getFormattedMessage()).contains(ctx.toString()); | ||
assertThat(iLoggingEvent.getLoggerName()).isEqualTo( | ||
"com.linecorp.armeria.server.logging.LoggingService"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters