当前位置: 首页>>代码示例>>Java>>正文


Java Configurator.initialize方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.config.Configurator.initialize方法的典型用法代码示例。如果您正苦于以下问题:Java Configurator.initialize方法的具体用法?Java Configurator.initialize怎么用?Java Configurator.initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.core.config.Configurator的用法示例。


在下文中一共展示了Configurator.initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initLog4j

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
private static void initLog4j() {
    String log4jConfigFolderPath = System.getProperty("motu-config-dir");
    if (log4jConfigFolderPath != null && log4jConfigFolderPath.length() > 0) {
        if (!log4jConfigFolderPath.endsWith("/")) {
            log4jConfigFolderPath += "/";
        }
    } else {
        System.err.println("Error while initializing log4j. Property is not set motu-config-dir or has a bad value");
    }
    // Do not use system property to avoid conflicts with other tomcat webapps
    // System.setProperty("log4j.configurationFile", log4jConfigFolderPath + "log4j.xml");

    try {
        ConfigurationSource source = new ConfigurationSource(new FileInputStream(log4jConfigFolderPath + "log4j.xml"));
        Configurator.initialize(null, source);
    } catch (IOException e) {
        System.err.println("Error while initializing log4j from file: " + log4jConfigFolderPath + "log4j.xml");
        e.printStackTrace();
    }
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:21,代码来源:MotuWebEngineContextListener.java

示例2: setUp

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    Configurator
        .initialize("FastMQ", Thread.currentThread().getContextClassLoader(), "log4j2.xml");
    Log log = new Log();
    LogSegment logSegment = new LogSegment();
    logSegment.setLedgerId(ledgerId);
    logSegment.setTimestamp(System.currentTimeMillis());
    log.setSegments(Collections.singletonList(logSegment));
    when(logInfoStorage.getLogInfo(any())).thenReturn(log);

    CuratorFramework curatorFramework = CuratorFrameworkFactory
        .newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
    curatorFramework.start();
    asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
    offsetStorage = new ZkOffsetStorageImpl(logInfoStorage, asyncCuratorFramework);
}
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:18,代码来源:ZkOffsetStorageImplTest.java

示例3: buildLoggerContext

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
/**
 * Build logger context logger context.
 *
 * @param environment    the environment
 * @param resourceLoader the resource loader
 * @return the logger context
 */
public static Pair<Resource, LoggerContext> buildLoggerContext(final Environment environment, final ResourceLoader resourceLoader) {
    try {
        final String logFile = environment.getProperty("logging.config", "classpath:/log4j2.xml");
        LOGGER.debug("Located logging configuration reference in the environment as [{}]", logFile);

        if (ResourceUtils.doesResourceExist(logFile, resourceLoader)) {
            final Resource logConfigurationFile = resourceLoader.getResource(logFile);
            LOGGER.debug("Loaded logging configuration resource [{}]. Initializing logger context...", logConfigurationFile);
            final LoggerContext loggerContext = Configurator.initialize("CAS", null, logConfigurationFile.getURI());
            LOGGER.debug("Installing log configuration listener to detect changes and update");
            loggerContext.getConfiguration().addListener(reconfigurable -> loggerContext.updateLoggers(reconfigurable.reconfigure()));
            return Pair.of(logConfigurationFile, loggerContext);

        }
        LOGGER.warn("Logging configuration cannot be found in the environment settings");
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:ControllerUtils.java

示例4: main

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
/**
 * @param args
 * @throws InterruptedException
 */
public static void main(String[] args) throws InterruptedException {
    Configurator.initialize("CocaRMQBenchmark", Thread.currentThread().getContextClassLoader(), "rmq-log4j2.xml");

    // init coca
    CocaSample sub = new CocaSample("appSub", "syncGroup");
    sub.initCoca(CONF);

    int warmCount = CocaRMQBenchmark.warmCount;
    int writeCount = CocaRMQBenchmark.writeCount;
    int total = warmCount + writeCount;

    long s0 = System.currentTimeMillis();
    while (true) {
        if (sub.countSub() >= total) {
            break;
        }
        LOG.info("total-{} sub-{}", total, sub.countSub());
        Thread.sleep(5000L);
    }
    long s1 = System.currentTimeMillis();

    sub.close();
    LOG.info("sub-{} time-{}", sub.countSub() - warmCount, s1 - s0);
}
 
开发者ID:dzh,项目名称:coca,代码行数:29,代码来源:CocaRMQSub.java

示例5: main

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    // System.setProperty("log4j.configurationFile", "");
    Configurator.initialize("SampleMain", Thread.currentThread().getContextClassLoader(), "simple-log4j2.xml");

    // initialize coca instance
    CocaSample app1 = new CocaSample("app1", "syncGroup");
    app1.initCoca(CONF);
    CocaSample app2 = new CocaSample("app2", "syncGroup");
    app2.initCoca(CONF);

    // testRead(app1, app2);

    testShareWrite(app1, app2);

    // close
    app1.close();
    app2.close();
}
 
开发者ID:dzh,项目名称:coca,代码行数:23,代码来源:SampleMain.java

示例6: test

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
public void test(final String[] args) {
    System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
    // System.out.println(System.getProperty("java.class.path"));
    final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-msg-ansi.xml"
            : args[0];
    try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(),
            config)) {
        final Logger logger = LogManager.getLogger(ConsoleAppenderJAnsiMessageMain.class);
        logger.info(ansi().fg(RED).a("Hello").fg(CYAN).a(" World").reset());
        // JAnsi format:
        // logger.info("@|red Hello|@ @|cyan World|@");
        for (final Entry<Object, Object> entry : System.getProperties().entrySet()) {
            logger.info("@|KeyStyle {}|@ = @|ValueStyle {}|@", entry.getKey(), entry.getValue());
        }
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:ConsoleAppenderJAnsiMessageMain.java

示例7: testInitialize

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
@Test
public void testInitialize() throws Exception {
    final String log4jConfigString =
        "<Configuration name=\"ConfigTest\" status=\"debug\" >" +
            "<Appenders>" +
            " <Console name=\"STDOUT\">" +
            "    <PatternLayout pattern=\"%m%n\"/>" +
            " </Console>" +
            "</Appenders>" +
            "<Loggers>" +
            "  <Root level=\"error\">" +
            "    <AppenderRef ref=\"STDOUT\"/>" +
            "  </Root>" +
            "</Loggers>" +
            "</Configuration>";
    final InputStream is = new ByteArrayInputStream(log4jConfigString.getBytes());
    final ConfigurationFactory.ConfigurationSource source =
        new ConfigurationFactory.ConfigurationSource(is);
    final long begin = System.currentTimeMillis();
    Configurator.initialize(null, source);
    final long tookForInit = System.currentTimeMillis() - begin;
    System.out.println("log4j 2.0 initialization took " + tookForInit + "ms");
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:24,代码来源:Log4jInitPerformance.java

示例8: test

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
public void test(final String[] args) {
    System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
    // System.out.println(System.getProperty("java.class.path"));
    final String config = args == null || args.length == 0 ? "target/test-classes/log4j2-console-xex-ansi.xml"
            : args[0];
    final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
    final Logger logger = LogManager.getLogger(ConsoleAppenderJAnsiXExceptionMain.class);
    try {
        Files.getFileStore(Paths.get("?BOGUS?"));
    } catch (final Exception e) {
        final IllegalArgumentException logE = new IllegalArgumentException("Bad argument foo", e);
        logger.error("Gotcha!", logE);
    } finally {
        Configurator.shutdown(ctx);
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:ConsoleAppenderJAnsiXExceptionMain.java

示例9: main

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
public static void main(final String[] args) {
    // System.out.println(System.getProperty("java.class.path"));
    String config = args.length == 0 ? "target/test-classes/log4j2-180.xml" : args[0];
    final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config);
    try {
        LOG.fatal("Fatal message.");
        LOG.error("Error message.");
        LOG.warn("Warning message.");
        LOG.info("Information message.");
        LOG.debug("Debug message.");
        LOG.trace("Trace message.");
        try {
            throw new NullPointerException();
        } catch (Exception e) {
            LOG.error("Error message.", e);
            LOG.catching(Level.ERROR, e);
        }
    } finally {
        Configurator.shutdown(ctx);
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:22,代码来源:ConsoleAppenderAnsiStyleJira180Main.java

示例10: initializeNonJndi

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
private void initializeNonJndi(final String location) {
    if (this.name == null) {
        this.name = this.servletContext.getServletContextName();
        LOGGER.debug("Using the servlet context name \"{}\".", this.name);
    }
    if (this.name == null) {
        this.name = this.servletContext.getContextPath();
        LOGGER.debug("Using the servlet context context-path \"{}\".", this.name);
    }

    if (this.name == null && location == null) {
        LOGGER.error("No Log4j context configuration provided. This is very unusual.");
        this.name = new SimpleDateFormat("yyyyMMdd_HHmmss.SSS").format(new Date());
    }

    final URI uri = getConfigURI(location);
    this.loggerContext = Configurator.initialize(this.name, this.getClassLoader(), uri, this.servletContext);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:Log4jWebInitializerImpl.java

示例11: main

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
public static void main(final String[] args) {
    System.setProperty("log4j.skipJansi", "false"); // LOG4J2-2087: explicitly enable
    // System.out.println(System.getProperty("java.class.path"));
    final String config = args.length == 0 ? "target/test-classes/log4j2-272.xml" : args[0];
    try (final LoggerContext ctx = Configurator.initialize(ConsoleAppenderAnsiMessagesMain.class.getName(), config)) {
        LOG.fatal("Fatal message.");
        LOG.error("Error message.");
        LOG.warn("Warning message.");
        LOG.info("Information message.");
        LOG.debug("Debug message.");
        LOG.trace("Trace message.");
        try {
            throw new NullPointerException();
        } catch (final Exception e) {
            LOG.error("Error message.", e);
            LOG.catching(Level.ERROR, e);
        }
        LOG.warn("this is ok \n And all \n this have only\t\tblack colour \n and here is colour again?");
        LOG.info("Information message.");
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:ConsoleAppenderAnsiStyleJira272Main.java

示例12: main

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
public static void main(final String[] args) {
    // src/test/resources/log4j2-console-progress.xml
    // target/test-classes/log4j2-progress-console.xml
    try (final LoggerContext ctx = Configurator.initialize(ProgressConsoleTest.class.getName(),
            "target/test-classes/log4j2-progress-console.xml")) {
        for (double i = 0; i <= 1; i = i + 0.05) {
            updateProgress(i);
            try {
                Thread.sleep(100);
            } catch (final InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:ProgressConsoleTest.java

示例13: testConfig

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
@Test
public void testConfig() {
    final LoggerContext ctx = Configurator.initialize("Test1", "target/test-classes/log4j2-sdfilter.xml");
    final Configuration config = ctx.getConfiguration();
    final Filter filter = config.getFilter();
    assertNotNull("No StructuredDataFilter", filter);
    assertTrue("Not a StructuredDataFilter", filter instanceof  StructuredDataFilter);
    final StructuredDataFilter sdFilter = (StructuredDataFilter) filter;
    assertFalse("Should not be And filter", sdFilter.isAnd());
    final Map<String, List<String>> map = sdFilter.getMap();
    assertNotNull("No Map", map);
    assertTrue("No elements in Map", map.size() != 0);
    assertTrue("Incorrect number of elements in Map", map.size() == 1);
    assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
    assertTrue("List does not contain 2 elements", map.get("eventId").size() == 2);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:StructuredDataFilterTest.java

示例14: testConfig

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
@Test
public void testConfig() {
    try (final LoggerContext ctx = Configurator.initialize("Test1",
            "target/test-classes/log4j2-dynamicfilter.xml")) {
        final Configuration config = ctx.getConfiguration();
        final Filter filter = config.getFilter();
        assertNotNull("No DynamicThresholdFilter", filter);
        assertTrue("Not a DynamicThresholdFilter", filter instanceof DynamicThresholdFilter);
        final DynamicThresholdFilter dynamic = (DynamicThresholdFilter) filter;
        final String key = dynamic.getKey();
        assertNotNull("Key is null", key);
        assertEquals("Incorrect key value", "loginId", key);
        final Map<String, Level> map = dynamic.getLevelMap();
        assertNotNull("Map is null", map);
        assertEquals("Incorrect number of map elements", 1, map.size());
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:DynamicThresholdFilterTest.java

示例15: setUp

import org.apache.logging.log4j.core.config.Configurator; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    Configurator
        .initialize("FastMQ", Thread.currentThread().getContextClassLoader(), "log4j2.xml");
    CountDownLatch initLatch = new CountDownLatch(1);
    CuratorFramework curatorFramework = CuratorFrameworkFactory
        .newClient("127.0.0.1:2181", new ExponentialBackoffRetry(1000, 3));
    curatorFramework.start();
    AsyncCuratorFramework asyncCuratorFramework = AsyncCuratorFramework.wrap(curatorFramework);
    when(offsetStorage.queryOffset(any())).thenReturn(new Offset());

    ledgerManager = new LogManagerImpl("ledger-manager-read-test-name", new BookKeeperConfig(),
        new BookKeeper("127.0.0.1:2181"), asyncCuratorFramework,
        new LogInfoStorageImpl(asyncCuratorFramework), this.offsetStorage);
    ledgerManager.init(new CommonCallback<Void, LedgerStorageException>() {
        @Override
        public void onCompleted(Void data, Version version) {
            initLatch.countDown();
        }

        @Override
        public void onThrowable(LedgerStorageException throwable) {
            throwable.printStackTrace();
            initLatch.countDown();
        }
    });
    initLatch.await();
}
 
开发者ID:aCoder2013,项目名称:fastmq,代码行数:29,代码来源:LogManagerImplTest.java


注:本文中的org.apache.logging.log4j.core.config.Configurator.initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。