/** * Add a loggerConfig. The LoggerConfig must already be configured with Appenders, Filters, etc. After addLogger is * called LoggerContext.updateLoggers must be called. * * @param loggerName The name of the Logger. * @param loggerConfig The LoggerConfig. */ @Override public synchronized void addLogger(final String loggerName, final LoggerConfig loggerConfig) { loggerConfigs.putIfAbsent(loggerName, loggerConfig); setParents(); }
/** * Remove a LoggerConfig. * * @param loggerName The name of the Logger. */ @Override public synchronized void removeLogger(final String loggerName) { loggerConfigs.remove(loggerName); setParents(); }
/** * Marks a LoggerConfig as additive. This method is synchronized in case a Logger with the same name is being * updated at the same time. * * Note: This method is not used when configuring via configuration. It is primarily used by unit tests. * * @param logger The Logger the Appender will be associated with. * @param additive True if the LoggerConfig should be additive, false otherwise. */ @Override public synchronized void setLoggerAdditive(final org.apache.logging.log4j.core.Logger logger, final boolean additive) { final String loggerName = logger.getName(); final LoggerConfig lc = getLoggerConfig(loggerName); if (lc.getName().equals(loggerName)) { lc.setAdditive(additive); } else { final LoggerConfig nlc = new LoggerConfig(loggerName, lc.getLevel(), additive); nlc.setParent(lc); loggerConfigs.putIfAbsent(loggerName, nlc); setParents(); logger.getContext().updateLoggers(); } }
/** * Associates an Appender with a LoggerConfig. This method is synchronized in case a Logger with the same name is * being updated at the same time. * * Note: This method is not used when configuring via configuration. It is primarily used by unit tests. * * @param logger The Logger the Appender will be associated with. * @param appender The Appender. */ @Override public synchronized void addLoggerAppender(final org.apache.logging.log4j.core.Logger logger, final Appender appender) { final String loggerName = logger.getName(); appenders.putIfAbsent(appender.getName(), appender); final LoggerConfig lc = getLoggerConfig(loggerName); if (lc.getName().equals(loggerName)) { lc.addAppender(appender, null, null); } else { final LoggerConfig nlc = new LoggerConfig(loggerName, lc.getLevel(), lc.isAdditive()); nlc.addAppender(appender, null, null); nlc.setParent(lc); loggerConfigs.putIfAbsent(loggerName, nlc); setParents(); logger.getContext().updateLoggers(); } }
/** * Associates a Filter with a LoggerConfig. This method is synchronized in case a Logger with the same name is being * updated at the same time. * * Note: This method is not used when configuring via configuration. It is primarily used by unit tests. * * @param logger The Logger the Footer will be associated with. * @param filter The Filter. */ @Override public synchronized void addLoggerFilter(final org.apache.logging.log4j.core.Logger logger, final Filter filter) { final String loggerName = logger.getName(); final LoggerConfig lc = getLoggerConfig(loggerName); if (lc.getName().equals(loggerName)) { lc.addFilter(filter); } else { final LoggerConfig nlc = new LoggerConfig(loggerName, lc.getLevel(), lc.isAdditive()); nlc.addFilter(filter); nlc.setParent(lc); loggerConfigs.putIfAbsent(loggerName, nlc); setParents(); logger.getContext().updateLoggers(); } }