本文整理了Java中org.apache.logging.log4j.core.appender.FileAppender.newBuilder()
方法的一些代码示例,展示了FileAppender.newBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileAppender.newBuilder()
方法的具体详情如下:
包路径:org.apache.logging.log4j.core.appender.FileAppender
类名称:FileAppender
方法名:newBuilder
暂无
代码示例来源:origin: org.apache.logging.log4j/log4j-core
/**
* Tests https://issues.apache.org/jira/browse/LOG4J2-1620
*/
@Test
public void testDefaultImmediateFlush() {
Assert.assertTrue(FileAppender.newBuilder().isImmediateFlush());
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
/**
* Validates that the code pattern we use to add an appender on the fly
* works with a basic appender that is not the new OutputStream appender or
* new Writer appender.
*/
@Test
public void testUpdatePatternWithFileAppender() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
// @formatter:off
final Appender appender = FileAppender.newBuilder()
.withFileName("target/" + getClass().getName() + ".log")
.withAppend(false)
.withName("File")
.withIgnoreExceptions(false)
.withBufferedIo(false)
.withBufferSize(4000)
.setConfiguration(config)
.build();
// @formatter:on
appender.start();
config.addAppender(appender);
ConfigurationTestUtils.updateLoggers(appender, config);
LogManager.getLogger().error("FOO MSG");
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testLazyCreate() throws Exception {
final Layout<String> layout = createPatternLayout();
// @formatter:off
final FileAppender appender = FileAppender.newBuilder()
.withFileName(FILE_NAME)
.withName("test")
.withImmediateFlush(false)
.withIgnoreExceptions(false)
.withBufferedIo(false)
.withBufferSize(1)
.withLayout(layout)
.withCreateOnDemand(createOnDemand)
.build();
// @formatter:on
Assert.assertEquals(createOnDemand, appender.getManager().isCreateOnDemand());
try {
Assert.assertNotEquals(createOnDemand, Files.exists(PATH));
appender.start();
Assert.assertNotEquals(createOnDemand, Files.exists(PATH));
} finally {
appender.stop();
}
Assert.assertNotEquals(createOnDemand, Files.exists(PATH));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final Layout<String> layout = createPatternLayout();
final FileAppender appender = FileAppender.newBuilder()
.withFileName(FILE_NAME)
.withName("test")
代码示例来源:origin: org.apache.logging.log4j/log4j-core
.build();
final FileAppender appender = FileAppender.newBuilder()
.withFileName(file.getAbsolutePath())
.withName("test")
代码示例来源:origin: org.apache.logging.log4j/log4j-core
.build();
final FileAppender appender = FileAppender.newBuilder()
.withFileName(file.getAbsolutePath())
.withName("test")
代码示例来源:origin: org.apache.logging.log4j/log4j-core
final Layout<String> layout = createPatternLayout();
final FileAppender appender = FileAppender.newBuilder()
.withFileName(FILE_NAME)
.withName("test")
代码示例来源:origin: org.apache.logging.log4j/log4j-core
.build();
final FileAppender appender = FileAppender.newBuilder()
.withFileName(LOG_FILE)
.withAppend(false)
代码示例来源:origin: com.github.redhatqe.byzantine/byzantine
/**
* Makes a FileAppender with the most common options
*
* @param filename
* @param layout
* @param name
* @return
*/
public static FileAppender makeFileAppender(String filename, PatternLayout layout, String name) {
return FileAppender.newBuilder()
.withFileName(filename)
.withBufferedIo(true)
.withLayout(layout)
.withName(name)
.build();
}
代码示例来源:origin: mopemope/meghanada-server
private static void addFileAppender() throws IOException {
String tempDir = System.getProperty("java.io.tmpdir");
File logFile = new File(tempDir, "meghanada_server.log");
Object ctx = LogManager.getContext(false);
if (ctx instanceof LoggerContext) {
try (LoggerContext context = (LoggerContext) ctx) {
Configuration configuration = context.getConfiguration();
LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
FileAppender fileAppender =
FileAppender.newBuilder()
.withName("file")
.withLayout(
PatternLayout.newBuilder()
.withPattern("[%d][%-5.-5p][%-14.-14c{1}:%4L] %-22.-22M - %m%n")
.build())
.withFileName(logFile.getCanonicalPath())
.build();
configuration.addAppender(fileAppender);
loggerConfig.addAppender(fileAppender, Level.ERROR, null);
context.updateLoggers();
}
}
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
final String advertiseUri,
final Configuration config) {
return FileAppender.<B>newBuilder()
.withAdvertise(Boolean.parseBoolean(advertise))
.withAdvertiseUri(advertiseUri)
代码示例来源:origin: elastic/support-diagnostics
public static void createFileAppender(String logDir, String logFile) {
logDir = logDir + SystemProperties.fileSeparator + logFile;
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration config = context.getConfiguration();
/*Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", null, config, null,
null,true, true, null, null );*/
Layout layout = PatternLayout.newBuilder()
.withConfiguration(config)
.withPattern("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n")
.build();
FileAppender.Builder builder = FileAppender.newBuilder();
builder.setConfiguration(config);
builder.withFileName(logDir);
builder.withAppend(false);
builder.withLocking(false);
builder.withName("File");
builder.withIgnoreExceptions(false);
builder.withImmediateFlush(true);
builder.withBufferedIo(false);
builder.withBufferSize(0);
builder.withLayout(layout);
builder.withAdvertise(false);
Appender appender = builder.build();
appender.start();
config.addAppender(appender);
AppenderRef.createAppenderRef("File", null, null);
config.getRootLogger().addAppender(appender, Level.DEBUG, null);
context.updateLoggers();
}
内容来源于网络,如有侵权,请联系作者删除!