java类org.apache.log4j.PropertyConfigurator的实例源码

SNSAppenderIntegrationTest.java 文件源码 项目:log4j-aws-appenders 阅读 22 收藏 0 点赞 0 评论 0
/**
 *  Loads the test-specific Log4J configuration and resets the environment.
 */
public void setUp(String propertiesName)
throws Exception
{
    URL config = ClassLoader.getSystemResource(propertiesName);
    assertNotNull("missing configuration: " + propertiesName, config);

    LogManager.resetConfiguration();
    PropertyConfigurator.configure(config);

    localLogger = Logger.getLogger(getClass());

    runId = String.valueOf(System.currentTimeMillis());
    resourceName = "SNSAppenderIntegrationTest-" + runId;
    System.setProperty("SNSAppenderIntegrationTest.resourceName", resourceName);

    localSNSclient = AmazonSNSClientBuilder.defaultClient();
    localSQSclient = AmazonSQSClientBuilder.defaultClient();
}
Initializer.java 文件源码 项目:oscm 阅读 23 收藏 0 点赞 0 评论 0
/**
 * On change event
 */
void handleOnChange(File logFile) {
    try {
        long lastModif = logFile.lastModified();
        if (lastModif > logFileLastModified) {
            logFileLastModified = lastModif;
            logger.debug("Reload log4j configuration from "
                    + logFile.getAbsolutePath());
            new PropertyConfigurator().doConfigure(
                    logFile.getAbsolutePath(),
                    LogManager.getLoggerRepository());
            logFileWarning = false;
        }
    } catch (Exception e) {
        if (!logFileWarning) {
            logFileWarning = true;
            logger.error(logFile.getAbsolutePath(), e);
        }
    }
}
App.java 文件源码 项目:fwm 阅读 34 收藏 0 点赞 0 评论 0
public static void noUiStart() throws Exception{
    AppConfig.firstInit();
    prod = AppConfig.getProd();
    appFileUtil = new AppFileUtil();
    if(!appFileUtil.success()){
        System.err.println(appFileUtil.getErrorMessage());
        System.exit(-1);
    }
    // ignore everything else because this means that we're in a jar file, so the app won't work
    // if it doesn't think that we're prod. 
    PropertyConfigurator.configure(appFileUtil.getLog4JFile().getAbsolutePath());
    AppConfig.init();

    String defaultLocationString = AppConfig.config.getString(AppConfig.WORLD_LOCATION);
    File defaultLocation = new File(defaultLocationString);


    defaultLocation.mkdirs();
    String relativePath = new File(".").toURI().relativize(defaultLocation.toURI()).getPath();
    AppConfig.saveDefaultWorldLocation("./" + relativePath);

    App.worldFileUtil = new WorldFileUtil(new File(AppConfig.config.getString(AppConfig.WORLD_LOCATION)));

    Backend.start();
}
TesterHost.java 文件源码 项目:phone-simulator 阅读 21 收藏 0 点赞 0 评论 0
private void setupLog4j(String appName) {

        // InputStream inStreamLog4j = getClass().getResourceAsStream("/log4j.properties");

        String propFileName = appName + ".log4j.properties";
        File f = new File("./" + propFileName);
        if (f.exists()) {

            try {
                InputStream inStreamLog4j = new FileInputStream(f);
                Properties propertiesLog4j = new Properties();

                propertiesLog4j.load(inStreamLog4j);
                PropertyConfigurator.configure(propertiesLog4j);
            } catch (Exception e) {
                e.printStackTrace();
                BasicConfigurator.configure();
            }
        } else {
            BasicConfigurator.configure();
        }

        // logger.setLevel(Level.TRACE);
        logger.debug("log4j configured");

    }
Log4jUtils.java 文件源码 项目:incubator-servicecomb-java-chassis 阅读 24 收藏 0 点赞 0 评论 0
public static void init(List<String> locationPatterns) throws Exception {
  if (inited) {
    return;
  }

  synchronized (LOCK) {
    if (inited) {
      return;
    }

    PropertiesLoader loader = new PropertiesLoader(locationPatterns);
    Properties properties = loader.load();
    if (properties.isEmpty()) {
      throw new Exception("can not find resource " + locationPatterns);
    }

    PropertyConfigurator.configure(properties);
    inited = true;

    // 如果最高优先级的文件是在磁盘上,且有写权限,则将merge的结果输出到该目录,方便维护时观察生效的参数
    outputFile(loader.getFoundResList(), properties);
  }
}
Utils.java 文件源码 项目:ripme 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Configures root logger, either for FILE output or just console.
 */
public static void configureLogger() {
    LogManager.shutdown();
    String logFile;
    if (getConfigBoolean("log.save", false)) {
        logFile = "log4j.file.properties";
    }
    else {
        logFile = "log4j.properties";
    }
    InputStream stream = Utils.class.getClassLoader().getResourceAsStream(logFile);
    if (stream == null) {
        PropertyConfigurator.configure("src/main/resources/" + logFile);
    } else {
        PropertyConfigurator.configure(stream);
    }
    logger.info("Loaded " + logFile);
    try {
        stream.close();
    } catch (IOException e) { }
}
CrawlerServlet.java 文件源码 项目:CrawlerSYS 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Initialization of the servlet. <br>
 *
 * @throws ServletException if an error occurs
 */
public void init() throws ServletException {
    String file = this.getServletContext().getRealPath(this.getInitParameter("log4j"));
    //从web.xml配置读取,名字一定要和web.xml配置一致
      if(file != null){
         PropertyConfigurator.configure(file);
      }
    // Put your code here
    new CrawlerServer(DefaultConfig.serverPort).start();
    try {
        new WebSocket(DefaultConfig.socketPort).start();
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
RPCServer.java 文件源码 项目:TakinRPC 阅读 25 收藏 0 点赞 0 评论 0
private void initConf() {
    try {
        String logpath = context.getConfigPath() + File.separator + "log4j.properties";
        PropertyConfigurator.configure(logpath);
        logger.info(String.format("log4j path:%s", logpath));

        String serverpath = context.getConfigPath() + File.separator + "server.properties";
        NettyServerConfig config = GuiceDI.getInstance(NettyServerConfig.class);
        PropertiesHelper pro = new PropertiesHelper(serverpath);
        config.setSelectorThreads(pro.getInt("selectorThreads"));
        config.setWorkerThreads(pro.getInt("workerThreads"));
        config.setListenPort(pro.getInt("server.Port"));
        config.setUsezk(pro.getBoolean("use.zk"));
        config.setZkhosts(pro.getString("zk.hosts"));

        logger.info(JSON.toJSONString(config));

    } catch (Exception e) {
        logger.error("", e);
    }
}
Test2.java 文件源码 项目:TakinRPC 阅读 28 收藏 0 点赞 0 评论 0
public static void main(String... args) throws Exception {
    PropertyConfigurator.configure("D:/log4j.properties");

    try {
        List<Replica> members = Lists.newArrayList();
        members.add(Replica.fromString("localhost:10000"));
        members.add(Replica.fromString("localhost:10002"));
        File logDir = new File("D:/raft1");
        logDir.mkdir();

        // configure the service
        RaftService raft = RaftService.newBuilder().local(Replica.fromString("localhost:10001")).members(members).logDir(logDir).timeout(300).build(new Test2());

        // start this replica
        raft.startAsync().awaitRunning();

    } catch (Exception e) {
        e.printStackTrace();
    }

}
Test3.java 文件源码 项目:TakinRPC 阅读 24 收藏 0 点赞 0 评论 0
public static void main(String... args) throws Exception {
    PropertyConfigurator.configure("D:/log4j.properties");

    try {
        List<Replica> members = Lists.newArrayList();
        members.add(Replica.fromString("localhost:10000"));
        members.add(Replica.fromString("localhost:10001"));
        File logDir = new File("D:/raft2");
        logDir.mkdir();

        // configure the service
        RaftService raft = RaftService.newBuilder().local(Replica.fromString("localhost:10002")).members(members).logDir(logDir).timeout(300).build(new Test3());

        // start this replica
        raft.startAsync().awaitRunning();

        // let's commit some things
        //            for (int i = 0; i < 10; i++) {
        //                raft.commit(new byte[] { 'O', '_', 'o' });
        //            }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
Test.java 文件源码 项目:TakinRPC 阅读 22 收藏 0 点赞 0 评论 0
public static void main(String... args) throws Exception {
    PropertyConfigurator.configure("D:/log4j.properties");

    try {
        List<Replica> members = Lists.newArrayList();
        members.add(Replica.fromString("localhost:10001"));
        members.add(Replica.fromString("localhost:10002"));
        File logDir = new File("D:/raft");
        logDir.mkdir();

        // configure the service
        RaftService raft = RaftService.newBuilder().local(Replica.fromString("localhost:10000")).members(members).logDir(logDir).timeout(300).build(new Test());

        // start this replica
        Service guavaservice = raft.startAsync();
        guavaservice.awaitRunning();

        // let's commit some things
        //            for (int i = 0; i < 10; i++) {
        //                raft.commit(new byte[] { 'O', '_', 'o' });
        //            }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
ClientTest.java 文件源码 项目:TakinRPC 阅读 24 收藏 0 点赞 0 评论 0
public static void main(String[] args) {
    try {
        RateLimiter limit = RateLimiter.create(100d);
        PropertyConfigurator.configure("conf/log4j.properties");
        while (true) {
            if (limit.tryAcquire()) {
                final HelloCommand command = new HelloCommand();
                //            System.out.println("result: " + command.execute());
                //            System.out.println("");

                Future<String> future = command.queue();
                System.out.println("result: " + future.get());
                System.out.println("");
            }
        }

        //            Observable<String> observe = command.observe();
        //            observe.asObservable().subscribe((result) -> {
        //                System.out.println(result);
        //            });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
HelloImpl.java 文件源码 项目:TakinRPC 阅读 22 收藏 0 点赞 0 评论 0
public static void main(String[] args) {
    PropertyConfigurator.configure("conf/log4j.properties");
    Method[] methods = HelloImpl.class.getDeclaredMethods();
    for (Method method : methods) {
        System.out.println(method.getName());
        Class<?>[] param = method.getParameterTypes();
        System.out.println(JSON.toJSONString(param));
        try {
            Method m2 = RMethodUtils.searchMethod(HelloImpl.class, method.getName(), param);
            if (m2 == null) {
                System.out.println("null");
            } else {
                System.out.println(method.getName());
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
ClientTest.java 文件源码 项目:TakinRPC 阅读 25 收藏 0 点赞 0 评论 0
public static void main(String[] args) {
    try {
        PropertyConfigurator.configure("conf/log4j.properties");
        final Hello hello = ProxyFactory.create(Hello.class, "test", null, null);
        System.out.println("result: " + hello.say("xiaoming"));
        System.out.println("");
        System.out.println("result: " + hello.hi(2));
        System.out.println("");
        //            System.out.println("result: " + hello.hi(2));
        //            System.out.println("");
        //            System.out.println("result: " + hello.hi(2));
        //            System.out.println("");
        //            System.out.println("result: " + hello.hi(2));
        System.out.println("");
        // 
    } catch (Exception e) {
        e.printStackTrace();
    }
}
ClientBeanTest.java 文件源码 项目:TakinRPC 阅读 20 收藏 0 点赞 0 评论 0
@Test
public void testbean() {
    try {
        PropertyConfigurator.configure("conf/log4j.properties");
        final Hello hello = ProxyFactory.create(Hello.class, "test", null, null);

        User u = new User();
        u.setAge(12);
        u.setName("nana");
        u.setStart(new Date());
        System.out.println("");
        u.setName("lua");
        System.out.println("");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
ClientBeanTest.java 文件源码 项目:TakinRPC 阅读 37 收藏 0 点赞 0 评论 0
@Test
public void testList() {
    try {
        PropertyConfigurator.configure("conf/log4j.properties");
        final Hello hello = ProxyFactory.create(Hello.class, "test", null, null);

        User u = new User();
        u.setAge(12);
        u.setName("nana");
        u.setStart(new Date());
        System.out.println("result: " + hello.getall(u));
        System.out.println("");
        u.setName("lua");
        System.out.println("result: " + hello.getall(u));
        System.out.println("");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
KMSWebApp.java 文件源码 项目:hadoop-oss 阅读 32 收藏 0 点赞 0 评论 0
private void initLogging(String confDir) {
  if (System.getProperty("log4j.configuration") == null) {
    System.setProperty("log4j.defaultInitOverride", "true");
    boolean fromClasspath = true;
    File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile();
    if (log4jConf.exists()) {
      PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000);
      fromClasspath = false;
    } else {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      URL log4jUrl = cl.getResource(LOG4J_PROPERTIES);
      if (log4jUrl != null) {
        PropertyConfigurator.configure(log4jUrl);
      }
    }
    LOG = LoggerFactory.getLogger(KMSWebApp.class);
    LOG.debug("KMS log starting");
    if (fromClasspath) {
      LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES);
      LOG.warn("Logging with INFO level to standard output");
    }
  } else {
    LOG = LoggerFactory.getLogger(KMSWebApp.class);
  }
}
PortMethodTest.java 文件源码 项目:OftenPorter 阅读 24 收藏 0 点赞 0 评论 0
@Test
public void testSort()
{
    PropertyConfigurator.configure(getClass().getResource("/log4j.properties"));
    PortMethod[] methods = {
            PortMethod.POST, PortMethod.GET, PortMethod.PUT, PortMethod.DELETE
    };
    Arrays.sort(methods);

    Assert.assertTrue(Arrays.binarySearch(methods, PortMethod.POST) >= 0);
    Assert.assertTrue(Arrays.binarySearch(methods, PortMethod.GET) >= 0);
    Assert.assertTrue(Arrays.binarySearch(methods, PortMethod.PUT) >= 0);
    Assert.assertTrue(Arrays.binarySearch(methods, PortMethod.DELETE) >= 0);

    Assert.assertTrue(Arrays.binarySearch(methods, PortMethod.OPTIONS) < 0);
    Assert.assertTrue(Arrays.binarySearch(methods, PortMethod.TARCE) < 0);
    Assert.assertTrue(Arrays.binarySearch(methods, PortMethod.HEAD) < 0);


}
LoggerFactory.java 文件源码 项目:opencron 阅读 29 收藏 0 点赞 0 评论 0
public static Logger getLogger(@SuppressWarnings("rawtypes") Class clazz) {

        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        URL url = loader.getResource("log4j.properties");
        String path;
        if (url==null) {
            String currPath = LoggerFactory.class.getProtectionDomain().getCodeSource().getLocation().getFile();
            File file = new File(currPath);
            path = file.getParentFile().getParentFile() + "/conf/log4j.properties";
            if (!new File(path).exists()) {
                throw new ExceptionInInitializerError("[opencron] error: can not found log4j.properties...");
            }
        }else {
            path = url.getPath();
        }
        PropertyConfigurator.configure(path);
        return org.slf4j.LoggerFactory.getLogger(clazz);
    }
Initializer.java 文件源码 项目:oscm-app 阅读 24 收藏 0 点赞 0 评论 0
/**
 * On change event
 */
void handleOnChange(File logFile) {
    try {
        long lastModif = logFile.lastModified();
        if (lastModif > logFileLastModified) {
            logFileLastModified = lastModif;
            logger.debug("Reload log4j configuration from "
                    + logFile.getAbsolutePath());
            new PropertyConfigurator().doConfigure(
                    logFile.getAbsolutePath(),
                    LogManager.getLoggerRepository());
            logFileWarning = false;
        }
    } catch (Exception e) {
        if (!logFileWarning) {
            logFileWarning = true;
            logger.error(logFile.getAbsolutePath(), e);
        }
    }
}
Initializer.java 文件源码 项目:oscm 阅读 27 收藏 0 点赞 0 评论 0
/**
 * On change event
 */
void handleOnChange(File logFile) {
    try {
        long lastModif = logFile.lastModified();
        if (lastModif > logFileLastModified) {
            logFileLastModified = lastModif;
            LOGGER.debug("Reload log4j configuration from " + logFile.getAbsolutePath());
            new PropertyConfigurator().doConfigure(logFile.getAbsolutePath(), LogManager.getLoggerRepository());
            logFileWarning = false;
        }
    } catch (Exception e) {
        if (!logFileWarning) {
            logFileWarning = true;
            LOGGER.error(logFile.getAbsolutePath(), e);
        }
    }
}
Initializer.java 文件源码 项目:oscm 阅读 23 收藏 0 点赞 0 评论 0
/**
 * On change event
 */
void handleOnChange(File logFile) {
    try {
        long lastModif = logFile.lastModified();
        if (lastModif > logFileLastModified) {
            logFileLastModified = lastModif;
            LOGGER.debug("Reload log4j configuration from "
                    + logFile.getAbsolutePath());
            new PropertyConfigurator().doConfigure(
                    logFile.getAbsolutePath(),
                    LogManager.getLoggerRepository());
            logFileWarning = false;
        }
    } catch (Exception e) {
        if (!logFileWarning) {
            logFileWarning = true;
            LOGGER.error(logFile.getAbsolutePath(), e);
        }
    }
}
Log4JInstrumentationTest.java 文件源码 项目:JInsight 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void testLoggerReconfiguration() throws Exception {
  logger.setLevel(Level.ERROR);

  Map<String, Long> expectedCounts = getCurrentCounts();
  expectedCounts.compute("total", (s, aLong) -> aLong + 1);
  expectedCounts.compute("error", (s, aLong) -> aLong + 1);

  Properties properties = new Properties();
  properties.setProperty("log4j.rootCategory", "INFO,TestLog");
  properties.setProperty("log4j.appender.TestLog", "org.apache.log4j.ConsoleAppender");
  properties.setProperty("log4j.appender.TestLog.layout", "org.apache.log4j.PatternLayout");
  PropertyConfigurator.configure(properties);

  logger.error("error!");
  assertEquals(expectedCounts, getCurrentCounts());

}
iBenchDriver.java 文件源码 项目:ibench 阅读 33 收藏 0 点赞 0 评论 0
private static void setUpExperimentalLogger(File pathF) throws IOException {

    Logger.getRootLogger().removeAllAppenders();
    log.removeAllAppenders();

    PropertyConfigurator.configure("resource/log4jproperties.txt");

    FileAppender resultAppender = new FileAppender(
            new PatternLayout("%m"),
            new File(pathF, "result.txt").toString(), false);

    LevelRangeFilter infoFilter = new LevelRangeFilter();
    infoFilter.setLevelMin(Level.INFO);
    infoFilter.setLevelMax(Level.FATAL);
    infoFilter.setAcceptOnMatch(true);
    resultAppender.addFilter(infoFilter);
    log.addAppender(resultAppender);
    Logger.getLogger(iBench.class).addAppender(resultAppender);

}
iBenchDriver.java 文件源码 项目:ibench 阅读 23 收藏 0 点赞 0 评论 0
private static void setUpConfigLogger(File pathF, String configName) throws IOException {
    Logger.getRootLogger().removeAllAppenders();

    String nameSuffix = configName.replace(".txt", "");

    PropertyConfigurator.configure("resource/log4jproperties.txt"); 

    FileAppender logFileAppender = new FileAppender(
            new PatternLayout("%-4r [%t] %-5p %c %x - %m%n"),
            new File(pathF, "log_" + nameSuffix + ".txt").toString(), false);
    Logger.getRootLogger().addAppender(logFileAppender);

    if (opt.logToConsole)
        Logger.getRootLogger().addAppender(new ConsoleAppender(
                new PatternLayout("%-4r [%t] %-5p %c %x - %m%n")));
}
TestLog4jAppender.java 文件源码 项目:flume-release-1.7.0 阅读 19 收藏 0 点赞 0 评论 0
@Test(expected = EventDeliveryException.class)
public void testSlowness() throws Throwable {
  ch = new SlowMemoryChannel(2000);
  Configurables.configure(ch, new Context());
  configureSource();
  props.put("log4j.appender.out2.Timeout", "1000");
  props.put("log4j.appender.out2.layout", "org.apache.log4j.PatternLayout");
  props.put("log4j.appender.out2.layout.ConversionPattern",
      "%-5p [%t]: %m%n");
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  Thread.currentThread().setName("Log4jAppenderTest");
  int level = 10000;
  String msg = "This is log message number" + String.valueOf(1);
  try {
    logger.log(Level.toLevel(level), msg);
  } catch (FlumeException ex) {
    throw ex.getCause();
  }
}
Property.java 文件源码 项目:CrypDist 阅读 26 收藏 0 点赞 0 评论 0
public Property() {

        PropertyConfigurator.configure(this.getClass().getResourceAsStream("log4j_custom.properties"));
        Logger l1 = Logger.getLogger("P2P");
        Appender a = new CustomAppender();
        l1.addAppender(a);

        l1 = Logger.getLogger("BlockchainManager");
        l1.addAppender(a);

        l1 = Logger.getLogger("DbManager");
        l1.addAppender(a);

        l1 = Logger.getLogger("CrypDist");
        l1.addAppender(a);

        try {
            Config.PRIVATE_KEY = new String((IOUtils.toByteArray(getClass().getResourceAsStream("private.pem"))) );

        } catch (Exception e) {

        }
    }
OnlineSectioningTestFwk.java 文件源码 项目:unitimes 阅读 17 收藏 0 点赞 0 评论 0
protected void configureLogging() {
       Properties props = new Properties();
       props.setProperty("log4j.rootLogger", "DEBUG, A1");
       props.setProperty("log4j.appender.A1", "org.apache.log4j.ConsoleAppender");
       props.setProperty("log4j.appender.A1.layout", "org.apache.log4j.PatternLayout");
       props.setProperty("log4j.appender.A1.layout.ConversionPattern","%-5p %c{2}: %m%n");
       props.setProperty("log4j.logger.org.hibernate","INFO");
       props.setProperty("log4j.logger.org.hibernate.cfg","WARN");
       props.setProperty("log4j.logger.org.hibernate.cache.EhCacheProvider","ERROR");
       props.setProperty("log4j.logger.org.unitime.commons.hibernate","INFO");
       props.setProperty("log4j.logger.net","INFO");
       props.setProperty("log4j.logger.org.unitime.timetable.onlinesectioning","WARN");
       props.setProperty("log4j.logger.org.unitime.timetable.onlinesectioning.test","INFO");
       props.setProperty("log4j.logger." + OnlineSectioningTestFwk.class.getName(), "INFO");
       props.setProperty("log4j.logger.org.cpsolver.ifs.util.JProf", "INFO");
       props.setProperty("log4j.logger.org.jgroups", "INFO");
       props.setProperty("log4j.logger.net.sf.ehcache.distribution.jgroups", "WARN");
       props.setProperty("log4j.logger.org.hibernate.cache.ehcache.AbstractEhcacheRegionFactory", "ERROR");
       props.setProperty("log4j.logger.net.sf.ehcache.distribution.jgroups.JGroupsCacheReceiver", "ERROR");
       props.setProperty("log4j.logger.org.unitime.timetable.solver.jgroups.DummySolverServer", "INFO");
       PropertyConfigurator.configure(props);
}
SolverServerImplementation.java 文件源码 项目:unitimes 阅读 19 收藏 0 点赞 0 评论 0
private static void configureLogging(Properties properties) {
       PropertyConfigurator.configure(properties);

       Logger log = Logger.getRootLogger();
       log.info("-----------------------------------------------------------------------");
       log.info("UniTime Log File");
       log.info("");
       log.info("Created: " + new Date());
       log.info("");
       log.info("System info:");
       log.info("System:      " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"));
       log.info("CPU:         " + System.getProperty("sun.cpu.isalist") + " endian:" + System.getProperty("sun.cpu.endian") + " encoding:" + System.getProperty("sun.io.unicode.encoding"));
       log.info("Java:        " + System.getProperty("java.vendor") + ", " + System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version", System.getProperty("java.version")));
       log.info("User:        " + System.getProperty("user.name"));
       log.info("Timezone:    " + System.getProperty("user.timezone"));
       log.info("Working dir: " + System.getProperty("user.dir"));
       log.info("Classpath:   " + System.getProperty("java.class.path"));
       log.info("Memory:      " + (Runtime.getRuntime().maxMemory() / 1024 / 1024) + " MB");
       log.info("Cores:       " + Runtime.getRuntime().availableProcessors());
       log.info("");
}
KMSWebApp.java 文件源码 项目:hadoop 阅读 24 收藏 0 点赞 0 评论 0
private void initLogging(String confDir) {
  if (System.getProperty("log4j.configuration") == null) {
    System.setProperty("log4j.defaultInitOverride", "true");
    boolean fromClasspath = true;
    File log4jConf = new File(confDir, LOG4J_PROPERTIES).getAbsoluteFile();
    if (log4jConf.exists()) {
      PropertyConfigurator.configureAndWatch(log4jConf.getPath(), 1000);
      fromClasspath = false;
    } else {
      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      URL log4jUrl = cl.getResource(LOG4J_PROPERTIES);
      if (log4jUrl != null) {
        PropertyConfigurator.configure(log4jUrl);
      }
    }
    LOG = LoggerFactory.getLogger(KMSWebApp.class);
    LOG.debug("KMS log starting");
    if (fromClasspath) {
      LOG.warn("Log4j configuration file '{}' not found", LOG4J_PROPERTIES);
      LOG.warn("Logging with INFO level to standard output");
    }
  } else {
    LOG = LoggerFactory.getLogger(KMSWebApp.class);
  }
}


问题


面经


文章

微信
公众号

扫码关注公众号