From 617f990cfe0c42c57ba6c8e02dd7fc02082a6def Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Sat, 10 Nov 2018 13:11:51 +0800 Subject: [PATCH] arthas-boot remove logback dependency --- boot/pom.xml | 8 ------- .../com/taobao/arthas/boot/Bootstrap.java | 22 +++++++++---------- .../com/taobao/arthas/boot/DownloadUtils.java | 8 ++----- .../com/taobao/arthas/boot/ProcessUtils.java | 17 +++++--------- 4 files changed, 17 insertions(+), 38 deletions(-) diff --git a/boot/pom.xml b/boot/pom.xml index 1b2d39b7..092d4763 100644 --- a/boot/pom.xml +++ b/boot/pom.xml @@ -22,14 +22,6 @@ cli - - ch.qos.logback - logback-classic - - - ch.qos.logback - logback-core - diff --git a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java index d1f56646..03868bb1 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java +++ b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java @@ -14,10 +14,9 @@ import java.util.List; import javax.xml.parsers.ParserConfigurationException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; +import com.taobao.arthas.common.AnsiLog; import com.taobao.arthas.common.SocketUtils; import com.taobao.middleware.cli.CLI; import com.taobao.middleware.cli.CommandLine; @@ -39,7 +38,6 @@ import com.taobao.middleware.cli.annotations.Summary; + " java -jar arthas-boot.jar --target-ip 0.0.0.0 --telnet-port 9999' \n" + " java -jar arthas-boot.jar -f batch.as 127.0.0.1\n") public class Bootstrap { - private static final Logger logger = LoggerFactory.getLogger(Bootstrap.class); private static final int DEFAULT_TELNET_PORT = 3658; private static final int DEFAULT_HTTP_PORT = 8563; private static final String DEFAULT_TARGET_IP = "127.0.0.1"; @@ -187,13 +185,13 @@ public class Bootstrap { if (bootStrap.getTelnetPort() > 0) { telnetPortPid = SocketUtils.findTcpListenProcess(bootStrap.getTelnetPort()); if (telnetPortPid > 0) { - logger.info("Process {} already using port {}", telnetPortPid, bootStrap.getTelnetPort()); + AnsiLog.info("Process {} already using port {}", telnetPortPid, bootStrap.getTelnetPort()); } } if (bootStrap.getHttpPort() > 0) { httpPortPid = SocketUtils.findTcpListenProcess(bootStrap.getHttpPort()); if (httpPortPid > 0) { - logger.info("Process {} already using port {}", httpPortPid, bootStrap.getHttpPort()); + AnsiLog.info("Process {} already using port {}", httpPortPid, bootStrap.getHttpPort()); } } @@ -208,12 +206,12 @@ public class Bootstrap { } if (telnetPortPid > 0 && pid != telnetPortPid) { - logger.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.", + AnsiLog.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.", pid, bootStrap.getTelnetPort()); } if (httpPortPid > 0 && pid != httpPortPid) { - logger.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.", + AnsiLog.warn("Target process {} is not the process using port {}, you will connect to an unexpected process.", pid, bootStrap.getHttpPort()); } @@ -269,7 +267,7 @@ public class Bootstrap { verifyArthasHome(arthasHomeDir.getAbsolutePath()); - logger.info("arthas home: " + arthasHomeDir); + AnsiLog.info("arthas home: " + arthasHomeDir); // start arthas-core.jar List attachArgs = new ArrayList(); @@ -288,11 +286,11 @@ public class Bootstrap { attachArgs.add("-agent"); attachArgs.add(new File(arthasHomeDir, "arthas-agent.jar").getAbsolutePath()); - logger.info("Try to attach process " + pid); - logger.debug("Start arthas-core.jar args: " + attachArgs); + AnsiLog.info("Try to attach process " + pid); + AnsiLog.debug("Start arthas-core.jar args: " + attachArgs); ProcessUtils.startArthasCore(pid, attachArgs); - logger.info("Attach process {} success.", pid); + AnsiLog.info("Attach process {} success.", pid); if (bootStrap.isAttachOnly()) { System.exit(0); @@ -319,7 +317,7 @@ public class Bootstrap { telnetArgs.add(bootStrap.getTargetIp()); telnetArgs.add("" + bootStrap.getTelnetPort()); - logger.debug("Start arthas-client.jar args: " + telnetArgs); + AnsiLog.debug("Start arthas-client.jar args: " + telnetArgs); mainMethod.invoke(null, new Object[] { telnetArgs.toArray(new String[0]) }); } diff --git a/boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java b/boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java index ff8a20e7..61c90585 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java +++ b/boot/src/main/java/com/taobao/arthas/boot/DownloadUtils.java @@ -12,12 +12,11 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import com.taobao.arthas.common.AnsiLog; import com.taobao.arthas.common.IOUtils; /** @@ -26,9 +25,6 @@ import com.taobao.arthas.common.IOUtils; * */ public class DownloadUtils { - - private static final Logger logger = LoggerFactory.getLogger(DownloadUtils.class); - private static final String MAVEN_METADATA_URL = "${REPO}/com/taobao/arthas/arthas-packaging/maven-metadata.xml"; private static final String REMOTE_DOWNLOAD_URL = "${REPO}/com/taobao/arthas/arthas-packaging/${VERSION}/arthas-packaging-${VERSION}-bin.zip"; @@ -83,7 +79,7 @@ public class DownloadUtils { File tempFile = File.createTempFile("arthas", "arthas"); String remoteDownloadUrl = REMOTE_DOWNLOAD_URL.replace("${REPO}", repoUrl).replace("${VERSION}", arthasVersion); - logger.info("Start download arthas from remote server: " + remoteDownloadUrl); + AnsiLog.info("Start download arthas from remote server: " + remoteDownloadUrl); saveUrl(tempFile.getAbsolutePath(), remoteDownloadUrl); IOUtils.unzip(tempFile.getAbsolutePath(), unzipDir.getAbsolutePath()); diff --git a/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java b/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java index 03d47d88..8a1a65c2 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java +++ b/boot/src/main/java/com/taobao/arthas/boot/ProcessUtils.java @@ -1,10 +1,8 @@ package com.taobao.arthas.boot; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.Iterator; @@ -13,9 +11,7 @@ import java.util.List; import java.util.Map; import java.util.Scanner; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import com.taobao.arthas.common.AnsiLog; import com.taobao.arthas.common.ExecutingCommand; import com.taobao.arthas.common.IOUtils; @@ -25,8 +21,6 @@ import com.taobao.arthas.common.IOUtils; * */ public class ProcessUtils { - private static final Logger logger = LoggerFactory.getLogger(ProcessUtils.class); - private static String PID = "-1"; static { @@ -51,7 +45,7 @@ public class ProcessUtils { Map processMap = listProcessByJps(v); if (processMap.isEmpty()) { - logger.info("Can not find java process."); + AnsiLog.info("Can not find java process. Try to pass pid in command line."); return -1; } @@ -118,7 +112,6 @@ public class ProcessUtils { } return result; - } public static void startArthasCore(int targetPid, List attachArgs) { @@ -199,7 +192,7 @@ public class ProcessUtils { int exitValue = proc.exitValue(); if (exitValue != 0) { - logger.error("attach fail, targetPid: " + targetPid); + AnsiLog.error("attach fail, targetPid: " + targetPid); System.exit(1); } } catch (Throwable e) { @@ -219,7 +212,7 @@ public class ProcessUtils { } } - logger.debug("can not find java under current java home: " + javaHome); + AnsiLog.debug("can not find java under current java home: " + javaHome); return null; } @@ -234,7 +227,7 @@ public class ProcessUtils { } } - logger.debug("can not find jps under current java home: " + javaHome); + AnsiLog.debug("can not find jps under current java home: " + javaHome); return null; }