Skip to content

Commit

Permalink
Use jul instead of slf4j for log output in agent core (#29746)
Browse files Browse the repository at this point in the history
* Use jul instead of slf4j and logback log output

* Exclude slf4j when packaging
  • Loading branch information
jiangML authored Jan 17, 2024
1 parent 3da2f14 commit 814379c
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 199 deletions.
21 changes: 21 additions & 0 deletions agent/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>

<dependency>
<groupId>com.cedarsoftware</groupId>
<artifactId>java-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.agent.core.advisor.config.yaml.loader.YamlAdvisorsConfigurationLoader;
import org.apache.shardingsphere.agent.core.advisor.config.yaml.swapper.YamlAdvisorsConfigurationSwapper;
import org.apache.shardingsphere.agent.core.log.AgentLogger;
import org.apache.shardingsphere.agent.core.log.AgentLoggerFactory;
import org.apache.shardingsphere.agent.core.plugin.classloader.AgentPluginClassLoader;

import java.io.File;
Expand All @@ -31,14 +29,15 @@
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.logging.Logger;

/**
* Advisor configuration loader.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AdvisorConfigurationLoader {

private static final AgentLogger LOGGER = AgentLoggerFactory.getAgentLogger(AdvisorConfigurationLoader.class);
private static final Logger LOGGER = Logger.getLogger(AdvisorConfigurationLoader.class.getName());

/**
* Load advisor configurations.
Expand All @@ -53,7 +52,7 @@ public static Map<String, AdvisorConfiguration> load(final Collection<JarFile> p
for (String each : pluginTypes) {
InputStream advisorsResourceStream = getResourceStream(agentPluginClassLoader, each);
if (null == advisorsResourceStream) {
LOGGER.info("No configuration of advisor for type `{}`.", each);
LOGGER.info(String.format("No configuration of advisor for type `%s`.", each));
} else {
mergeConfigurations(result, YamlAdvisorsConfigurationSwapper.swap(YamlAdvisorsConfigurationLoader.load(advisorsResourceStream), each));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.ConstructorAdvice;
import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutor;
import org.apache.shardingsphere.agent.core.log.AgentLogger;
import org.apache.shardingsphere.agent.core.log.AgentLoggerFactory;
import org.apache.shardingsphere.agent.core.plugin.PluginContext;

import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;

/**
* Constructor advice executor.
*/
@RequiredArgsConstructor
public final class ConstructorAdviceExecutor implements AdviceExecutor {

private static final AgentLogger LOGGER = AgentLoggerFactory.getAgentLogger(ConstructorAdviceExecutor.class);
private static final Logger LOGGER = Logger.getLogger(ConstructorAdviceExecutor.class.getName());

private final Map<String, Collection<ConstructorAdvice>> advices;

Expand All @@ -66,9 +65,9 @@ public void advice(@This final TargetAdviceObject target, @AllArguments final Ob
}
}
// CHECKSTYLE:OFF
} catch (final Throwable throwable) {
} catch (final Throwable ex) {
// CHECKSTYLE:ON
LOGGER.error("Constructor advice execution error. class: {}", target.getClass().getTypeName(), throwable);
LOGGER.severe(String.format("Constructor advice execution error. class: %s, %s", target.getClass().getTypeName(), ex.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@
import org.apache.shardingsphere.agent.api.advice.TargetAdviceObject;
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutor;
import org.apache.shardingsphere.agent.core.log.AgentLogger;
import org.apache.shardingsphere.agent.core.log.AgentLoggerFactory;
import org.apache.shardingsphere.agent.core.plugin.PluginContext;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.logging.Logger;

/**
* Instance method advice executor.
*/
@RequiredArgsConstructor
public final class InstanceMethodAdviceExecutor implements AdviceExecutor {

private static final AgentLogger LOGGER = AgentLoggerFactory.getAgentLogger(InstanceMethodAdviceExecutor.class);
private static final Logger LOGGER = Logger.getLogger(InstanceMethodAdviceExecutor.class.getName());

private final Map<String, Collection<InstanceMethodAdvice>> advices;

Expand Down Expand Up @@ -95,7 +94,7 @@ private void adviceBefore(final TargetAdviceObject target, final Method method,
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
LOGGER.error("Failed to execute the pre-method of method `{}` in class `{}`.", method.getName(), target.getClass(), ex);
LOGGER.severe(String.format("Failed to execute the pre-method of method `%s` in class `%s`, %s.", method.getName(), target.getClass(), ex.getMessage()));
}
}

Expand All @@ -109,7 +108,7 @@ private void adviceThrow(final TargetAdviceObject target, final Method method, f
// CHECKSTYLE:OFF
} catch (final Throwable ignored) {
// CHECKSTYLE:ON
LOGGER.error("Failed to execute the error handler of method `{}` in class `{}`.", method.getName(), target.getClass(), ex);
LOGGER.severe(String.format("Failed to execute the error handler of method `%s` in class `%s`, %s.", method.getName(), target.getClass(), ex.getMessage()));
}
}

Expand All @@ -124,7 +123,7 @@ private void adviceAfter(final TargetAdviceObject target, final Method method, f
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
LOGGER.error("Failed to execute the post-method of method `{}` in class `{}`.", method.getName(), target.getClass(), ex);
LOGGER.severe(String.format("Failed to execute the post-method of method `%s` in class `%s`, %s.", method.getName(), target.getClass(), ex.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,22 @@
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;
import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutor;
import org.apache.shardingsphere.agent.core.log.AgentLogger;
import org.apache.shardingsphere.agent.core.log.AgentLoggerFactory;
import org.apache.shardingsphere.agent.core.plugin.PluginContext;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
import java.util.logging.Logger;

/**
* Static method advice executor.
*/
@RequiredArgsConstructor
public final class StaticMethodAdviceExecutor implements AdviceExecutor {

private static final AgentLogger LOGGER = AgentLoggerFactory.getAgentLogger(StaticMethodAdviceExecutor.class);
private static final Logger LOGGER = Logger.getLogger(StaticMethodAdviceExecutor.class.getName());

private final Map<String, Collection<StaticMethodAdvice>> advices;

Expand Down Expand Up @@ -93,7 +92,7 @@ private void adviceBefore(final Class<?> klass, final Method method, final Objec
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
LOGGER.error("Failed to execute the pre-method of method `{}` in class `{}`.", method.getName(), klass, ex);
LOGGER.severe(String.format("Failed to execute the pre-method of method `%s` in class `%s`, %s.", method.getName(), klass, ex.getMessage()));
}
}

Expand All @@ -107,7 +106,7 @@ private void adviceThrow(final Class<?> klass, final Method method, final Object
// CHECKSTYLE:OFF
} catch (final Throwable ignored) {
// CHECKSTYLE:ON
LOGGER.error("Failed to execute the error handler of method `{}` in class `{}`.", method.getName(), klass, ex);
LOGGER.severe(String.format("Failed to execute the error handler of method `%s` in class `%s`, %s.", method.getName(), klass, ex.getMessage()));
}
}

Expand All @@ -121,7 +120,7 @@ private void adviceAfter(final Class<?> klass, final Method method, final Object
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
LOGGER.error("Failed to execute the post-method of method `{}` in class `{}`.", method.getName(), klass, ex);
LOGGER.severe(String.format("Failed to execute the post-method of method `%s` in class `%s` %s.", method.getName(), klass, ex.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import org.apache.shardingsphere.agent.core.builder.interceptor.AgentBuilderInterceptChainEngine;
import org.apache.shardingsphere.agent.core.builder.interceptor.impl.MethodAdvisorBuilderInterceptor;
import org.apache.shardingsphere.agent.core.builder.interceptor.impl.TargetAdviceObjectBuilderInterceptor;
import org.apache.shardingsphere.agent.core.log.AgentLogger;
import org.apache.shardingsphere.agent.core.log.AgentLoggerFactory;
import org.apache.shardingsphere.agent.core.plugin.PluginLifecycleServiceManager;
import org.apache.shardingsphere.agent.core.plugin.classloader.AgentPluginClassLoader;
import org.apache.shardingsphere.agent.core.plugin.classloader.ClassLoaderContext;
Expand All @@ -42,14 +40,15 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarFile;
import java.util.logging.Logger;

/**
* Agent transformer.
*/
@RequiredArgsConstructor
public final class AgentTransformer implements Transformer {

private static final AgentLogger LOGGER = AgentLoggerFactory.getAgentLogger(AdvisorConfigurationLoader.class);
private static final Logger LOGGER = Logger.getLogger(AdvisorConfigurationLoader.class.getName());

private static final Map<AgentPluginClassLoader, TypePool> TYPE_POOL_MAP = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -80,7 +79,7 @@ private AdvisorConfiguration filterInvalidAdviceClass(final AdvisorConfiguration
result.getAdvisors().add(each);
continue;
}
LOGGER.error("The advice class `{}` does not exist", each.getAdviceClassName());
LOGGER.severe(String.format("The advice class `%s` does not exist", each.getAdviceClassName()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,16 @@
import org.apache.shardingsphere.agent.core.advisor.executor.AdviceExecutorFactory;
import org.apache.shardingsphere.agent.core.builder.interceptor.AgentBuilderInterceptor;
import org.apache.shardingsphere.agent.core.plugin.classloader.ClassLoaderContext;
import org.apache.shardingsphere.agent.core.log.AgentLogger;
import org.apache.shardingsphere.agent.core.log.AgentLoggerFactory;

import java.util.Optional;
import java.util.logging.Logger;

/**
* Method advisor builder interceptor.
*/
public final class MethodAdvisorBuilderInterceptor implements AgentBuilderInterceptor {

private static final AgentLogger LOGGER = AgentLoggerFactory.getAgentLogger(MethodAdvisorBuilderInterceptor.class);
private static final Logger LOGGER = Logger.getLogger(MethodAdvisorBuilderInterceptor.class.getName());

private final TypeDescription typePointcut;

Expand All @@ -59,7 +58,7 @@ public Builder<?> intercept(final Builder<?> builder) {
// CHECKSTYLE:OFF
} catch (final Throwable ex) {
// CHECKSTYLE:ON
LOGGER.error("Failed to load advice class: {}.", typePointcut.getTypeName(), ex);
LOGGER.severe(String.format("Failed to load advice class: %s, %s.", typePointcut.getTypeName(), ex.getMessage()));
}
}
return result;
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 814379c

Please sign in to comment.