本文整理汇总了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}"));
}
示例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}"));
}
示例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");
}
示例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);
}
示例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);
}