當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertyConfigurator類代碼示例

本文整理匯總了Java中org.apache.log4j.PropertyConfigurator的典型用法代碼示例。如果您正苦於以下問題:Java PropertyConfigurator類的具體用法?Java PropertyConfigurator怎麽用?Java PropertyConfigurator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PropertyConfigurator類屬於org.apache.log4j包,在下文中一共展示了PropertyConfigurator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUp

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
/**
 *  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();
}
 
開發者ID:kdgregory,項目名稱:log4j-aws-appenders,代碼行數:22,代碼來源:SNSAppenderIntegrationTest.java

示例2: configureLogger

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
/**
 * 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) { }
}
 
開發者ID:RipMeApp,項目名稱:ripme,代碼行數:24,代碼來源:Utils.java

示例3: main

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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();
        }
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:20,代碼來源:HelloImpl.java

示例4: handleOnChange

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
/**
 * 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);
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:23,代碼來源:Initializer.java

示例5: testSlowness

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
@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();
  }
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:21,代碼來源:TestLog4jAppender.java

示例6: noUiStart

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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();
}
 
開發者ID:ForJ-Latech,項目名稱:fwm,代碼行數:26,代碼來源:App.java

示例7: setupLog4j

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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");

    }
 
開發者ID:RestComm,項目名稱:phone-simulator,代碼行數:27,代碼來源:TesterHost.java

示例8: init

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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);
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:24,代碼來源:Log4jUtils.java

示例9: init

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
/**
 * 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();
	}
}
 
開發者ID:zrtzrt,項目名稱:CrawlerSYS,代碼行數:21,代碼來源:CrawlerServlet.java

示例10: initConf

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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);
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:22,代碼來源:RPCServer.java

示例11: main

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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();
    }

}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:22,代碼來源:Test2.java

示例12: main

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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();
    }

}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:26,代碼來源:Test3.java

示例13: main

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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();
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:26,代碼來源:Test.java

示例14: main

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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();
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:25,代碼來源:ClientTest.java

示例15: main

import org.apache.log4j.PropertyConfigurator; //導入依賴的package包/類
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();
    }
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:20,代碼來源:ClientTest.java


注:本文中的org.apache.log4j.PropertyConfigurator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。