當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。