From 5bd79bf8f905ff63a2e6e4f60c3aab0bf0cce34c Mon Sep 17 00:00:00 2001 From: = Date: Tue, 30 Nov 2021 10:21:39 +0800 Subject: [PATCH 1/8] add dynamically adjust log level --- .../examples/{log => telemetry}/DemoLog.java | 70 +- pom.xml | 826 +++++++++--------- sdk-component/pom.xml | 7 + .../log/agent/CapaLog4jAppenderAgent.java | 1 + .../log/agent/CapaLogbackAppenderAgent.java | 157 ++-- .../telemetry/log/manager/CapaLogLevel.java | 30 + .../telemetry/log/manager/LogsManager.java | 9 + 7 files changed, 575 insertions(+), 525 deletions(-) rename examples/src/main/java/group/rxcloud/capa/examples/{log => telemetry}/DemoLog.java (95%) create mode 100644 sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/CapaLogLevel.java create mode 100644 sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/LogsManager.java diff --git a/examples/src/main/java/group/rxcloud/capa/examples/log/DemoLog.java b/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java similarity index 95% rename from examples/src/main/java/group/rxcloud/capa/examples/log/DemoLog.java rename to examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java index 20ac7e2..e75463b 100644 --- a/examples/src/main/java/group/rxcloud/capa/examples/log/DemoLog.java +++ b/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java @@ -1,35 +1,35 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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 - * - * 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 group.rxcloud.capa.examples.log; - -import lombok.extern.slf4j.Slf4j; - -/** - * An application cannot use log4j and logback configuration to print logs at the same time. - * So if you want to test the log4j2 configuration to print logs, then you need to copy the resources/xml/log4j2.xml file to the resources directory, and then add log4j-slf4j-impl dependency to the pom file. - * Else if you want to use logback configuration to print logs, then the resources/xml/logback.xml file needs to be copied to the resources path, and the logback-classic dependency needs to be added to the pom file. - * Notice: - * 1. Resources cannot contain log4j2.xml and logback.xml files at the same time, - * 2. log4j-slf4j-impl and logback-classic cannot exist at the same time. - */ -@Slf4j -public class DemoLog { - - public static void main(String[] args) { - log.info("test"); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 + * + * 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 group.rxcloud.capa.examples.telemetry; + +import lombok.extern.slf4j.Slf4j; + +/** + * An application cannot use log4j and logback configuration to print logs at the same time. + * So if you want to test the log4j2 configuration to print logs, then you need to copy the resources/xml/log4j2.xml file to the resources directory, and then add log4j-slf4j-impl dependency to the pom file. + * Else if you want to use logback configuration to print logs, then the resources/xml/logback.xml file needs to be copied to the resources path, and the logback-classic dependency needs to be added to the pom file. + * Notice: + * 1. Resources cannot contain log4j2.xml and logback.xml files at the same time, + * 2. log4j-slf4j-impl and logback-classic cannot exist at the same time. + */ +@Slf4j +public class DemoLog { + + public static void main(String[] args) { + log.info("test"); + } +} diff --git a/pom.xml b/pom.xml index c45dd65..546f707 100644 --- a/pom.xml +++ b/pom.xml @@ -1,414 +1,414 @@ - - - - 4.0.0 - - group.rxcloud - capa-parent - pom - 1.0.7-beta-2 - capa-sdk-parent - SDK for Capa. - https://github.com/reactivegroup - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - kevinten10 - 596823919@qq.com - - - - - scm:git:git@github.com:reactivegroup/capa.git - scm:git:git@github.com:reactivegroup/capa.git - git@github.com:reactivegroup/capa.git - - - - - ossrh - https://s01.oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - examples - sdk-springboot - sdk-spi-demo - sdk-spi - sdk - sdk-component - sdk-infrastructure - - - - 8 - UTF-8 - 3.8.1 - 1.0.8.RELEASE - 3.3.22.RELEASE - 1.7.21 - 1.9.0 - 1.9.0-alpha - - 5.3.1 - 3.6.0 - 3.1.2 - 0.13 - 2.7 - 3.2.0 - 3.0.0-M1 - 0.8.6 - true - true - true - - - - - - - group.rxcloud - capa-sdk-spi-demo - ${project.version} - - - group.rxcloud - capa-sdk-spi - ${project.version} - - - group.rxcloud - capa-sdk - ${project.version} - - - group.rxcloud - capa-sdk-component - ${project.version} - - - group.rxcloud - capa-sdk-infrastructure - ${project.version} - - - - - group.rxcloud - cloud-runtimes-api - ${cloud-runtimes.version} - - - - - io.projectreactor - reactor-core - ${reactor-core.version} - true - - - - - org.slf4j - slf4j-api - ${slf4j.version} - - - - - io.opentelemetry - opentelemetry-api - ${open.telemetry.version} - - - io.opentelemetry - opentelemetry-api-metrics - ${open.telemetry.version.alpha} - - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - - - org.mockito - mockito-core - ${mockito-core.version} - test - - - - - - - - jacoco - - false - - - - - rat - - false - - - - - checkstyle - - false - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven.version} - - ${java.version} - ${java.version} - ${file.encoding} - - - - org.apache.maven.plugins - maven-resources-plugin - ${maven.resources.version} - - UTF-8 - - - - copy-checkstyle - validate - - copy-resources - - - ${basedir}/target/codestyle - - - ${basedir}/codestyle - - * - - - - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${checkstyle.version} - - - com.puppycrawl.tools - checkstyle - 8.41 - - - - - checkstyle-validation - validate - - codestyle/checkstyle.xml - codestyle/checkstyle-suppressions.xml - UTF-8 - true - true - ${checkstyle.skip} - - **/generated/**/*, - **/target/**/*, - **/*.json - **/*.sh - - - - check - - - - - - org.apache.rat - apache-rat-plugin - ${apache.rat.version} - - - rat-validate - validate - - check - - - - - - **/*.versionsBackup - **/.idea/ - **/*.iml - **/*.txt - **/*.load - **/*.flex - **/*.fc - **/*.properties - **/*.sh - **/*.bat - **/*.md - .git/ - .gitignore - - .repository/ - **/.settings/* - **/.classpath - **/.project - **/target/** - **/*.log - .codecov.yml - .travis.yml - PULL_REQUEST_TEMPLATE.md - CONTRIBUTING.md - README.md - Jenkinsfile - **/codestyle/* - **/resources/META-INF/** - .github/** - codestyle/** - docs/** - spec/** - **/generated/** - **/*.json - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.maven.version} - - - html - xml - - - - - - org.jacoco - jacoco-maven-plugin - ${maven.jacoco.version} - - - - prepare-agent - - prepare-agent - - - - - generate-report - - report - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.2.0 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ossrh - https://s01.oss.sonatype.org/ - true - - - - - + + + + 4.0.0 + + group.rxcloud + capa-parent + pom + 1.0.7-beta-3 + capa-sdk-parent + SDK for Capa. + https://github.com/reactivegroup + + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + kevinten10 + 596823919@qq.com + + + + + scm:git:git@github.com:reactivegroup/capa.git + scm:git:git@github.com:reactivegroup/capa.git + git@github.com:reactivegroup/capa.git + + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + examples + sdk-springboot + sdk-spi-demo + sdk-spi + sdk + sdk-component + sdk-infrastructure + + + + 8 + UTF-8 + 3.8.1 + 1.0.8.RELEASE + 3.3.22.RELEASE + 1.7.21 + 1.9.0 + 1.9.0-alpha + + 5.3.1 + 3.6.0 + 3.1.2 + 0.13 + 2.7 + 3.2.0 + 3.0.0-M1 + 0.8.6 + true + true + true + + + + + + + group.rxcloud + capa-sdk-spi-demo + ${project.version} + + + group.rxcloud + capa-sdk-spi + ${project.version} + + + group.rxcloud + capa-sdk + ${project.version} + + + group.rxcloud + capa-sdk-component + ${project.version} + + + group.rxcloud + capa-sdk-infrastructure + ${project.version} + + + + + group.rxcloud + cloud-runtimes-api + ${cloud-runtimes.version} + + + + + io.projectreactor + reactor-core + ${reactor-core.version} + true + + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + + io.opentelemetry + opentelemetry-api + ${open.telemetry.version} + + + io.opentelemetry + opentelemetry-api-metrics + ${open.telemetry.version.alpha} + + + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.mockito + mockito-core + ${mockito-core.version} + test + + + + + + + + jacoco + + false + + + + + rat + + false + + + + + checkstyle + + false + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.version} + + ${java.version} + ${java.version} + ${file.encoding} + + + + org.apache.maven.plugins + maven-resources-plugin + ${maven.resources.version} + + UTF-8 + + + + copy-checkstyle + validate + + copy-resources + + + ${basedir}/target/codestyle + + + ${basedir}/codestyle + + * + + + + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${checkstyle.version} + + + com.puppycrawl.tools + checkstyle + 8.41 + + + + + checkstyle-validation + validate + + codestyle/checkstyle.xml + codestyle/checkstyle-suppressions.xml + UTF-8 + true + true + ${checkstyle.skip} + + **/generated/**/*, + **/target/**/*, + **/*.json + **/*.sh + + + + check + + + + + + org.apache.rat + apache-rat-plugin + ${apache.rat.version} + + + rat-validate + validate + + check + + + + + + **/*.versionsBackup + **/.idea/ + **/*.iml + **/*.txt + **/*.load + **/*.flex + **/*.fc + **/*.properties + **/*.sh + **/*.bat + **/*.md + .git/ + .gitignore + + .repository/ + **/.settings/* + **/.classpath + **/.project + **/target/** + **/*.log + .codecov.yml + .travis.yml + PULL_REQUEST_TEMPLATE.md + CONTRIBUTING.md + README.md + Jenkinsfile + **/codestyle/* + **/resources/META-INF/** + .github/** + codestyle/** + docs/** + spec/** + **/generated/** + **/*.json + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.maven.version} + + + html + xml + + + + + + org.jacoco + jacoco-maven-plugin + ${maven.jacoco.version} + + + + prepare-agent + + prepare-agent + + + + + generate-report + + report + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + + \ No newline at end of file diff --git a/sdk-component/pom.xml b/sdk-component/pom.xml index 714aee9..895a561 100644 --- a/sdk-component/pom.xml +++ b/sdk-component/pom.xml @@ -98,6 +98,13 @@ true ${logback.version} + + ch.qos.logback + logback-classic + + true + ${logback.version} + org.junit.jupiter diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLog4jAppenderAgent.java b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLog4jAppenderAgent.java index 4cdf775..74ff0f3 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLog4jAppenderAgent.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLog4jAppenderAgent.java @@ -97,6 +97,7 @@ public static CapaLog4jAppender buildCapaLog4jAppender() { @Override public void append(LogEvent event) { + event.getLevel(); logAppender.appendLog(event); } diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLogbackAppenderAgent.java b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLogbackAppenderAgent.java index 31c7423..3c84ae7 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLogbackAppenderAgent.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/agent/CapaLogbackAppenderAgent.java @@ -1,77 +1,80 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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 - * - * 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 group.rxcloud.capa.component.telemetry.log.agent; - -import ch.qos.logback.core.UnsynchronizedAppenderBase; -import group.rxcloud.capa.infrastructure.CapaClassLoader; - -/** - * The agent of the logback impl. - */ -public class CapaLogbackAppenderAgent extends UnsynchronizedAppenderBase { - - /** - * The log component type. - */ - private static final String LOG_COMPONENT_TYPE = "log"; - /** - * Capa logback appender instance. - */ - private static final CapaLogbackAppender logbackAppender; - - /** - * Init the logbackAppender impl. - */ - static { - logbackAppender = buildCapaLogbackAppender(); - } - - /** - * Build the logback appender impl. - * - * @return CapaLogbackAppender instance. - */ - public static CapaLogbackAppender buildCapaLogbackAppender() { - // load spi capa logback appender impl - return CapaClassLoader.loadComponentClassObj( - LOG_COMPONENT_TYPE, - CapaLogbackAppender.class); - } - - /** - * Deal with the log. - * - * @param event The log event. - */ - @Override - protected void append(EVENT event) { - logbackAppender.appendLog(event); - } - - /** - * The abstract api of the logback appender impl.Implement this and provide your specific impl. - */ - public interface CapaLogbackAppender { - - /** - * Deal with the log. - * - * @param event The log event. - */ - void appendLog(EVENT event); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 + * + * 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 group.rxcloud.capa.component.telemetry.log.agent; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.UnsynchronizedAppenderBase; +import group.rxcloud.capa.infrastructure.CapaClassLoader; +import jdk.jfr.internal.LogLevel; + +/** + * The agent of the logback impl. + */ +public class CapaLogbackAppenderAgent extends UnsynchronizedAppenderBase { + + /** + * The log component type. + */ + private static final String LOG_COMPONENT_TYPE = "log"; + /** + * Capa logback appender instance. + */ + private static final CapaLogbackAppender logbackAppender; + + /** + * Init the logbackAppender impl. + */ + static { + logbackAppender = buildCapaLogbackAppender(); + } + + /** + * Build the logback appender impl. + * + * @return CapaLogbackAppender instance. + */ + public static CapaLogbackAppender buildCapaLogbackAppender() { + // load spi capa logback appender impl + return CapaClassLoader.loadComponentClassObj( + LOG_COMPONENT_TYPE, + CapaLogbackAppender.class); + } + + /** + * Deal with the log. + * + * @param event The log event. + */ + @Override + protected void append(ILoggingEvent event) { + event.getLevel(); + logbackAppender.appendLog(event); + } + + /** + * The abstract api of the logback appender impl.Implement this and provide your specific impl. + */ + public interface CapaLogbackAppender { + + /** + * Deal with the log. + * + * @param event The log event. + */ + void appendLog(ILoggingEvent event); + } +} diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/CapaLogLevel.java b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/CapaLogLevel.java new file mode 100644 index 0000000..fed2c89 --- /dev/null +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/CapaLogLevel.java @@ -0,0 +1,30 @@ +package group.rxcloud.capa.component.telemetry.log.manager; + +import java.util.Arrays; + +public enum CapaLogLevel { + OFF(1, "OFF"), + FATAL(2, "FATAL"), + TRACE(3, "TRACE"), + DEBUG(4, "DEBUG"), + INFO(5, "INFO"), + WARN(6, "WARN"), + ERROR(7, "ERROR"), + ALL(8, "ALL"); + + final int level; + final String levelName; + + + CapaLogLevel(int level, String levelName) { + this.level = level; + this.levelName = levelName; + } + + public CapaLogLevel toCapaLogLevel(String logLevelArg) { + return Arrays.stream(CapaLogLevel.values()) + .filter(logLevel -> logLevel.levelName.equalsIgnoreCase(logLevelArg)) + .findAny() + .orElseThrow(() -> new IllegalArgumentException("Level " + logLevelArg + " is unknown.")); + } +} diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/LogsManager.java b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/LogsManager.java new file mode 100644 index 0000000..1c43b28 --- /dev/null +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/telemetry/log/manager/LogsManager.java @@ -0,0 +1,9 @@ +package group.rxcloud.capa.component.telemetry.log.manager; + + +public class LogsManager { + + public static boolean isLogLevelClosed(CapaLogLevel logLevel) { + return false; + } +} From 130b3cde3512eb71149eab2ca02a7f054fe3fcdb Mon Sep 17 00:00:00 2001 From: dgzpg Date: Wed, 1 Dec 2021 19:40:02 +0800 Subject: [PATCH 2/8] addDynamicallyAdjustLogLevel --- .../capa/examples/telemetry/DemoLog.java | 6 +- .../log/agent/CapaLog4jAppenderAgent.java | 2 +- .../log/agent/CapaLogbackAppenderAgent.java | 2 +- .../configuration/LogSwitchConfiguration.java | 128 +++++------------- .../component/log/enums/CapaLogLevel.java | 15 +- .../component/log/manager/LogManager.java | 91 +++++++++++-- 6 files changed, 134 insertions(+), 110 deletions(-) diff --git a/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java b/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java index e75463b..aef9e09 100644 --- a/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java +++ b/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java @@ -30,6 +30,10 @@ public class DemoLog { public static void main(String[] args) { - log.info("test"); + try { + log.info("test"); + }catch (Exception e){ + System.out.println(); + } } } diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLog4jAppenderAgent.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLog4jAppenderAgent.java index 6c43f85..2957661 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLog4jAppenderAgent.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLog4jAppenderAgent.java @@ -102,7 +102,7 @@ public static CapaLog4jAppender buildCapaLog4jAppender() { public void append(LogEvent event) { if (event != null && event.getLevel() != null) { Optional capaLogLevel = CapaLogLevel.toCapaLogLevel(event.getLevel().name()); - if (capaLogLevel.isPresent() && LogManager.isLogLevelSwitchOn(capaLogLevel.get())) { + if (capaLogLevel.isPresent() && LogManager.whetherLogsCanBeOutput(capaLogLevel.get())) { logAppender.appendLog(event); } } diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java index 63cbb94..fe54ffd 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java @@ -66,7 +66,7 @@ public static CapaLogbackAppender buildCapaLogbackAppender() { protected void append(ILoggingEvent event) { if (event != null && event.getLevel() != null) { Optional capaLogLevel = CapaLogLevel.toCapaLogLevel(event.getLevel().levelStr); - if (capaLogLevel.isPresent() && LogManager.isLogLevelSwitchOn(capaLogLevel.get())) { + if (capaLogLevel.isPresent() && LogManager.whetherLogsCanBeOutput(capaLogLevel.get())) { logbackAppender.appendLog(event); } } diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java index 4aa5fa1..5747cfa 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java @@ -17,6 +17,7 @@ package group.rxcloud.capa.component.log.configuration; import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import group.rxcloud.capa.infrastructure.hook.ConfigurationHooks; import group.rxcloud.capa.infrastructure.hook.Mixer; import group.rxcloud.cloudruntimes.domain.core.configuration.SubConfigurationResp; @@ -25,14 +26,30 @@ import org.apache.commons.lang3.StringUtils; import reactor.core.publisher.Flux; +import java.util.Map; import java.util.Optional; +/** + * Log switch configuration + */ public class LogSwitchConfiguration { + /** + * Capa configuration hooks. + */ private static final Optional configurationHooks; - private static final String LOGS_SWITCH_CONFIG_FILE_NAME = "logs-switch.properties"; - private static LogsSwitchConfig logsSwitchConfig; - + /** + * Log switch config file name. + */ + private static final String LOGS_SWITCH_CONFIG_FILE_NAME = "log-level-switch.properties"; + /** + * Log switch config's value. + */ + private static Map logsSwitchConfig = Maps.newHashMap(); + + /** + * Init configuration hooks and subscribe configuration. + */ static { configurationHooks = Mixer.configurationHooksNullable(); configurationHooks.ifPresent(configurationHooks -> { @@ -40,18 +57,22 @@ public class LogSwitchConfiguration { }); } + /** + * Subscribe configuration. + * + * @param configurationHooks + */ private static void subscribeConfiguration(ConfigurationHooks configurationHooks) { - // todo get storeName and appId from hooks of configuration - String storeName = ""; - String appId = ""; - Flux> configFlux = configurationHooks.subscribeConfiguration( + String storeName = configurationHooks.registryStoreNames().get(0); + String appId = configurationHooks.defaultConfigurationAppId(); + Flux> configFlux = configurationHooks.subscribeConfiguration( storeName, appId, Lists.newArrayList(LOGS_SWITCH_CONFIG_FILE_NAME), null, StringUtils.EMPTY, StringUtils.EMPTY, - TypeRef.get(LogsSwitchConfig.class)); + TypeRef.get(Map.class)); configFlux.subscribe(resp -> { if (CollectionUtils.isNotEmpty(resp.getItems())) { logsSwitchConfig = resp.getItems().get(0).getContent(); @@ -59,91 +80,12 @@ private static void subscribeConfiguration(ConfigurationHooks configurationHooks }); } - public static LogsSwitchConfig getLogsSwitchConfig() { + /** + * Get the log switch config's values. + * + * @return + */ + public static Map getLogsSwitchConfig() { return logsSwitchConfig; } - - public static class LogsSwitchConfig { - private Boolean logsSwitch; - private Boolean allLevelSwitch; - private Boolean traceLevelSwitch; - private Boolean debugLevelSwitch; - private Boolean infoLevelSwitch; - private Boolean warnLevelSwitch; - private Boolean errorLevelSwitch; - private Boolean fatalLevelSwitch; - private Boolean offLevelSwitch; - - public Boolean getLogsSwitch() { - return logsSwitch; - } - - public void setLogsSwitch(Boolean logsSwitch) { - this.logsSwitch = logsSwitch; - } - - public Boolean getAllLevelSwitch() { - return allLevelSwitch; - } - - public void setAllLevelSwitch(Boolean allLevelSwitch) { - this.allLevelSwitch = allLevelSwitch; - } - - public Boolean getTraceLevelSwitch() { - return traceLevelSwitch; - } - - public void setTraceLevelSwitch(Boolean traceLevelSwitch) { - this.traceLevelSwitch = traceLevelSwitch; - } - - public Boolean getDebugLevelSwitch() { - return debugLevelSwitch; - } - - public void setDebugLevelSwitch(Boolean debugLevelSwitch) { - this.debugLevelSwitch = debugLevelSwitch; - } - - public Boolean getInfoLevelSwitch() { - return infoLevelSwitch; - } - - public void setInfoLevelSwitch(Boolean infoLevelSwitch) { - this.infoLevelSwitch = infoLevelSwitch; - } - - public Boolean getWarnLevelSwitch() { - return warnLevelSwitch; - } - - public void setWarnLevelSwitch(Boolean warnLevelSwitch) { - this.warnLevelSwitch = warnLevelSwitch; - } - - public Boolean getErrorLevelSwitch() { - return errorLevelSwitch; - } - - public void setErrorLevelSwitch(Boolean errorLevelSwitch) { - this.errorLevelSwitch = errorLevelSwitch; - } - - public Boolean getFatalLevelSwitch() { - return fatalLevelSwitch; - } - - public void setFatalLevelSwitch(Boolean fatalLevelSwitch) { - this.fatalLevelSwitch = fatalLevelSwitch; - } - - public Boolean getOffLevelSwitch() { - return offLevelSwitch; - } - - public void setOffLevelSwitch(Boolean offLevelSwitch) { - this.offLevelSwitch = offLevelSwitch; - } - } } diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java index 6be30a1..da26619 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java @@ -19,6 +19,9 @@ import java.util.Arrays; import java.util.Optional; +/** + * Capa log level. + */ public enum CapaLogLevel { /** * Standard order of log priorities: @@ -41,13 +44,23 @@ public enum CapaLogLevel { this.levelName = levelName; } + /** + * Convert logLevelArg to {@link CapaLogLevel} + * + * @param logLevelArg + * @return + */ public static Optional toCapaLogLevel(String logLevelArg) { return Arrays.stream(CapaLogLevel.values()) .filter(logLevel -> logLevel.levelName.equalsIgnoreCase(logLevelArg)) .findAny(); - } + /** + * Get level. + * + * @return + */ public int getLevel() { return level; } diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java index 59d1f1b..04031a6 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java @@ -19,32 +19,97 @@ import group.rxcloud.capa.component.log.configuration.LogSwitchConfiguration; import group.rxcloud.capa.component.log.enums.CapaLogLevel; +import java.util.Map; + +/** + * LogManager, to manage log output levels. + */ public class LogManager { - public static Boolean isLogLevelSwitchOn(CapaLogLevel capaLogLevel) { - LogSwitchConfiguration.LogsSwitchConfig logsSwitchConfig = LogSwitchConfiguration.getLogsSwitchConfig(); - //no configuration instance or logs switch configuration, then follow the default logic - if (logsSwitchConfig == null || Boolean.FALSE.equals(logsSwitchConfig.getLogsSwitch())) { + /** + * Dynamically adjust the log level switch name. + */ + private static final String LOG_LEVEL_SWITCH_NAME = "logLevelSwitch"; + /** + * All level switch name. + */ + private static final String ALL_LEVEL_SWITCH_NAME = "allLevelSwitch"; + /** + * Trace level switch name. + */ + private static final String TRACE_LEVEL_SWITCH_NAME = "traceLevelSwitch"; + /** + * Debug level switch name. + */ + private static final String DEBUG_LEVEL_SWITCH_NAME = "debugLevelSwitch"; + /** + * Info level switch name. + */ + private static final String INFO_LEVEL_SWITCH_NAME = "infoLevelSwitch"; + /** + * Warn level switch. + */ + private static final String WARN_LEVEL_SWITCH_NAME = "warnLevelSwitch"; + /** + * Error level switch. + */ + private static final String ERROR_LEVEL_SWITCH_NAME = "errorLevelSwitch"; + /** + * Fatal level switch + */ + private static final String FATAL_LEVEL_SWITCH_NAME = "fatalLevelSwitch"; + /** + * Off level switch. + */ + private static final String OFF_LEVEL_SWITCH_NAME = "offLevelSwitch"; + + /** + * Whether logs can be output. + * @param capaLogLevel + * @return + */ + public static Boolean whetherLogsCanBeOutput(CapaLogLevel capaLogLevel) { + Map logsSwitchConfigs = LogSwitchConfiguration.getLogsSwitchConfig(); + //no configuration instance or logs switch configuration, then follow the default logic. + if (logsSwitchConfigs == null + || logsSwitchConfigs.isEmpty() + || Boolean.FALSE.equals(logsSwitchConfigs.get(LOG_LEVEL_SWITCH_NAME))) { return isLogsLevelClosedWithDefault(capaLogLevel); } switch (capaLogLevel) { case ALL: - return logsSwitchConfig.getAllLevelSwitch() == null ? Boolean.FALSE : logsSwitchConfig.getAllLevelSwitch(); + return logsSwitchConfigs.get(ALL_LEVEL_SWITCH_NAME) == null + ? Boolean.FALSE + : logsSwitchConfigs.get(ALL_LEVEL_SWITCH_NAME); case TRACE: - return logsSwitchConfig.getTraceLevelSwitch() == null ? Boolean.FALSE : logsSwitchConfig.getTraceLevelSwitch(); + return logsSwitchConfigs.get(TRACE_LEVEL_SWITCH_NAME) == null + ? Boolean.FALSE + : logsSwitchConfigs.get(TRACE_LEVEL_SWITCH_NAME); case DEBUG: - return logsSwitchConfig.getDebugLevelSwitch() == null ? Boolean.FALSE : logsSwitchConfig.getDebugLevelSwitch(); + return logsSwitchConfigs.get(DEBUG_LEVEL_SWITCH_NAME) == null + ? Boolean.FALSE + : logsSwitchConfigs.get(DEBUG_LEVEL_SWITCH_NAME); case INFO: - return logsSwitchConfig.getInfoLevelSwitch() == null ? Boolean.TRUE : logsSwitchConfig.getInfoLevelSwitch(); + return logsSwitchConfigs.get(INFO_LEVEL_SWITCH_NAME) == null + ? Boolean.TRUE + : logsSwitchConfigs.get(INFO_LEVEL_SWITCH_NAME); case WARN: - return logsSwitchConfig.getWarnLevelSwitch() == null ? Boolean.TRUE : logsSwitchConfig.getWarnLevelSwitch(); + return logsSwitchConfigs.get(WARN_LEVEL_SWITCH_NAME) == null + ? Boolean.TRUE + : logsSwitchConfigs.get(WARN_LEVEL_SWITCH_NAME); case ERROR: - return logsSwitchConfig.getErrorLevelSwitch() == null ? Boolean.TRUE : logsSwitchConfig.getErrorLevelSwitch(); + return logsSwitchConfigs.get(ERROR_LEVEL_SWITCH_NAME) == null + ? Boolean.TRUE + : logsSwitchConfigs.get(ERROR_LEVEL_SWITCH_NAME); case FATAL: - return logsSwitchConfig.getFatalLevelSwitch() == null ? Boolean.TRUE : logsSwitchConfig.getFatalLevelSwitch(); + return logsSwitchConfigs.get(FATAL_LEVEL_SWITCH_NAME) == null + ? Boolean.TRUE + : logsSwitchConfigs.get(FATAL_LEVEL_SWITCH_NAME); case OFF: - return logsSwitchConfig.getOffLevelSwitch() == null ? Boolean.TRUE : logsSwitchConfig.getOffLevelSwitch(); + return logsSwitchConfigs.get(OFF_LEVEL_SWITCH_NAME) == null + ? Boolean.TRUE + : logsSwitchConfigs.get(OFF_LEVEL_SWITCH_NAME) == null; default: return Boolean.FALSE; } @@ -54,7 +119,7 @@ public static Boolean isLogLevelSwitchOn(CapaLogLevel capaLogLevel) { * Logs of the {@link CapaLogLevel#INFO} level or higher are normally output, but logs of the {@link CapaLogLevel#INFO} level lower are not output. * * @param capaLogLevel - * @return whether capaLogLevel's priority is equal or more then {@link CapaLogLevel#INFO}. + * @return whether the capaLogLevel's priority is equal or more then {@link CapaLogLevel#INFO}. */ private static Boolean isLogsLevelClosedWithDefault(CapaLogLevel capaLogLevel) { return capaLogLevel.getLevel() >= CapaLogLevel.INFO.getLevel(); From 6a11865aeb6a6f99656d8ed0fc0d7449885ebb7f Mon Sep 17 00:00:00 2001 From: dgzpg Date: Wed, 1 Dec 2021 19:54:17 +0800 Subject: [PATCH 3/8] merge metric --- .../log/configuration/LogSwitchConfiguration.java | 2 +- .../rxcloud/capa/component/log/manager/LogManager.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java index 5747cfa..9d8d3f2 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/configuration/LogSwitchConfiguration.java @@ -83,7 +83,7 @@ private static void subscribeConfiguration(ConfigurationHooks configurationHooks /** * Get the log switch config's values. * - * @return + * @return the log switch config's values. */ public static Map getLogsSwitchConfig() { return logsSwitchConfig; diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java index 04031a6..fba8605 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/manager/LogManager.java @@ -65,8 +65,15 @@ public class LogManager { /** * Whether logs can be output. + * If there is no corresponding configuration information or the switch of dynamic configuration log level is set to false, + * then only logs of info level and above will be output. + *

+ * If the value of the dynamic configuration log level switch is true, only the log with the log level configured as true will be output. + *

+ * If the log level is not in the {@link CapaLogLevel#values()}, the log is not output. + * * @param capaLogLevel - * @return + * @return If the log can be output, it is true, otherwise it is false. */ public static Boolean whetherLogsCanBeOutput(CapaLogLevel capaLogLevel) { Map logsSwitchConfigs = LogSwitchConfiguration.getLogsSwitchConfig(); From 8d3688fcff9f0a3d4eed5a28c980da52769780f3 Mon Sep 17 00:00:00 2001 From: dgzpg Date: Wed, 1 Dec 2021 20:23:08 +0800 Subject: [PATCH 4/8] update demo --- .../java/group/rxcloud/capa/spi/demo/log/DemoLog4jAppender.java | 2 +- .../group/rxcloud/capa/spi/demo/log/DemoLogbackAppender.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLog4jAppender.java b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLog4jAppender.java index ccf07cc..f94df0f 100644 --- a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLog4jAppender.java +++ b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLog4jAppender.java @@ -23,6 +23,6 @@ public class DemoLog4jAppender implements CapaLog4jAppenderAgent.CapaLog4jAppend @Override public void appendLog(LogEvent event) { - System.out.println("test log log4j and content is " + event.getMessage().getFormattedMessage()); + System.out.println("Test log log4j and content is " + event.getMessage().getFormattedMessage()); } } diff --git a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLogbackAppender.java b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLogbackAppender.java index 65ee325..8e5ee40 100644 --- a/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLogbackAppender.java +++ b/sdk-spi-demo/src/main/java/group/rxcloud/capa/spi/demo/log/DemoLogbackAppender.java @@ -26,6 +26,6 @@ public DemoLogbackAppender() { @Override public void appendLog(ILoggingEvent event) { - System.out.println("test logback log and content is " + event.getFormattedMessage()); + System.out.println("Test logback log and content is " + event.getFormattedMessage()); } } From 9a80190289a613f8a58432345ad3de9b09f4e6df Mon Sep 17 00:00:00 2001 From: = Date: Wed, 1 Dec 2021 20:57:54 +0800 Subject: [PATCH 5/8] update file format --- .../capa/infrastructure/CapaClassLoader.java | 188 +++++++++--------- 1 file changed, 94 insertions(+), 94 deletions(-) diff --git a/sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/CapaClassLoader.java b/sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/CapaClassLoader.java index 203ee93..6429f40 100644 --- a/sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/CapaClassLoader.java +++ b/sdk-infrastructure/src/main/java/group/rxcloud/capa/infrastructure/CapaClassLoader.java @@ -1,94 +1,94 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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 - * - * 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 group.rxcloud.capa.infrastructure; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.Properties; - -/** - * The Capa SPI Class loader. - */ -public final class CapaClassLoader { - - /** - * Load component class obj. - * - * @param the target class type - * @param componentDomain the component domain - * @param superClazz the interface class type - * @return the target spi class obj - */ - public static T loadComponentClassObj(String componentDomain, Class superClazz) { - return loadComponentClassObj(componentDomain, superClazz, null, null); - } - - /** - * Load component class obj. - * - * @param the target class type - * @param componentDomain the component domain - * @param superClazz the interface class type - * @param parameterTypes the constructor parameters - * @param initargs the constructor initargs - * @return the target spi class obj - */ - public static T loadComponentClassObj(String componentDomain, Class superClazz, Class[] parameterTypes, Object[] initargs) { - Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply(componentDomain); - String implClassPath = properties.getProperty(superClazz.getName()); - return loadClassObj(implClassPath, parameterTypes, initargs); - } - - /** - * Load infrastructure class obj. - * - * @param the target class type - * @param infrastructureDomain the infrastructure domain - * @param superClazz the interface class type - * @return the target spi class obj - */ - public static T loadInfrastructureClassObj(String infrastructureDomain, Class superClazz) { - return loadInfrastructureClassObj(infrastructureDomain, superClazz, null, null); - } - - /** - * Load infrastructure class obj. - * - * @param the target class type - * @param infrastructureDomain the infrastructure domain - * @param superClazz the interface class type - * @param parameterTypes the constructor parameters - * @param initargs the constructor initargs - * @return the target spi class obj - */ - public static T loadInfrastructureClassObj(String infrastructureDomain, Class superClazz, Class[] parameterTypes, Object[] initargs) { - Properties properties = CapaProperties.INFRASTRUCTURE_PROPERTIES_SUPPLIER.apply(infrastructureDomain); - String implClassPath = properties.getProperty(superClazz.getName()); - return loadClassObj(implClassPath, parameterTypes, initargs); - } - - private static T loadClassObj(String classPath, Class[] parameterTypes, Object[] initargs) { - try { - Class aClass = (Class) Class.forName(classPath); - Constructor constructor = aClass.getConstructor(parameterTypes); - Object newInstance = constructor.newInstance(initargs); - return (T) newInstance; - } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { - throw new IllegalArgumentException("Capa load class error: [" + classPath + "] not found."); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 + * + * 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 group.rxcloud.capa.infrastructure; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Properties; + +/** + * The Capa SPI Class loader. + */ +public final class CapaClassLoader { + + /** + * Load component class obj. + * + * @param the target class type + * @param componentDomain the component domain + * @param superClazz the interface class type + * @return the target spi class obj + */ + public static T loadComponentClassObj(String componentDomain, Class superClazz) { + return loadComponentClassObj(componentDomain, superClazz, null, null); + } + + /** + * Load component class obj. + * + * @param the target class type + * @param componentDomain the component domain + * @param superClazz the interface class type + * @param parameterTypes the constructor parameters + * @param initargs the constructor initargs + * @return the target spi class obj + */ + public static T loadComponentClassObj(String componentDomain, Class superClazz, Class[] parameterTypes, Object[] initargs) { + Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.apply(componentDomain); + String implClassPath = properties.getProperty(superClazz.getName()); + return loadClassObj(implClassPath, parameterTypes, initargs); + } + + /** + * Load infrastructure class obj. + * + * @param the target class type + * @param infrastructureDomain the infrastructure domain + * @param superClazz the interface class type + * @return the target spi class obj + */ + public static T loadInfrastructureClassObj(String infrastructureDomain, Class superClazz) { + return loadInfrastructureClassObj(infrastructureDomain, superClazz, null, null); + } + + /** + * Load infrastructure class obj. + * + * @param the target class type + * @param infrastructureDomain the infrastructure domain + * @param superClazz the interface class type + * @param parameterTypes the constructor parameters + * @param initargs the constructor initargs + * @return the target spi class obj + */ + public static T loadInfrastructureClassObj(String infrastructureDomain, Class superClazz, Class[] parameterTypes, Object[] initargs) { + Properties properties = CapaProperties.INFRASTRUCTURE_PROPERTIES_SUPPLIER.apply(infrastructureDomain); + String implClassPath = properties.getProperty(superClazz.getName()); + return loadClassObj(implClassPath, parameterTypes, initargs); + } + + private static T loadClassObj(String classPath, Class[] parameterTypes, Object[] initargs) { + try { + Class aClass = (Class) Class.forName(classPath); + Constructor constructor = aClass.getConstructor(parameterTypes); + Object newInstance = constructor.newInstance(initargs); + return (T) newInstance; + } catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { + throw new IllegalArgumentException("Capa load class error: [" + classPath + "] not found."); + } + } +} From baaab892931fc34a3359ce905f30a4747e3e4709 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 1 Dec 2021 21:00:29 +0800 Subject: [PATCH 6/8] update format --- .../capa/component/log/agent/CapaLogbackAppenderAgent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java index fe54ffd..fb9d86a 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/agent/CapaLogbackAppenderAgent.java @@ -84,4 +84,4 @@ public interface CapaLogbackAppender { */ void appendLog(ILoggingEvent event); } -} \ No newline at end of file +} From c1bb16f9a1686e9bb6a883e4a19667a0da2767d6 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 1 Dec 2021 21:07:05 +0800 Subject: [PATCH 7/8] update format --- .../group/rxcloud/capa/component/log/enums/CapaLogLevel.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java b/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java index da26619..099fac3 100644 --- a/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java +++ b/sdk-component/src/main/java/group/rxcloud/capa/component/log/enums/CapaLogLevel.java @@ -24,8 +24,7 @@ */ public enum CapaLogLevel { /** - * Standard order of log priorities: - * ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF + * Standard order of log priorities:ALL,TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF */ ALL(1, "ALL"), TRACE(2, "TRACE"), From cda1bc3b3348ffb5201aee01e3e144f26d10409e Mon Sep 17 00:00:00 2001 From: = Date: Wed, 1 Dec 2021 21:14:16 +0800 Subject: [PATCH 8/8] update example --- .../capa/examples/telemetry/DemoLog.java | 79 ++++++++++--------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java b/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java index aef9e09..93ef506 100644 --- a/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java +++ b/examples/src/main/java/group/rxcloud/capa/examples/telemetry/DemoLog.java @@ -1,39 +1,40 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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 - * - * 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 group.rxcloud.capa.examples.telemetry; - -import lombok.extern.slf4j.Slf4j; - -/** - * An application cannot use log4j and logback configuration to print logs at the same time. - * So if you want to test the log4j2 configuration to print logs, then you need to copy the resources/xml/log4j2.xml file to the resources directory, and then add log4j-slf4j-impl dependency to the pom file. - * Else if you want to use logback configuration to print logs, then the resources/xml/logback.xml file needs to be copied to the resources path, and the logback-classic dependency needs to be added to the pom file. - * Notice: - * 1. Resources cannot contain log4j2.xml and logback.xml files at the same time, - * 2. log4j-slf4j-impl and logback-classic cannot exist at the same time. - */ -@Slf4j -public class DemoLog { - - public static void main(String[] args) { - try { - log.info("test"); - }catch (Exception e){ - System.out.println(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 + * + * 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 group.rxcloud.capa.examples.telemetry; + +import lombok.extern.slf4j.Slf4j; + +/** + * An application cannot use log4j and logback configuration to print logs at the same time. + * So if you want to test the log4j2 configuration to print logs, then you need to copy the resources/xml/log4j2.xml file to the resources directory, and then add log4j-slf4j-impl dependency to the pom file. + * Else if you want to use logback configuration to print logs, then the resources/xml/logback.xml file needs to be copied to the resources path, and the logback-classic dependency needs to be added to the pom file. + * Notice: + * 1. Resources cannot contain log4j2.xml and logback.xml files at the same time, + * 2. log4j-slf4j-impl and logback-classic cannot exist at the same time. + */ +@Slf4j +public class DemoLog { + + public static void main(String[] args) { + try { + log.info("test"); + }catch (Exception e){ + System.out.println(); + } + + } +}