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


Java Appender.getLayout方法代碼示例

本文整理匯總了Java中org.apache.logging.log4j.core.Appender.getLayout方法的典型用法代碼示例。如果您正苦於以下問題:Java Appender.getLayout方法的具體用法?Java Appender.getLayout怎麽用?Java Appender.getLayout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.logging.log4j.core.Appender的用法示例。


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

示例1: testEnvironment

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testEnvironment() throws Exception {
    final LoggerContext ctx = Configurator.initialize("-config", null);
    LogManager.getLogger("org.apache.test.TestConfigurator");
    final Configuration config = ctx.getConfiguration();
    assertNotNull("No configuration", config);
    assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
    final Map<String, Appender> map = config.getAppenders();
    assertNotNull("Appenders map should not be null.", map);
    assertTrue("Appenders map should not be empty.", map.size() > 0);
    Appender app = null;
    for (final Map.Entry<String, Appender> entry: map.entrySet()) {
        if (entry.getKey().equals("List2")) {
            app = entry.getValue();
            break;
        }
    }
    assertNotNull("No ListAppender named List2", app);
    final Layout<? extends Serializable> layout = app.getLayout();
    assertNotNull("Appender List2 does not have a Layout", layout);
    assertTrue("Appender List2 is not configured with a PatternLayout", layout instanceof PatternLayout);
    final String pattern = ((PatternLayout) layout).getConversionPattern();
    assertNotNull("No conversion pattern for List2 PatternLayout", pattern);
    assertFalse("Environment variable was not substituted", pattern.startsWith("${env:PATH}"));
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:26,代碼來源:TestConfigurator.java

示例2: testEnvironment

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
@Test
public void testEnvironment() throws Exception {
    ctx = Configurator.initialize("-config", null);
    LogManager.getLogger("org.apache.test.TestConfigurator");
    final Configuration config = ctx.getConfiguration();
    assertNotNull("No configuration", config);
    assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
    final Map<String, Appender> map = config.getAppenders();
    assertNotNull("Appenders map should not be null.", map);
    assertThat(map, hasSize(greaterThan(0)));
    assertThat("No ListAppender named List2", map, hasKey("List2"));
    final Appender app = map.get("List2");
    final Layout<? extends Serializable> layout = app.getLayout();
    assertNotNull("Appender List2 does not have a Layout", layout);
    assertThat("Appender List2 is not configured with a PatternLayout", layout, instanceOf(PatternLayout.class));
    final String pattern = ((PatternLayout) layout).getConversionPattern();
    assertNotNull("No conversion pattern for List2 PatternLayout", pattern);
    assertFalse("Environment variable was not substituted", pattern.startsWith("${env:PATH}"));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:20,代碼來源:TestConfigurator.java

示例3: installLogFormat

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
private void installLogFormat() {
    Appender terminalAppender = CommonLogInstaller.getTerminalAppender(TERMINAL_NAME);

    Layout<? extends Serializable> oldLayout = terminalAppender.getLayout();
    String logFormat = configMapper.getInstance().getLogFormat();
    String appenderClass = terminalAppender.getClass().getName();
    if (oldLayout.toString().contains("minecraftFormatting") || appenderClass.contains("minecrell")) {
        logFormat = logFormat.replace("%msg", "%minecraftFormatting{%msg}");
    }

    if (configMapper.getInstance().isColorLoggingLevel()) {
        logFormat = logFormat.replace("%level",  "%highlight{%level}{"
                + "FATAL=" + configMapper.getInstance().getLevelColors().get("FATAL") + ", "
                + "ERROR=" + configMapper.getInstance().getLevelColors().get("ERROR") + ", "
                + "WARN=" + configMapper.getInstance().getLevelColors().get("WARN") + ", "
                + "INFO=" + configMapper.getInstance().getLevelColors().get("INFO") + ", "
                + "DEBUG=" + configMapper.getInstance().getLevelColors().get("DEBUG") + ", "
                + "TRACE=" + configMapper.getInstance().getLevelColors().get("TRACE") + '}');
    }

    String dateStyle = configMapper.getInstance().getDateStyle();
    logFormat = logFormat.replace("%d{HH:mm:ss}", "%style{" + "%d{HH:mm:ss}" + "}{" + dateStyle + '}');

    try {
        PatternLayout layout = CommonLogInstaller.createLayout(logFormat);
        CommonLogInstaller.setLayout(layout, terminalAppender);
    } catch (ReflectiveOperationException ex) {
        logger.warn("Cannot install log format", ex);
    }

    ColorPluginAppender pluginAppender = new ColorPluginAppender(terminalAppender, getConfig());
    pluginAppender.initPluginColors(getConfig().getPluginColors(), getConfig().getDefaultPluginColor());

    CommonLogInstaller.installAppender(pluginAppender, TERMINAL_NAME);
    CommonLogInstaller.installAppender(pluginAppender, "Console");
}
 
開發者ID:games647,項目名稱:ColorConsole,代碼行數:37,代碼來源:ColorConsoleSponge.java

示例4: ColorAppender

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
protected ColorAppender(Appender oldAppender, Collection<String> hideMessages
        , boolean colorizeTag, boolean truncateColor, Map<String, String> levelColors) {
    super(oldAppender.getName(), null, oldAppender.getLayout());

    this.oldAppender = oldAppender;
    this.formatter = new CommonFormatter(hideMessages, colorizeTag, truncateColor, levelColors);

}
 
開發者ID:games647,項目名稱:ColorConsole,代碼行數:9,代碼來源:ColorAppender.java

示例5: installLogFormat

import org.apache.logging.log4j.core.Appender; //導入方法依賴的package包/類
private void installLogFormat(Map<String, String> levelColors) {
    Appender terminalAppender = CommonLogInstaller.getTerminalAppender(TERMINAL_NAME);

    oldLayout = terminalAppender.getLayout();
    String logFormat = getConfig().getString("logFormat");
    String appenderClass = terminalAppender.getClass().getName();
    if (oldLayout.toString().contains("minecraftFormatting") || appenderClass.contains("minecrell")) {
        logFormat = logFormat.replace("%msg", "%minecraftFormatting{%msg}");
    }

    if (getConfig().getBoolean("colorLoggingLevel")) {
        logFormat = logFormat.replace("%level",  "%highlight{%level}{"
                + "FATAL=" + getConfig().getString("FATAL") + ", "
                + "ERROR=" + getConfig().getString("ERROR") + ", "
                + "WARN=" + getConfig().getString("WARN") + ", "
                + "INFO=" + getConfig().getString("INFO") + ", "
                + "DEBUG=" + getConfig().getString("DEBUG") + ", "
                + "TRACE=" + getConfig().getString("TRACE") + '}');
    }

    String dateStyle = getConfig().getString("dateStyle");
    logFormat = logFormat.replaceFirst("(%d)\\{.{1,}\\}", "%style{$0}{" + dateStyle + '}');
    try {
        PatternLayout layout = CommonLogInstaller.createLayout(logFormat);
        CommonLogInstaller.setLayout(layout, terminalAppender);
    } catch (ReflectiveOperationException ex) {
        getLogger().log(Level.WARNING, "Cannot install log format", ex);
    }

    ColorPluginAppender pluginAppender = new ColorPluginAppender(terminalAppender, getConfig(), levelColors);
    Map<String, String> colors = Maps.newHashMap();
    for (Map.Entry<String, Object> entry : getConfig().getValues(false).entrySet()) {
        if (!entry.getKey().startsWith("P-")) {
            continue;
        }

        colors.put(entry.getKey().replace("P-", ""), (String) entry.getValue());
    }

    pluginAppender.initPluginColors(colors, getConfig().getString("PLUGIN"));
    CommonLogInstaller.installAppender(pluginAppender, TERMINAL_NAME);
}
 
開發者ID:games647,項目名稱:ColorConsole,代碼行數:43,代碼來源:ColorConsoleBukkit.java


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