muse-dev[bot] commented on a change in pull request #5914:
URL: https://github.com/apache/skywalking/pull/5914#discussion_r531827850



##########
File path: 
apm-sniffer/apm-sdk-plugin/logger-plugin/src/main/java/org/apache/skywalking/apm/plugin/logger/ContextConfig.java
##########
@@ -0,0 +1,254 @@
+/*
+ * 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 org.apache.skywalking.apm.plugin.logger;
+
+import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
+import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * contains all config of the logger plugin.
+ */
+public class ContextConfig {
+
+    private final LoggerConfig logbackConfig;
+    private final LoggerConfig log4jConfig;
+    private final LoggerConfig log4j2Config;
+
+    private ContextConfig(LoggerConfig logbackConfig, LoggerConfig 
log4jConfig, LoggerConfig log4j2Config) {
+        this.logbackConfig = logbackConfig;
+        this.log4jConfig = log4jConfig;
+        this.log4j2Config = log4j2Config;
+    }
+
+    public LoggerConfig getLogbackConfig() {
+        return logbackConfig;
+    }
+
+    public LoggerConfig getLog4jConfig() {
+        return log4jConfig;
+    }
+
+    public LoggerConfig getLog4j2Config() {
+        return log4j2Config;
+    }
+
+    public static ContextConfig getInstance() {
+        return HolderContextConfig.INSTANCE;
+    }
+
+    //use singleton
+    private static class HolderContextConfig {
+        private final static ContextConfig INSTANCE = initContextConfig();
+
+        private static ContextConfig initContextConfig() {
+            // judge whether has yaml file
+            File configFile;
+            try {
+                configFile = new File(AgentPackagePath.getPath(), 
"/config/logconfig.yaml");
+            } catch (AgentPackageNotFoundException e) {
+                throw new RuntimeException(e);
+            }
+            LoggerConfig logbackConfig = null, log4jConfig = null, 
log4j2Config = null;
+            // not has config file, make config default
+            if (!configFile.exists()) {
+                List<String> packages = new ArrayList<>();
+                packages.add("*");
+                logbackConfig = new LoggerConfig("logback", packages, 
LogLevel.ERROR);
+                log4jConfig = new LoggerConfig("log4j", packages, 
LogLevel.ERROR);
+                log4j2Config = new LoggerConfig("log4j2", packages, 
LogLevel.ERROR);
+            } else {
+                // use config file to init ContextConfig
+                FileInputStream configFileInputStream = null;
+                try {
+                    configFileInputStream = new FileInputStream(configFile);
+                    List<LoggerConfig> configs = 
parseConfigFile(configFileInputStream);
+                    // initialization of variables which are described in 
config file
+                    for (LoggerConfig loggerConfig : configs) {
+                        if ("logback".equals(loggerConfig.getName())) {
+                            logbackConfig = fillLoggerConfig(loggerConfig);
+                        } else if ("log4j".equals(loggerConfig.getName())) {
+                            log4jConfig = fillLoggerConfig(loggerConfig);
+                        } else if ("log4j2".equals(loggerConfig.getName())) {
+                            log4j2Config = fillLoggerConfig(loggerConfig);
+                        } else {
+                            throw new IllegalArgumentException();
+                        }
+                    }
+                } catch (FileNotFoundException e) {
+                    e.printStackTrace();
+                } finally {
+                    //close input stream
+                    if (configFileInputStream != null) {
+                        try {
+                            configFileInputStream.close();
+                        } catch (IOException e) {
+                            e.printStackTrace();

Review comment:
       *CatchAndPrintStackTrace:*  Logging or rethrowing exceptions should 
usually be preferred to catching and calling printStackTrace

##########
File path: 
apm-sniffer/apm-sdk-plugin/logger-plugin/src/main/java/org/apache/skywalking/apm/plugin/logger/ContextConfig.java
##########
@@ -0,0 +1,254 @@
+/*
+ * 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 org.apache.skywalking.apm.plugin.logger;
+
+import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
+import org.apache.skywalking.apm.agent.core.boot.AgentPackagePath;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * contains all config of the logger plugin.
+ */
+public class ContextConfig {
+
+    private final LoggerConfig logbackConfig;
+    private final LoggerConfig log4jConfig;
+    private final LoggerConfig log4j2Config;
+
+    private ContextConfig(LoggerConfig logbackConfig, LoggerConfig 
log4jConfig, LoggerConfig log4j2Config) {
+        this.logbackConfig = logbackConfig;
+        this.log4jConfig = log4jConfig;
+        this.log4j2Config = log4j2Config;
+    }
+
+    public LoggerConfig getLogbackConfig() {
+        return logbackConfig;
+    }
+
+    public LoggerConfig getLog4jConfig() {
+        return log4jConfig;
+    }
+
+    public LoggerConfig getLog4j2Config() {
+        return log4j2Config;
+    }
+
+    public static ContextConfig getInstance() {
+        return HolderContextConfig.INSTANCE;
+    }
+
+    //use singleton
+    private static class HolderContextConfig {
+        private final static ContextConfig INSTANCE = initContextConfig();
+
+        private static ContextConfig initContextConfig() {
+            // judge whether has yaml file
+            File configFile;
+            try {
+                configFile = new File(AgentPackagePath.getPath(), 
"/config/logconfig.yaml");
+            } catch (AgentPackageNotFoundException e) {
+                throw new RuntimeException(e);
+            }
+            LoggerConfig logbackConfig = null, log4jConfig = null, 
log4j2Config = null;
+            // not has config file, make config default
+            if (!configFile.exists()) {
+                List<String> packages = new ArrayList<>();
+                packages.add("*");
+                logbackConfig = new LoggerConfig("logback", packages, 
LogLevel.ERROR);
+                log4jConfig = new LoggerConfig("log4j", packages, 
LogLevel.ERROR);
+                log4j2Config = new LoggerConfig("log4j2", packages, 
LogLevel.ERROR);
+            } else {
+                // use config file to init ContextConfig
+                FileInputStream configFileInputStream = null;
+                try {
+                    configFileInputStream = new FileInputStream(configFile);
+                    List<LoggerConfig> configs = 
parseConfigFile(configFileInputStream);
+                    // initialization of variables which are described in 
config file
+                    for (LoggerConfig loggerConfig : configs) {
+                        if ("logback".equals(loggerConfig.getName())) {
+                            logbackConfig = fillLoggerConfig(loggerConfig);
+                        } else if ("log4j".equals(loggerConfig.getName())) {
+                            log4jConfig = fillLoggerConfig(loggerConfig);
+                        } else if ("log4j2".equals(loggerConfig.getName())) {
+                            log4j2Config = fillLoggerConfig(loggerConfig);
+                        } else {
+                            throw new IllegalArgumentException();
+                        }
+                    }
+                } catch (FileNotFoundException e) {
+                    e.printStackTrace();

Review comment:
       *CatchAndPrintStackTrace:*  Logging or rethrowing exceptions should 
usually be preferred to catching and calling printStackTrace




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to