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


Java Configuration.addAppender方法代码示例

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


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

示例1: addFileAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private static void addFileAppender() throws IOException {
  final String tempDir = System.getProperty("java.io.tmpdir");
  final File logFile = new File(tempDir, "meghanada_server.log");
  final LoggerContext context = (LoggerContext) LogManager.getContext(false);
  final Configuration configuration = context.getConfiguration();
  final LoggerConfig loggerConfig = configuration.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
  final 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();
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:20,代码来源:Main.java

示例2: configureLogging

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
protected void configureLogging() {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    Layout layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN, null, config, null, null,
            true, false, null, null);
    Appender appender = FileAppender.createAppender(workDir + "/logs/camel-standalone.log", "false", "false", "File", "true",
            "false", "false", "4000", layout, null, "false", null, config);
    appender.start();
    config.addAppender(appender);
    AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
    AppenderRef[] refs = new AppenderRef[] {ref};
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, "StandaloneFileLoggerConfig",
            "true", refs, null, config, null );
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("StandaloneFileLoggerConfig", loggerConfig);
    ctx.updateLoggers();
}
 
开发者ID:Steve973,项目名称:camel-standalone,代码行数:18,代码来源:Standalone.java

示例3: configureLog4j

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
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");
}
 
开发者ID:vitaly-chibrikov,项目名称:homework_tester,代码行数:18,代码来源:Main.java

示例4: bindLogger

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public static void bindLogger() {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();

    Map<String, ESLogger> loggers = Maps.newConcurrentHashMap();
    Appender appender = new AbstractAppender("", null, null) {
        @Override
        public void append(LogEvent event) {
            String name = event.getLoggerName();
            ESLogger logger = loggers.computeIfAbsent(name, key -> new ESLogger(key, null, (LoggerImpl) LoggerFactory.getLogger(key)));
            logger.log(event.getLevel(), event.getMarker(), event.getMessage(), event.getThrown());
        }
    };
    appender.start();
    config.addAppender(appender);

    LoggerConfig loggerConfig = new LoggerConfig("", Level.ALL, false);
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("", loggerConfig);
    context.updateLoggers();
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:22,代码来源:ESLoggerConfigFactory.java

示例5: setUpAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
@Before
public void setUpAppender() throws IOException {
    file = folder.newFile();

    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    final LoggerConfig root = ((AbstractConfiguration) config).getRootLogger();

    PatternLayout layout = PatternLayout.createLayout("[%p] %m%n", config, null, null, true, false, null, null);
    FileAppender appender = FileAppender.createAppender(file.getAbsolutePath(), "true", "false", "TestLogFile", "true", "false", "false", "8192", layout, null, "false", null, config);

    appender.start();
    config.addAppender(appender);

    root.addAppender(appender, null, null);
    ctx.updateLoggers();
}
 
开发者ID:DjDCH,项目名称:Log4j-StaticShutdown,代码行数:18,代码来源:Log4jShutdownTest.java

示例6: createFileAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private void createFileAppender(DiagnosticContext ctx) {

      String logDir = ctx.getTempDir() + SystemProperties.fileSeparator + "diagnostics.log";

      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 );
      Appender appender = FileAppender.createAppender(logDir, "false", "false", "File", "true",
         "false", "false", "0", layout, null, "false", null, config);
      appender.start();
      config.addAppender(appender);
      AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
      AppenderRef[] refs = new AppenderRef[] {ref};

      config.getRootLogger().addAppender(appender, null, null);
      context.updateLoggers();
      Logger testLog = LogManager.getLogger();
      testLog.error("Testing");
   }
 
开发者ID:elastic,项目名称:elasticsearch-support-diagnostics,代码行数:21,代码来源:Diagnostic.java

示例7: testUpdatePatternWithFileAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
 * 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");
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:26,代码来源:OutputStreamAppenderTest.java

示例8: addFollowConsoleAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
private void addFollowConsoleAppender() {
    final LoggerContext context = LoggerContext.getContext(false);
    final Configuration config = context.getConfiguration();
    final PatternLayout layout = PatternLayout.newBuilder().withPattern("%-5level %c{-4} - %msg%n").build();
    Appender appender = ConsoleAppender.newBuilder().setFollow(true).setTarget(ConsoleAppender.Target.SYSTEM_OUT)
            .withName("ExecutionRecorder").withLayout(layout).build();
    appender.start();
    config.addAppender(appender);
    config.getRootLogger().addAppender(appender, logLevel, null);
}
 
开发者ID:RUB-NDS,项目名称:TLS-Attacker,代码行数:11,代码来源:ExecutionRecorder.java

示例9: createConsoleLogger

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
 * Creates console appender with some reasonable default logging settings.
 *
 * @return Logger with auto configured console appender.
 */
public Logger createConsoleLogger() {
    // from http://logging.apache.org/log4j/2.x/manual/customconfig.html
    final LoggerContext ctx = impl.getContext();

    final Configuration cfg = ctx.getConfiguration();

    PatternLayout.Builder builder = PatternLayout.newBuilder()
        .withPattern("%d{ISO8601}][%-5p][%t][%c{1}] %m%n")
        .withCharset(Charset.defaultCharset())
        .withAlwaysWriteExceptions(false)
        .withNoConsoleNoAnsi(false);

    PatternLayout layout = builder.build();

    ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder()
        .withName(CONSOLE_APPENDER)
        .withLayout(layout);

    ConsoleAppender consoleApp = consoleAppenderBuilder.build();

    consoleApp.start();

    cfg.addAppender(consoleApp);
    cfg.getRootLogger().addAppender(consoleApp, Level.TRACE, null);

    ctx.updateLoggers(cfg);

    return ctx.getRootLogger();
}
 
开发者ID:apache,项目名称:ignite,代码行数:35,代码来源:Log4J2Logger.java

示例10: install

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public void install() {
    if (installed.compareAndSet(false, true)) {
        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration config = ctx.getConfiguration();
        config.addAppender(this);

        for (LoggerConfig loggerConfig : config.getLoggers().values()) {
            loggerConfig.addAppender(this, Level.INFO, null);
        }
    }

    start();
}
 
开发者ID:jivesoftware,项目名称:miru,代码行数:14,代码来源:HttpKinesisLogAppender.java

示例11: install

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
public void install() {
    if (installed.compareAndSet(false, true)) {
        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        Configuration config = ctx.getConfiguration();
        config.addAppender(this);

        for (LoggerConfig loggerConfig : config.getLoggers().values()) {
            loggerConfig.addAppender(this, Level.INFO, null); // TODO expose to config
        }
    }

    start();
}
 
开发者ID:jivesoftware,项目名称:miru,代码行数:14,代码来源:MiruStumptownInternalLogAppender.java

示例12: addRootApender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
 * Adds the specified appender to the root logger.
 * 
 * @param appender
 *            the appender
 * @param level
 *            the logging level to assign to the appender. Default is INFO
 */
public static synchronized void addRootApender(Appender appender, String level) {
	Configuration config = getConfiguration();
	appender.start();
	config.addAppender(appender);
	Level l = Level.toLevel(level, Level.INFO);

	LoggerConfig root = config.getRootLogger();
	if (!root.getLevel().isLessSpecificThan(l)) {
		if (originalRootLevel == null) {
			originalRootLevel = root.getLevel();
			Iterator<AppenderRef> it = root.getAppenderRefs().iterator();
			while (it.hasNext()) {
				AppenderRef ar = it.next();
				if (ar.getLevel() == null) {
					Appender a = root.getAppenders().get(ar.getRef());
					root.removeAppender(a.getName());
					root.addAppender(a, originalRootLevel, ar.getFilter());
				}
			}
		}
		root.setLevel(l);
	}
	root.addAppender(appender, l, null);
	addedAppenders++;
	getContext().updateLoggers();
}
 
开发者ID:sfera-labs,项目名称:sfera,代码行数:35,代码来源:LoggerUtils.java

示例13: addAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:10,代码来源:WriterAppenderTest.java

示例14: addAppender

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:13,代码来源:OutputStreamAppenderTest.java

示例15: getLogger

import org.apache.logging.log4j.core.config.Configuration; //导入方法依赖的package包/类
/**
 * Get the logger used for output
 *
 * @param validatedArgs with output file, silent, and verbose options that
 *                      are used to configure the logger
 * @return Logger with dynamically-generated configuration
 */
public static Logger getLogger(ValidatedArgs validatedArgs) {
    // This approach is ugly, but it circumvents the need for multiple log4j
    // configuration files and simplifies writing results to the console and the output file
    // Silence StatusLogger
    System.setProperty("org.apache.logging.log4j.simplelog.StatusLogger.level", "FATAL");
    // Setup context
    LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    Configuration configuration = loggerContext.getConfiguration();
    // Define layout
    PatternLayout patternLayout = PatternLayout.newBuilder()
            .withConfiguration(configuration)
            // uncomment this pattern for debugging
            //.withPattern("%d{ISO8601} [%level] [%F:%L] %msg%n")
            .build();
    // Add appenders
    AppenderRef[] appenderRefs;
    //// Create console appender unless silent
    ConsoleAppender consoleAppender = null;
    AppenderRef consoleAppenderRef = null;
    if (!validatedArgs.silent) {
        consoleAppender = ConsoleAppender.newBuilder()
                .setConfiguration(configuration)
                .withLayout(patternLayout)
                .withName(CONSOLE_APPENDER)
                .build();
        consoleAppender.start();
        configuration.addAppender(consoleAppender);
        consoleAppenderRef = AppenderRef.createAppenderRef(CONSOLE_APPENDER, null, null);
    }
    //// Create file appender if output file specified
    FileAppender fileAppender = null;
    AppenderRef fileAppenderRef = null;
    if (validatedArgs.outputFile != null) {
        fileAppender = FileAppender.newBuilder()
                .setConfiguration(configuration)
                .withLayout(patternLayout)
                .withName(FILE_APPENDER)
                .withFileName(validatedArgs.outputFile.getAbsolutePath())
                .build();
        fileAppender.start();
        configuration.addAppender(fileAppender);
        fileAppenderRef = AppenderRef.createAppenderRef(FILE_APPENDER, null, null);
    }
    if ((consoleAppenderRef != null) && (fileAppenderRef != null)) {
        appenderRefs = new AppenderRef[]{consoleAppenderRef, fileAppenderRef};
    } else if (consoleAppenderRef != null) {
        appenderRefs = new AppenderRef[]{consoleAppenderRef};
    } else if (fileAppenderRef != null) {
        appenderRefs = new AppenderRef[]{fileAppenderRef};
    } else {
        throw new IllegalStateException("At least one appender must be configured to provide output!");
    }
    // Build and update the LoggerConfig
    Level levelToUse = validatedArgs.verbose ? VERBOSE_LEVEL : DEFAULT_LEVEL;
    LoggerConfig loggerConfig = LoggerConfig.createLogger(false, levelToUse, LOGGER_NAME, "true", appenderRefs, null, configuration, null);
    if (consoleAppender != null) {
        loggerConfig.addAppender(consoleAppender, null, null);
    }
    if (fileAppender != null) {
        loggerConfig.addAppender(fileAppender, null, null);
    }
    configuration.addLogger(LOGGER_NAME, loggerConfig);
    loggerContext.updateLoggers();
    return (Logger) LogManager.getLogger(LOGGER_NAME);
}
 
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:73,代码来源:LoggerFactory.java


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