@Test public void testArthasHome() throws URISyntaxException { Properties properties1 = new Properties(); properties1.put("arthas.home", testResourcesDir); arthasEnvironment.addLast(new PropertiesPropertySource("test1", properties1)); LoggerContext loggerContext = LogUtil.initLooger(arthasEnvironment); Logger logger = loggerContext.getLogger("root"); Level level = logger.getLevel(); Assertions.assertThat(level).isEqualTo(Level.ERROR); }
public static LoggerContext initLooger(ArthasEnvironment env) { String loggingConfig = env.resolvePlaceholders(LOGGING_CONFIG); if (loggingConfig == null || loggingConfig.trim().isEmpty()) { return null; } AnsiLog.debug("arthas logging file: " + loggingConfig); File configFile = new File(loggingConfig); if (!configFile.isFile()) { AnsiLog.error("can not find arthas logging config: " + loggingConfig); return null; } try { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); String fileName = env.getProperty(FILE_NAME_PROPERTY); ; if (fileName != null) { loggerContext.putProperty(ARTHAS_LOG_FILE, fileName); } String filePath = env.getProperty(FILE_PATH_PROPERTY); if (filePath != null) { loggerContext.putProperty(ARTHAS_LOG_PATH, filePath); } JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(configFile.toURI().toURL()); Iterator<Appender<ILoggingEvent>> appenders = loggerContext.getLogger("root").iteratorForAppenders(); while (appenders.hasNext()) { Appender<ILoggingEvent> appender = appenders.next(); if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; if ("ARTHAS".equalsIgnoreCase(fileAppender.getName())) { logFile = fileAppender.getFile(); } } } return loggerContext; } catch (Throwable e) { AnsiLog.error("try to load arthas logging config file error: " + configFile, e); } return null; }
LogUtil { public static LoggerContext initLooger(ArthasEnvironment env) { String loggingConfig = env.resolvePlaceholders(LOGGING_CONFIG); if (loggingConfig == null || loggingConfig.trim().isEmpty()) { return null; } AnsiLog.debug("arthas logging file: " + loggingConfig); File configFile = new File(loggingConfig); if (!configFile.isFile()) { AnsiLog.error("can not find arthas logging config: " + loggingConfig); return null; } try { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); String fileName = env.getProperty(FILE_NAME_PROPERTY); ; if (fileName != null) { loggerContext.putProperty(ARTHAS_LOG_FILE, fileName); } String filePath = env.getProperty(FILE_PATH_PROPERTY); if (filePath != null) { loggerContext.putProperty(ARTHAS_LOG_PATH, filePath); } JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(configFile.toURI().toURL()); Iterator<Appender<ILoggingEvent>> appenders = loggerContext.getLogger("root").iteratorForAppenders(); while (appenders.hasNext()) { Appender<ILoggingEvent> appender = appenders.next(); if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; if ("ARTHAS".equalsIgnoreCase(fileAppender.getName())) { logFile = fileAppender.getFile(); } } } return loggerContext; } catch (Throwable e) { AnsiLog.error("try to load arthas logging config file error: " + configFile, e); } return null; } }
LogUtil { public static LoggerContext initLooger(ArthasEnvironment env) { String loggingConfig = env.resolvePlaceholders(LOGGING_CONFIG); if (loggingConfig == null || loggingConfig.trim().isEmpty()) { return null; } AnsiLog.debug("arthas logging file: " + loggingConfig); File configFile = new File(loggingConfig); if (!configFile.isFile()) { AnsiLog.error("can not find arthas logging config: " + loggingConfig); return null; } try { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); String fileName = env.getProperty(FILE_NAME_PROPERTY); ; if (fileName != null) { loggerContext.putProperty(ARTHAS_LOG_FILE, fileName); } String filePath = env.getProperty(FILE_PATH_PROPERTY); if (filePath != null) { loggerContext.putProperty(ARTHAS_LOG_PATH, filePath); } JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(configFile.toURI().toURL()); Iterator<Appender<ILoggingEvent>> appenders = loggerContext.getLogger("root").iteratorForAppenders(); while (appenders.hasNext()) { Appender<ILoggingEvent> appender = appenders.next(); if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; if ("ARTHAS".equalsIgnoreCase(fileAppender.getName())) { logFile = fileAppender.getFile(); } } } return loggerContext; } catch (Throwable e) { AnsiLog.error("try to load arthas logging config file error: " + configFile, e); } return null; }  }
LogUtil { public static LoggerContext initLooger(ArthasEnvironment env) { String loggingConfig = env.resolvePlaceholders(LOGGING_CONFIG); if (loggingConfig == null || loggingConfig.trim().isEmpty()) { return null; } AnsiLog.debug("arthas logging file: " + loggingConfig); File configFile = new File(loggingConfig); if (!configFile.isFile()) { AnsiLog.error("can not find arthas logging config: " + loggingConfig); return null; } try { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); String fileName = env.getProperty(FILE_NAME_PROPERTY); ; if (fileName != null) { loggerContext.putProperty(ARTHAS_LOG_FILE, fileName); } String filePath = env.getProperty(FILE_PATH_PROPERTY); if (filePath != null) { loggerContext.putProperty(ARTHAS_LOG_PATH, filePath); } JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(configFile.toURI().toURL()); Iterator<Appender<ILoggingEvent>> appenders = loggerContext.getLogger("root").iteratorForAppenders(); while (appenders.hasNext()) { Appender<ILoggingEvent> appender = appenders.next(); if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; if ("ARTHAS".equalsIgnoreCase(fileAppender.getName())) { logFile = fileAppender.getFile(); } } } return loggerContext; } catch (Throwable e) { AnsiLog.error("try to load arthas logging config file error: " + configFile, e); } return null; }  static LoggerContext initLooger(ArthasEnvironment env); static String loggingFile(); static String loggingDir(); static String cacheDir(); static Logger getResultLogger(); }
LogUtil { public static LoggerContext initLooger(ArthasEnvironment env) { String loggingConfig = env.resolvePlaceholders(LOGGING_CONFIG); if (loggingConfig == null || loggingConfig.trim().isEmpty()) { return null; } AnsiLog.debug("arthas logging file: " + loggingConfig); File configFile = new File(loggingConfig); if (!configFile.isFile()) { AnsiLog.error("can not find arthas logging config: " + loggingConfig); return null; } try { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.reset(); String fileName = env.getProperty(FILE_NAME_PROPERTY); ; if (fileName != null) { loggerContext.putProperty(ARTHAS_LOG_FILE, fileName); } String filePath = env.getProperty(FILE_PATH_PROPERTY); if (filePath != null) { loggerContext.putProperty(ARTHAS_LOG_PATH, filePath); } JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(loggerContext); configurator.doConfigure(configFile.toURI().toURL()); Iterator<Appender<ILoggingEvent>> appenders = loggerContext.getLogger("root").iteratorForAppenders(); while (appenders.hasNext()) { Appender<ILoggingEvent> appender = appenders.next(); if (appender instanceof RollingFileAppender) { RollingFileAppender fileAppender = (RollingFileAppender) appender; if ("ARTHAS".equalsIgnoreCase(fileAppender.getName())) { logFile = fileAppender.getFile(); } } } return loggerContext; } catch (Throwable e) { AnsiLog.error("try to load arthas logging config file error: " + configFile, e); } return null; }  static LoggerContext initLooger(ArthasEnvironment env); static String loggingFile(); static String loggingDir(); static String cacheDir(); static Logger getResultLogger(); static final String LOGGING_CONFIG_PROPERTY; static final String LOGGING_CONFIG; static final String FILE_NAME_PROPERTY; static final String ARTHAS_LOG_FILE; static final String FILE_PATH_PROPERTY; static final String ARTHAS_LOG_PATH; }