-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#10539): When the operation configuration fails, log.
- Loading branch information
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
config/src/main/java/com/alibaba/nacos/config/server/aspect/ConfigOpFailureAspect.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,70 @@ | ||
/* | ||
* Copyright 1999-2022 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.alibaba.nacos.config.server.aspect; | ||
|
||
import com.alibaba.nacos.config.server.utils.LogUtil; | ||
import org.aspectj.lang.JoinPoint; | ||
import org.aspectj.lang.annotation.AfterThrowing; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.slf4j.Logger; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* The pointcut for configuration change operations, it will log when the configuration change fails. | ||
* | ||
* @author blake.qiu | ||
*/ | ||
@Aspect | ||
@Component | ||
public class ConfigOpFailureAspect { | ||
|
||
private static final Logger LOGGER = LogUtil.DEFAULT_LOG; | ||
|
||
/** | ||
* Pointcut for all methods from 'configRepositoryInterface'. | ||
*/ | ||
@Pointcut("within(com.alibaba.nacos.config.server.service.repository..*)") | ||
public void configRepositoryInterfaceMethods() { | ||
} | ||
|
||
/** | ||
* Log message when a method from 'configRepositoryInterface' throws an exception. | ||
*/ | ||
@AfterThrowing(pointcut = "configRepositoryInterfaceMethods()", throwing = "exception") | ||
public void logException(JoinPoint joinPoint, Throwable exception) { | ||
try { | ||
Object[] args = joinPoint.getArgs(); | ||
StringBuilder params = new StringBuilder(); | ||
if (args != null) { | ||
for (int i = 0; i < args.length; i++) { | ||
if (i < args.length - 1) { | ||
params.append(args[i]).append(", "); | ||
} else { | ||
params.append(args[i]); | ||
} | ||
} | ||
} | ||
String methodName = joinPoint.getSignature().getName(); | ||
LOGGER.error("An error occurred while executing method [{}].\n Parameters: [{}].", methodName, params, | ||
exception); | ||
} catch (Exception e) { | ||
LOGGER.error("An error occurred while logging the original exception. method [{}]", | ||
joinPoint.getSignature().getName(), e); | ||
} | ||
} | ||
} |