Skip to content

Commit

Permalink
[#noissue] Remove CommonLogger Adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Dec 13, 2024
1 parent 97a368b commit e492e33
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 347 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import com.navercorp.pinpoint.common.config.util.BypassResolver;
import com.navercorp.pinpoint.common.config.util.ValueResolver;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.common.util.logger.CommonLogger;
import com.navercorp.pinpoint.common.util.logger.StdoutCommonLoggerFactory;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -40,8 +38,6 @@
public class DefaultProfilerConfig implements ProfilerConfig {
public static final String PROFILER_INTERCEPTOR_EXCEPTION_PROPAGATE = "profiler.interceptor.exception.propagate";

private static final CommonLogger logger = StdoutCommonLoggerFactory.INSTANCE.getLogger(DefaultProfilerConfig.class.getName());

// TestAgent only
public static final String IMPORT_PLUGIN = "profiler.plugin.import-plugin";

Expand Down Expand Up @@ -185,21 +181,13 @@ public String readString(String propertyName, String defaultValue, ValueResolver
Objects.requireNonNull(valueResolver, "valueResolver");

String value = properties.getProperty(propertyName, defaultValue);
value = valueResolver.resolve(propertyName, value);
if (logger.isDebugEnabled()) {
logger.debug(propertyName + "=" + value);
}
return value;
return valueResolver.resolve(propertyName, value);
}

@Override
public int readInt(String propertyName, int defaultValue) {
String value = properties.getProperty(propertyName);
int result = NumberUtils.parseInteger(value, defaultValue);
if (logger.isDebugEnabled()) {
logger.debug(propertyName + "=" + result);
}
return result;
return NumberUtils.parseInteger(value, defaultValue);
}

@Override
Expand All @@ -215,20 +203,13 @@ public DumpType readDumpType(String propertyName, DumpType defaultDump) {
} catch (IllegalArgumentException e) {
result = defaultDump;
}
if (logger.isDebugEnabled()) {
logger.debug(propertyName + "=" + result);
}
return result;
}

@Override
public long readLong(String propertyName, long defaultValue) {
String value = properties.getProperty(propertyName);
long result = NumberUtils.parseLong(value, defaultValue);
if (logger.isDebugEnabled()) {
logger.debug(propertyName + "=" + result);
}
return result;
return NumberUtils.parseLong(value, defaultValue);
}

@Override
Expand All @@ -243,11 +224,7 @@ public List<String> readList(String propertyName) {
@Override
public boolean readBoolean(String propertyName, boolean defaultValue) {
String value = properties.getProperty(propertyName, Boolean.toString(defaultValue));
boolean result = Boolean.parseBoolean(value);
if (logger.isDebugEnabled()) {
logger.debug(propertyName + "=" + result);
}
return result;
return Boolean.parseBoolean(value);
}

@Override
Expand All @@ -263,11 +240,6 @@ public Map<String, String> readPattern(String propertyNamePatternRegex) {
}
}
}

if (logger.isDebugEnabled()) {
logger.debug(propertyNamePatternRegex + "=" + result);
}

return result;
}

Expand All @@ -291,4 +263,4 @@ public String toString() {
", agentClassloaderAdditionalLibs='" + agentClassloaderAdditionalLibs + '\'' +
'}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@

import com.navercorp.pinpoint.common.config.util.ValueAnnotationProcessor;
import com.navercorp.pinpoint.common.util.PropertyUtils;
import com.navercorp.pinpoint.common.util.logger.CommonLogger;
import com.navercorp.pinpoint.common.util.logger.StdoutCommonLoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ProfilerConfigLoader {

private static final CommonLogger logger = StdoutCommonLoggerFactory.INSTANCE.getLogger(DefaultProfilerConfig.class.getName());

public static ProfilerConfig load(InputStream inputStream) {
Properties properties = loadProperties(inputStream);
return load(properties);
Expand All @@ -38,9 +34,6 @@ private static Properties loadProperties(InputStream inputStream) {
try {
return PropertyUtils.loadProperty(inputStream);
} catch (IOException ex) {
if (logger.isWarnEnabled()) {
logger.warn("IO error. Error:" + ex.getMessage(), ex);
}
throw new RuntimeException("IO error. Error:" + ex.getMessage(), ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
package com.navercorp.pinpoint.bootstrap.logging;


import com.navercorp.pinpoint.common.util.logger.CommonLogger;
import com.navercorp.pinpoint.common.util.logger.StdoutCommonLoggerFactory;

import java.util.Objects;

/**
Expand All @@ -29,13 +26,12 @@ public class PluginLogManager {

private static PluginLoggerBinder loggerBinder;

public static void initialize(PluginLoggerBinder loggerBinder) {
public static boolean initialize(PluginLoggerBinder loggerBinder) {
if (PluginLogManager.loggerBinder == null) {
PluginLogManager.loggerBinder = loggerBinder;
} else {
final CommonLogger logger = StdoutCommonLoggerFactory.INSTANCE.getLogger(PluginLogManager.class.getName());
logger.warn("loggerBinder is not null");
return true;
}
return false;
}

public static void unregister(PluginLoggerBinder loggerBinder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.navercorp.pinpoint.common.util.NetUtils;
import com.navercorp.pinpoint.common.util.OsType;
import com.navercorp.pinpoint.common.util.OsUtils;
import com.navercorp.pinpoint.common.util.logger.CommonLogger;
import com.navercorp.pinpoint.common.util.logger.StdoutCommonLoggerFactory;

import java.net.InetAddress;
import java.net.MalformedURLException;
Expand All @@ -40,9 +38,9 @@ public final class NetworkUtils {

public static final String ERROR_HOST_NAME = "UNKNOWN-HOST";

private static final String LOOPBACK_ADDRESS_V4_1 = "127.0.0.1";
private static final String LOOPBACK_ADDRESS_V4_2 = "127.0.1.1";
private static final String LOOPBACK_ADDRESS_V6 = "0:0:0:0:0:0:0:1";
public static final String LOOPBACK_ADDRESS_V4_1 = "127.0.0.1";
public static final String LOOPBACK_ADDRESS_V4_2 = "127.0.1.1";
public static final String LOOPBACK_ADDRESS_V6 = "0:0:0:0:0:0:0:1";

private static volatile String LOCAL_HOST_CACHE;

Expand Down Expand Up @@ -86,10 +84,9 @@ static String getHostNameFromEnv() {
}
}

public static String getRepresentationHostIp() {
String ip = getHostIp();
if (!isLoopbackAddress(ip)) {
return ip;
public static String getRepresentationHostIp(String hostIp) {
if (!isLoopbackAddress(hostIp)) {
return hostIp;
}

List<String> ipList = getHostIpList();
Expand All @@ -100,17 +97,9 @@ public static String getRepresentationHostIp() {
return LOOPBACK_ADDRESS_V4_1;
}

public static String getHostIp() {
String hostIp;
try {
final InetAddress thisIp = InetAddress.getLocalHost();
hostIp = thisIp.getHostAddress();
} catch (UnknownHostException e) {
CommonLogger logger = getLogger();
logger.warn(e.getMessage());
hostIp = LOOPBACK_ADDRESS_V4_1;
}
return hostIp;
public static String getHostIp() throws UnknownHostException{
final InetAddress thisIp = InetAddress.getLocalHost();
return thisIp.getHostAddress();
}

public static List<String> getHostIpList() {
Expand Down Expand Up @@ -150,14 +139,6 @@ public static List<String> getHostIpList() {
return result;
}

public static String getHostV4Ip() {
String hostIp = getHostIp();
if (validationIpV4FormatAddress(hostIp)) {
return hostIp;
}
return LOOPBACK_ADDRESS_V4_1;
}

public static List<String> getHostV4IpList() {
List<String> hostIpList = getHostIpList();
List<String> hostV4IpList = new ArrayList<>(hostIpList.size());
Expand Down Expand Up @@ -198,9 +179,6 @@ public static boolean validationIpV4FormatAddress(String address) {
return NetUtils.validationIpV4FormatAddress(address);
}

private static CommonLogger getLogger() {
return StdoutCommonLoggerFactory.INSTANCE.getLogger(NetworkUtils.class.getName());
}

public static String getHostFromURL(final String urlSpec) {
if (urlSpec == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.navercorp.pinpoint.profiler.logging;

import com.navercorp.pinpoint.bootstrap.logging.PluginLogManager;
import com.navercorp.pinpoint.bootstrap.logging.PluginLogger;
import com.navercorp.pinpoint.bootstrap.logging.PluginLoggerBinder;
import org.apache.logging.log4j.LogManager;

Expand All @@ -30,7 +31,10 @@ public class Log4j2LoggerBinderInitializer {
private static final PluginLoggerBinder loggerBinder = new Log4j2Binder(LogManager.getContext());

public static void beforeClass() {
PluginLogManager.initialize(loggerBinder);
if (!PluginLogManager.initialize(loggerBinder)) {
PluginLogger logger = loggerBinder.getLogger(Log4j2LoggerBinderInitializer.class.getName());
logger.warn("LoggerBinder is already initialized");
}
}

public static void afterClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ private void bindPluginLogFactory(PluginLoggerBinder binder) {
pluginLogger.info("PluginLogManager.initialize() bind:{} cl:{}", binderClassName, binder.getClass().getClassLoader());
// Set binder to static PluginLogManager
// Should we unset binder at shutdown hook or stop()?
PluginLogManager.initialize(binder);
if (!PluginLogManager.initialize(binder)) {
pluginLogger.warn("LoggerBinder is already initialized");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
import com.google.inject.PrivateModule;
import com.google.inject.Scopes;
import com.navercorp.pinpoint.common.profiler.trace.TraceMetadataLoader;
import com.navercorp.pinpoint.common.util.logger.CommonLoggerFactory;
import com.navercorp.pinpoint.loader.service.AnnotationKeyRegistryService;
import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService;
import com.navercorp.pinpoint.loader.service.TraceMetadataLoaderService;
import com.navercorp.pinpoint.profiler.context.provider.plugin.AnnotationKeyRegistryServiceProvider;
import com.navercorp.pinpoint.profiler.context.provider.plugin.ServiceTypeRegistryServiceProvider;
import com.navercorp.pinpoint.profiler.context.provider.plugin.Slf4jCommonLoggerFactory;
import com.navercorp.pinpoint.profiler.context.provider.plugin.TraceMetadataLoaderProvider;
import com.navercorp.pinpoint.profiler.context.provider.plugin.TraceMetadataLoaderServiceProvider;
import org.apache.logging.log4j.LogManager;
Expand All @@ -46,7 +44,6 @@ protected void configure() {
binder().requireAtInjectOnConstructors();
binder().disableCircularProxies();

bind(CommonLoggerFactory.class).toInstance(new Slf4jCommonLoggerFactory());
bind(TraceMetadataLoader.class).toProvider(TraceMetadataLoaderProvider.class);
bind(TraceMetadataLoaderService.class).toProvider(TraceMetadataLoaderServiceProvider.class).in(Scopes.SINGLETON);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@
import com.navercorp.pinpoint.profiler.context.module.ApplicationServerType;
import com.navercorp.pinpoint.profiler.context.module.Container;
import com.navercorp.pinpoint.profiler.util.RuntimeMXBeanUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.net.UnknownHostException;
import java.util.Objects;

/**
* @author Woonduk Kang(emeroad)
*/
public class AgentInformationProvider implements Provider<AgentInformation> {
private final Logger logger = LogManager.getLogger(this.getClass());

private final String agentId;
private final String agentName;
Expand Down Expand Up @@ -70,14 +74,25 @@ public AgentInformation get() {
public AgentInformation createAgentInformation() {

final String machineName = NetworkUtils.getHostName();
final String hostIp = NetworkUtils.getRepresentationHostIp();
String hostIp = getHostIp();

final int pid = RuntimeMXBeanUtils.getPid();
final String jvmVersion = JvmUtils.getSystemProperty(SystemPropertyKey.JAVA_VERSION);
return new DefaultAgentInformation(agentId, agentName, applicationName, isContainer, agentStartTime, pid, machineName, hostIp, serverType, jvmVersion, Version.VERSION);
}

private String checkId(String keyName,String id) {
private String getHostIp() {
String hostIp;
try {
hostIp = NetworkUtils.getHostIp();
} catch (UnknownHostException e) {
logger.info("Cannot resolve HostIp. HostIp is set to {}", NetworkUtils.LOOPBACK_ADDRESS_V4_1, e);
hostIp = NetworkUtils.LOOPBACK_ADDRESS_V4_1;
}
return NetworkUtils.getRepresentationHostIp(hostIp);
}

private String checkId(String keyName, String id) {
if (!IdValidateUtils.validateId(id)) {
throw new IllegalArgumentException("invalid " + keyName + "=" + id);
}
Expand Down
Loading

0 comments on commit e492e33

Please sign in to comment.