wu-sheng commented on a change in pull request #5357: URL: https://github.com/apache/skywalking/pull/5357#discussion_r473777796
########## File path: apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/logging/core/LoggingBenchmark.java ########## @@ -0,0 +1,64 @@ +/* + * 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.agent.core.logging.core; + +import com.google.gson.Gson; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; + +import java.util.concurrent.TimeUnit; + +public class LoggingBenchmark { Review comment: Traditionally, we put the benchmark result in the class comments. Then other developers could have a clear result at the first time, rather than running on its own laptop. ########## File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java ########## @@ -259,6 +260,43 @@ * @see org.apache.skywalking.apm.agent.core.logging.core.PatternLogger#DEFAULT_CONVERTER_MAP */ public static String PATTERN = "%level %timestamp %thread %class : %msg %throwable"; + + public static class JSON { + /** + * Key of the AgentName + */ + public static String AGENT_NAME_KEY = "agent_name"; Review comment: Technically, yes, my question is more about, why and who will config this. ########## File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/Converter.java ########## @@ -19,10 +19,13 @@ package org.apache.skywalking.apm.agent.core.logging.core; /** - * The Converter, It is used to convert the LogEvent to the String. + * The Converter, it is used to convert the LogEvent to the String. */ public interface Converter { String convert(LogEvent logEvent); + default String getKey() { Review comment: Once you add this, why need a default implementation? ########## File path: apm-sniffer/apm-agent/src/main/java/org/apache/skywalking/apm/agent/SkyWalkingAgent.java ########## @@ -65,63 +66,68 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins()); } catch (AgentPackageNotFoundException ape) { - logger.error(ape, "Locate agent.jar failure. Shutting down."); + LOGGER = LogManager.getLogger(SkyWalkingAgent.class); Review comment: You should make `SnifferConfigInitializer.initializeCoreConfig(agentArgs);` in a separate `try/catch/finally` to reset the logger, please do this so many times. ########## File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java ########## @@ -249,6 +251,11 @@ */ public static LogOutput OUTPUT = LogOutput.FILE; + /** + * The log resolver type. Default is PATTERN which will create PatternLogResolver later. + */ + public static ResolverType LOGGER = ResolverType.PATTERN; Review comment: ```suggestion public static ResolverType RESOLVER = ResolverType.PATTERN; ``` ########## File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/JsonLogger.java ########## @@ -0,0 +1,60 @@ +/* + * 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.agent.core.logging.core; + +import com.google.gson.Gson; +import org.apache.skywalking.apm.agent.core.logging.core.converters.LiteralConverter; + +import java.util.HashMap; +import java.util.Map; + +public class JsonLogger extends AbstractLogger { + private final Gson gson; + + public JsonLogger(Class<?> targetClass, Gson gson) { + this(targetClass.getSimpleName(), gson); + } + + public JsonLogger(String targetClass, Gson gson) { + super(targetClass); + this.gson = gson; + for (Map.Entry<String, Class<? extends Converter>> entry : DEFAULT_CONVERTER_MAP.entrySet()) { + try { + if (converters instanceof LiteralConverter) { + continue; + } + converters.add(entry.getValue().newInstance()); + } catch (IllegalAccessException | InstantiationException ignore) { + } + } + } + + protected void logger(LogLevel level, String message, Throwable e) { Review comment: Why need to override this method? I think this method should be in `AbstractLogger` too, and the two implementations only have their own `format` method(an abstract method in the parent). ########## File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/JsonLogger.java ########## @@ -0,0 +1,60 @@ +/* + * 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.agent.core.logging.core; + +import com.google.gson.Gson; +import org.apache.skywalking.apm.agent.core.logging.core.converters.LiteralConverter; + +import java.util.HashMap; +import java.util.Map; + +public class JsonLogger extends AbstractLogger { + private final Gson gson; + + public JsonLogger(Class<?> targetClass, Gson gson) { + this(targetClass.getSimpleName(), gson); + } + + public JsonLogger(String targetClass, Gson gson) { + super(targetClass); + this.gson = gson; + for (Map.Entry<String, Class<? extends Converter>> entry : DEFAULT_CONVERTER_MAP.entrySet()) { + try { + if (converters instanceof LiteralConverter) { + continue; + } + converters.add(entry.getValue().newInstance()); + } catch (IllegalAccessException | InstantiationException ignore) { Review comment: Why you hide the expression? What happens once these happen? ########## File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java ########## @@ -259,6 +266,43 @@ * @see org.apache.skywalking.apm.agent.core.logging.core.PatternLogger#DEFAULT_CONVERTER_MAP */ public static String PATTERN = "%level %timestamp %thread %class : %msg %throwable"; + + public static class JSON { + /** + * Key of the AgentName + */ + public static String AGENT_NAME_KEY = "agent_name"; + + /** + * Key of the timestamp + */ + public static String TIMESTAMP_KEY = "@timestamp"; Review comment: Why starting with `@` in JSON? ########## File path: apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/SnifferConfigInitializer.java ########## @@ -40,7 +42,7 @@ * The <code>SnifferConfigInitializer</code> initializes all configs in several way. */ public class SnifferConfigInitializer { - private static final ILog logger = LogManager.getLogger(SnifferConfigInitializer.class); + private static ILog LOGGER = LogManager.getLogger(SnifferConfigInitializer.class); Review comment: It used to be able to pass, then it still can. All codes in the master branch have to pass the style check. Please recheck again. In the rule, we set an exception for the logger due to the legacy issue. ---------------------------------------------------------------- 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: [email protected]
