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


Java LoggerConfig.addAppender方法代码示例

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


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

示例1: watch

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public void watch(Class<?> loggerClass, Level level) {
    this.loggerClass = loggerClass;
    Appender appender = new AbstractAppender(APPENDER_NAME, null, PatternLayout.createDefaultLayout()) {
        @Override
        public void append(LogEvent event) {
            logEvents.add(event);
        }
    };
    appender.start();
    final LoggerContext ctx = getLoggerContext();
    LoggerConfig loggerConfig = ctx.getConfiguration().getLoggerConfig(loggerClass.getName());
    oldLevel = loggerConfig.getLevel();
    loggerConfig.setLevel(level);
    loggerConfig.addAppender(appender, level, null);
    ctx.updateLoggers();
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:17,代码来源:LogTestRule.java

示例2: removeAlertListener

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public synchronized boolean removeAlertListener(final DistributedMember member) {
  final boolean memberWasFound = this.listeners.remove(new Listener(null, member));

  if (memberWasFound) {
    if (this.listeners.size() == 0) {
      this.appenderContext.getLoggerContext().removePropertyChangeListener(this);
      this.appenderContext.getLoggerConfig().removeAppender(APPENDER_NAME);

    } else {
      LoggerConfig loggerConfig = this.appenderContext.getLoggerConfig();
      loggerConfig.addAppender(this, this.listeners.get(0).getLevel(), null);
    }
    if (logger.isDebugEnabled()) {
      logger.debug("Removed alert listener for member {}", member);
    }
  }

  return memberWasFound;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:AlertAppender.java

示例3: addSuspectFileAppender

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
/**
 * Add an appender to Log4j which sends all INFO+ messages to a separate file which will be used
 * later to scan for suspect strings. The pattern of the messages conforms to the original log
 * format so that hydra will be able to parse them.
 */
private static void addSuspectFileAppender(final String workspaceDir) {
  final String suspectFilename = new File(workspaceDir, SUSPECT_FILENAME).getAbsolutePath();

  final LoggerContext appenderContext =
      ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogService.BASE_LOGGER_NAME))
          .getContext();

  final PatternLayout layout = PatternLayout.createLayout(
      "[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n",
      null, null, null, Charset.defaultCharset(), true, false, "", "");

  final FileAppender fileAppender = FileAppender.createAppender(suspectFilename, "true", "false",
      DUnitLauncher.class.getName(), "true", "false", "false", "0", layout, null, null, null,
      appenderContext.getConfiguration());
  fileAppender.start();

  LoggerConfig loggerConfig =
      appenderContext.getConfiguration().getLoggerConfig(LogService.BASE_LOGGER_NAME);
  loggerConfig.addAppender(fileAppender, Level.INFO, null);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:DUnitLauncher.java

示例4: addFileAppender

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的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

示例5: StandaloneLoggerConfiguration

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
/**
 * Constructor to create the default configuration.
 */
public StandaloneLoggerConfiguration(ConfigurationSource source) {
    super(source);

    setName(CONFIG_NAME);
    final Appender appender = StandaloneLogEventAppender.createAppender("StandaloneLogAppender", 1000);
    appender.start();
    addAppender(appender);
    final LoggerConfig root = getRootLogger();
    root.addAppender(appender, null, null);

    final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
    final Level level = levelName != null && Level.valueOf(levelName) != null ?
            Level.valueOf(levelName) : Level.ALL;
    root.setLevel(level);
}
 
开发者ID:Steve973,项目名称:camel-standalone,代码行数:19,代码来源:StandaloneLoggerConfiguration.java

示例6: configureLogging

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的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

示例7: configureLog4j

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的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

示例8: bindLogger

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的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

示例9: main

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void main(String[] args) throws UnRetriableException{

        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
        ConsoleAppender appender = ConsoleAppender.createDefaultAppenderForLayout(PatternLayout.createDefaultLayout());
        appender.start();
        config.addAppender(appender);
        AppenderRef[] refs = new AppenderRef[] { AppenderRef.createAppenderRef(appender.getName(), null, null) };
        LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.INFO, LogManager.ROOT_LOGGER_NAME, "true", refs, null, config, null);
        loggerConfig.addAppender(appender, null, null);
        config.addLogger(LogManager.ROOT_LOGGER_NAME, loggerConfig);
        ctx.updateLoggers();


        Runner runner = defaultRunner();
        runner.init();
        runner.start();

    }
 
开发者ID:caricah,项目名称:iotracah,代码行数:20,代码来源:IOTracah.java

示例10: main

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void main(String[] args) throws UnRetriableException {


        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
        AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
        ConsoleAppender appender = ConsoleAppender.createDefaultAppenderForLayout(PatternLayout.createDefaultLayout());
        appender.start();
        config.addAppender(appender);
        AppenderRef[] refs = new AppenderRef[] { AppenderRef.createAppenderRef(appender.getName(), null, null) };
        LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.WARN, LogManager.ROOT_LOGGER_NAME, "true", refs, null, config, null);
        loggerConfig.addAppender(appender, null, null);
        config.addLogger(LogManager.ROOT_LOGGER_NAME, loggerConfig);
        ctx.updateLoggers();


        Runner runner = defaultRunner();
        runner.init();
        runner.start();

    }
 
开发者ID:caricah,项目名称:iotracah,代码行数:21,代码来源:IOTracah.java

示例11: registerListener

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
@Override
public void registerListener(ListenerConfig cfg) {
  if (history != null)
    throw new IllegalStateException("History already registered");

  history = new CircularList<LogEvent>(cfg.size);

  Level threshold = (cfg.threshold != null) ? Level.toLevel(cfg.threshold) : Level.WARN;
  ThresholdFilter filter = ThresholdFilter.createFilter(threshold, Filter.Result.ACCEPT, Filter.Result.DENY);
  appender = new Log4j2Appender(this, filter, threshold);
  if (!appender.isStarted())
    appender.start();

  LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
  LoggerConfig config = getLoggerConfig(ctx, LoggerInfo.ROOT_NAME);
  config.addAppender(appender, threshold, filter);
  ctx.updateLoggers();
}
 
开发者ID:lucidworks,项目名称:solr-log4j2,代码行数:19,代码来源:Log4j2Watcher.java

示例12: setUpAppender

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的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

示例13: addAppenderToContext

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public void addAppenderToContext(
        final LoggerContext ctx,
        final AuditAppender auditAppender,
        final LoggerConfig eventLogConf) {

    Appender targetAppender = ctx.getConfiguration().getAppender(auditAppender.getTargetAppenderName());
    if (targetAppender == null) {
        targetAppender = auditAppender.getTargetAppender();
    }
    targetAppender.start();
    ctx.getConfiguration().addAppender(targetAppender);
    if (auditAppender.isRewriteEnabled()) {
        RewriteAppender rewriteAppender = ctx.getConfiguration().getAppender(auditAppender.
                getTargetAppenderName() + "_rewrite");
        if (rewriteAppender == null) {
            rewriteAppender = auditAppender.getRewriteAppender();
        }
        rewriteAppender.start();
        ctx.getConfiguration().addAppender(rewriteAppender);
        eventLogConf.addAppender(rewriteAppender, Level.DEBUG, null);
    } else {
        eventLogConf.addAppender(targetAppender, Level.DEBUG, null);
    }
}
 
开发者ID:apache,项目名称:syncope,代码行数:25,代码来源:LoggerLoader.java

示例14: addFileAppender

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void addFileAppender(final String loggerPath, final File logFile, final AppConfig appConfig)
	throws IOException
{
	// retrieve the logger context
	LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
	Configuration configuration = loggerContext.getConfiguration();
	
	// retrieve the root logger config
	LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
	loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
	
	// Define log pattern layout
	PatternLayout layout = PatternLayout.createLayout(DEFAULT_LOGGER_PATTERN, null, null, null,
		Charset.defaultCharset(), false, false, null, null);
	
	// create the appenders
	FileAppender fileAppender =
		FileAppender.createAppender(logFile.getAbsolutePath(), "true", "false", "fileAppender",
			"true", "true", "true", "8192", layout, null, "false", null, null);
	fileAppender.start();
	
	// add the appenders
	loggerConfig.addAppender(fileAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
	loggerContext.updateLoggers();
}
 
开发者ID:ThreatConnect-Inc,项目名称:threatconnect-java,代码行数:26,代码来源:LoggerUtil.java

示例15: addServerAppender

import org.apache.logging.log4j.core.config.LoggerConfig; //导入方法依赖的package包/类
public static void addServerAppender(final String loggerPath, final AppConfig appConfig)
	throws IOException
{
	// retrieve the logger context
	LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
	Configuration configuration = loggerContext.getConfiguration();
	
	// retrieve the root logger config
	LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerPath);
	loggerConfig.setLevel(Level.toLevel(appConfig.getTcLogLevel()));
	
	// create the appenders
	ServerLoggerAppender serverLoggerAppender = ServerLoggerAppender.createAppender("serverLoggerAppender");
	serverLoggerAppender.start();
	
	// add the appenders
	loggerConfig.addAppender(serverLoggerAppender, Level.toLevel(appConfig.getTcLogLevel()), null);
	loggerContext.updateLoggers();
}
 
开发者ID:ThreatConnect-Inc,项目名称:threatconnect-java,代码行数:20,代码来源:LoggerUtil.java


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