本文整理汇总了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();
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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();
}
示例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");
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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();
}
示例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();
}