本文整理了Java中org.apache.logging.log4j.core.Appender.start()
方法的一些代码示例,展示了Appender.start()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Appender.start()
方法的具体详情如下:
包路径:org.apache.logging.log4j.core.Appender
类名称:Appender
方法名:start
暂无
代码示例来源:origin: apache/hive
if (appNode.getObject() instanceof Appender) {
final Appender app = appNode.getObject();
app.start();
if (!(app instanceof RandomAccessFileAppender)) {
String message =
代码示例来源:origin: igniterealtime/Openfire
String addAppender(final Writer writer) {
final String name = "openfire-s2s-test-appender-" + StringUtils.randomString( 10 );
final LoggerContext context = LoggerContext.getContext(false);
final Configuration config = context.getConfiguration();
final PatternLayout layout = PatternLayout.createDefaultLayout(config);
final Appender appender = WriterAppender.createAppender(layout, null, writer, name, false, true);
appender.start();
config.addAppender(appender);
final Level level = null;
final Filter filter = null;
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(appender, level, filter);
}
config.getRootLogger().addAppender(appender, level, filter);
return name;
}
代码示例来源:origin: apache/incubator-druid
@BeforeClass
public static void setUpStatic()
{
appender = OutputStreamAppender
.newBuilder()
.setName("test stream")
.setTarget(baos)
.setLayout(JsonLayout.createLayout(false, true, false, true, true, StandardCharsets.UTF_8))
.build();
final Logger logger = (Logger)
LogManager.getLogger(LoggingRequestLogger.class);
appender.start();
logger.addAppender(appender);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
/**
* Tests that you can add an output stream appender dynamically.
*/
private void addAppender(final OutputStream outputStream, final String outputStreamName) {
final LoggerContext context = LoggerContext.getContext(false);
final Configuration config = context.getConfiguration();
final PatternLayout layout = PatternLayout.createDefaultLayout(config);
final Appender appender = OutputStreamAppender.createAppender(layout, null, outputStream, outputStreamName, false, true);
appender.start();
config.addAppender(appender);
ConfigurationTestUtils.updateLoggers(appender, config);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
private void addAppender(final Writer writer, final String writerName) {
final LoggerContext context = LoggerContext.getContext(false);
final Configuration config = context.getConfiguration();
final PatternLayout layout = PatternLayout.createDefaultLayout(config);
final Appender appender = WriterAppender.createAppender(layout, null, writer, writerName, false, true);
appender.start();
config.addAppender(appender);
ConfigurationTestUtils.updateLoggers(appender, config);
}
代码示例来源:origin: javamelody/javamelody
void register() {
if (LogManager.getContext(false) instanceof LoggerContext) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
if (ctx.getConfiguration() instanceof AbstractConfiguration) {
final AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
final Appender appender = getSingleton();
appender.start();
config.addAppender(appender);
final Logger rootLogger = LogManager.getRootLogger();
final LoggerConfig loggerConfig = config.getLoggerConfig(rootLogger.getName());
loggerConfig.addAppender(appender, null, null);
ctx.updateLoggers();
}
}
}
代码示例来源: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: mulesoft/mule
private void doAddAppender(LoggerContext context, Appender appender) {
appender.start();
context.getConfiguration().addAppender(appender);
getRootLogger(context).addAppender(appender, Level.ALL, null);
}
代码示例来源:origin: Meituan-Dianping/Zebra
fileInfoFilter, "false", null, null, config);
config.addAppender(fileInfoAppender);
fileInfoAppender.start();
AppenderRef fileInfoRef = AppenderRef.createAppenderRef("FileInfo", null, fileInfoFilter);
"false", "false");
config.addAppender(consoleErrorAppender);
consoleErrorAppender.start();
"ConsoleWarn", "false", "false");
config.addAppender(consoleWarnAppender);
consoleWarnAppender.start();
AppenderRef consoleWarnAppenderRef = AppenderRef.createAppenderRef("ConsoleWarn", Level.WARN, consoleWarnFilter);
AppenderRef consoleErrorAppenderRef = AppenderRef.createAppenderRef("ConsoleError", Level.WARN, null);
代码示例来源:origin: rhwayfun/spring-boot-learning-examples
@Override
protected void doConfigure() {
super.doConfigure();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = ctx.getConfiguration();
LoggerConfig rootLogger = getRootLogger();
rootLogger.setLevel(Level.INFO);
for (AppenderTypeEn appenderTypeEn : AppenderTypeEn.values()) {
Appender appender = AppenderUtil.createAppender(ctx, appenderTypeEn);
if (appender == null) {
continue;
}
appender.start();
addAppender(appender);
addLoggerWithRef(configuration, rootLogger, appenderTypeEn, appender);
}
for (LoggerTypeEn logger : LoggerTypeEn.values()) {
LoggerConfig loggerConfig = LoggerConfig.createLogger(true, logger.getLevel(), logger.getLoggerName(),
"true", new AppenderRef[]{}, null, configuration, null);
addLogger(logger.getLoggerName(), loggerConfig);
}
}
代码示例来源:origin: org.mule.munit/munit-runner
private static void doAddAppender(Configuration logConfiguration, Appender appender) {
appender.start();
logConfiguration.addAppender(appender);
LoggerConfig lc = ((AbstractConfiguration) logConfiguration).getRootLogger();
lc.addAppender(appender, Level.INFO, null);
}
}
代码示例来源:origin: apache/samza
private void attachAppenderToLoggers(Appender appender) {
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
// ensure appender is attached only once per JVM (regardless of #containers)
if (config.getRootLogger().getAppenders().get(SimpleDiagnosticsAppender.class.getName()) == null) {
LOG.info("Attaching diagnostics appender to root logger");
appender.start();
config.addAppender(appender);
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(appender, null, null);
}
}
}
代码示例来源:origin: ldbc/ldbc_graphalytics
public static void appendFileLogger(Level level, String name, Path filePath) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Layout layout = PatternLayout.createLayout("%d{HH:mm} [%-5p] %msg%n", null, config, null, null, true, false, null, null);
Appender appender = FileAppender.createAppender(filePath.toFile().getAbsolutePath(), "true", "false", name, "true",
"false", "false", "8192", layout, null, "false", null, config);
appender.start();
config.getRootLogger().addAppender(appender, level, null);
ctx.updateLoggers();
}
代码示例来源:origin: org.mule.modules/mule-module-launcher
private void doAddAppender(LoggerContext context, Appender appender)
{
appender.start();
context.getConfiguration().addAppender(appender);
getRootLogger(context).addAppender(appender, Level.ALL, null);
}
代码示例来源:origin: org.nuxeo.runtime/nuxeo-runtime-test
@Override
public void beforeRun(FeaturesRunner runner) throws Exception {
// create class filter
classFilter = instantiateFilter(() -> runner.getConfig(FilterWith.class),
() -> runner.getConfig(FilterOn.class));
if (classFilter == null) {
log.info("Class {} uses LogCaptureFeature without defining a filter",
runner.getTargetTestClass().getName());
}
// set current filter and start appender
currentFilter = classFilter;
logAppender.start();
LoggerContext.getContext(false).getRootLogger().addAppender(logAppender);
}
代码示例来源:origin: org.mule.runtime/mule-module-launcher
private void doAddAppender(LoggerContext context, Appender appender) {
appender.start();
context.getConfiguration().addAppender(appender);
getRootLogger(context).addAppender(appender, Level.ALL, null);
}
代码示例来源:origin: ldbc/ldbc_graphalytics
public static void appendSimplifiedConsoleLogger(Level level) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Layout layout = PatternLayout.createLayout("%msg%n", null, config, null, null, true, false, null, null);
Appender appender = ConsoleAppender.createAppender(layout, null, ConsoleAppender.Target.SYSTEM_OUT, "stdout", true, true);
appender.start();
config.getRootLogger().addAppender(appender, level, null);
ctx.updateLoggers();
}
代码示例来源:origin: ldbc/ldbc_graphalytics
public static void appendConsoleLogger(Level level) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Layout layout = PatternLayout.createLayout("%highlight{%d{HH:mm} [%-5p] %msg%n}{STYLE=Logback}", null, config, null, null, true, true, null, null);
Appender appender = ConsoleAppender.createAppender(layout, null, ConsoleAppender.Target.SYSTEM_OUT, "stdout", true, true);
appender.start();
config.getRootLogger().addAppender(appender, level, null);
ctx.updateLoggers();
}
代码示例来源:origin: apache/asterixdb
public static void start() {
final LoggerContext context = LoggerContext.getContext(false);
final Appender appender = WriterAppender.createAppender(null, null, new LogWriter(), "MEMORY", false, true);
appender.start();
final Configuration config = context.getConfiguration();
config.addAppender(appender);
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(appender, null, null);
}
config.getRootLogger().addAppender(appender, Level.ALL, null);
context.updateLoggers();
}
代码示例来源:origin: vitaly-chibrikov/homework_tester
private static Logger configureLog4j() {
LoggerContext context = (LoggerContext) LogManager.getContext();
Configuration config = context.getConfiguration();
PatternLayout layout = PatternLayout.createLayout("%m%n", null, null, Charset.defaultCharset(), false, false, null, null);
Appender appender = ConsoleAppender.createAppender(layout, null, null, "CONSOLE_APPENDER", null, null);
appender.start();
AppenderRef ref = AppenderRef.createAppenderRef("CONSOLE_APPENDER", null, null);
AppenderRef[] refs = new AppenderRef[]{ref};
LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "CONSOLE_LOGGER", "com", refs, null, null, null);
loggerConfig.addAppender(appender, null, null);
config.addAppender(appender);
config.addLogger("Main.class", loggerConfig);
context.updateLoggers(config);
return LogManager.getContext().getLogger("Main.class");
}
内容来源于网络,如有侵权,请联系作者删除!