-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bc956f
commit 912046f
Showing
7 changed files
with
155 additions
and
51 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
53 changes: 53 additions & 0 deletions
53
core/src/main/java/com/linecorp/armeria/server/AccessLogWriterUtil.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,53 @@ | ||
/* | ||
* Copyright 2024 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; | ||
|
||
import com.linecorp.armeria.common.util.SafeCloseable; | ||
import com.linecorp.armeria.server.logging.AccessLogWriter; | ||
|
||
/** | ||
* Utility class for {@link AccessLogWriter}. | ||
*/ | ||
final class AccessLogWriterUtil { | ||
|
||
/** | ||
* Writes an access log if the {@link TransientServiceOption#WITH_ACCESS_LOGGING} option is enabled | ||
* for the {@link ServiceConfig#transientServiceOptions()} and the {@link ServiceConfig#accessLogWriter()} | ||
* is not {@link AccessLogWriter#DISABLED} for the given {@link ServiceRequestContext#config()}. | ||
*/ | ||
static void maybeWriteAccessLog(ServiceRequestContext reqCtx) { | ||
final ServiceConfig config = reqCtx.config(); | ||
if (shouldWriteAccessLog(config)) { | ||
reqCtx.log().whenComplete().thenAccept(log -> { | ||
try (SafeCloseable ignored = reqCtx.push()) { | ||
config.accessLogWriter().log(log); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Returns whether an access log should be written. | ||
* | ||
*/ | ||
private static boolean shouldWriteAccessLog(ServiceConfig config) { | ||
return config.accessLogWriter() != AccessLogWriter.DISABLED && | ||
config.transientServiceOptions().contains(TransientServiceOption.WITH_ACCESS_LOGGING); | ||
} | ||
|
||
private AccessLogWriterUtil() {} | ||
} |
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