我有一個異步appender,只有當我設置level = debug時才起作用。對於「錯誤」級別,它不會記錄任何內容。log4j2異步appender只適用於調試級別
<Configuration packages="com.custom.appender">
<Appenders>
<CustomLogger name="customLogger"/>
<Async name="customAsync" bufferSize="2" includeLocation="flase">
<AppenderRef ref="customLogger"/>
</Async>
</Appenders>
<Loggers>
<logger name="com.mypackage" level="error">
<AppenderRef ref="customAsync"/>
</logger>
</Loggers>
</Configuration>
我不知道我在這個配置中缺少什麼。這是我想使用
package com.custom.appender
@Plugin(name = "CustomLogger", category = "Core", elementType = "appender", printObject = true)
public class CustomLogger extends AbstractAppender {
private static volatile CustomLogger instance;
public CustomLogger(final String name, final Filter filter,
final Layout<? extends Serializable> layout) {
super(name, filter, layout);
}
@PluginFactory
public static CustomLogger createAppender(
@PluginAttribute("name") String name,
@PluginAttribute("ignoreExceptions") boolean ignoreExceptions,
@PluginElement("Layout") Layout layout,
@PluginElement("Filters") Filter filter) {
if (layout == null) {
layout = PatternLayout.createDefaultLayout();
}
instance = new CustomLogger(name, filter, layout);
return instance;
}
public static CustomLogger getInstance() {
return instance;
}
@Override
public void append(LogEvent event) {
//Log the event to mongoDB
}
}
什麼類型的appender你要使用?它是一個控制檯appender嗎? –
我不認爲引用來自異步appender元素的記錄器元素是正確的。從那裏你必須訪問一個appender。 –
https://logging.apache.org/log4j/2.x/manual/configuration.html –