使用java配置Ignite logger和appender

使用java配置Ignite logger和appender,ignite,Ignite,我想通过编程而不是xml来配置ignite log4j2配置。 如何使用java配置ignite log4j2配置?有人能帮忙吗?不幸的是,它构建的Ignite目前不支持纯编程的配置方式 但事实上,您可以使用slf4j日志外观,该外观由引擎盖下的log4j2支持。在这种情况下,您将拥有某种完全的日志记录配置。 为了实现这一点,您应该手动添加log4j2依赖项以及依赖项。同时,您需要log4j2slf4j来允许Ignite日志记录设施将调用转移到log4j2 例如,如果使用maven,则pom.x

我想通过编程而不是xml来配置ignite log4j2配置。
如何使用java配置ignite log4j2配置?有人能帮忙吗?

不幸的是,它构建的
Ignite
目前不支持纯编程的配置方式

但事实上,您可以使用
slf4j
日志外观,该外观由引擎盖下的
log4j2
支持。在这种情况下,您将拥有某种完全的日志记录配置。 为了实现这一点,您应该手动添加
log4j2
依赖项以及依赖项。同时,您需要
log4j2
slf4j
来允许
Ignite
日志记录设施将调用转移到
log4j2

例如,如果使用
maven
,则
pom.xml
应包含:


org.apache.ignite
来配置那些东西。例如,您可以尝试将扩展了
org.apache.logging.log4j.core.config.ConfigurationFactory
的类添加到您的类路径中。它可能看起来像这样:

导入java.net.URI;
导入org.apache.logging.log4j.Level;
导入org.apache.logging.log4j.core.Filter;
导入org.apache.logging.log4j.core.LoggerContext;
导入org.apache.logging.log4j.core.appender.ConsoleAppender;
导入org.apache.logging.log4j.core.config.Configuration;
导入org.apache.logging.log4j.core.config.ConfigurationFactory;
导入org.apache.logging.log4j.core.config.ConfigurationSource;
导入org.apache.logging.log4j.core.config.Order;
导入org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
导入org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
导入org.apache.logging.log4j.core.config.builder.impl.BuilConfiguration;
导入org.apache.logging.log4j.core.config.plugins.Plugin;
@插件(name=“CustomConfigurationFactory”,category=ConfigurationFactory.category)
@订单(50)
公共类CustomConfigurationFactory扩展了ConfigurationFactory{
静态配置createConfiguration(最终字符串名,ConfigurationBuilder){
builder.setConfigurationName(名称);
builder.setStatusLevel(Level.ERROR);
添加(builder.newFilter(“ThresholdFilter”、Filter.Result.ACCEPT、Filter.Result.NEUTRAL)。
addAttribute(“level”,level.DEBUG));
AppenderComponentBuilder appenderBuilder=builder.newAppender(“标准输出”、“控制台”)。
addAttribute(“target”,ConsoleAppender.target.SYSTEM_OUT);
add(builder.newLayout(“PatternLayout”)。
addAttribute(“模式”,%d[%t]-5级别:%msg%n%throwable”);
add(builder.newFilter(“MarkerFilter”、Filter.Result.DENY、,
Filter.Result.NEUTRAL)addAttribute(“标记”、“流”);
builder.add(appenderBuilder);
add(builder.newLogger(“org.apache.logging.log4j”,Level.DEBUG)。
添加(builder.newAppenderRef(“Stdout”))。
addAttribute(“可加性”,false));
add(builder.newRootLogger(Level.ERROR).add(builder.newAppenderRef(“Stdout”));
返回builder.build();
}
@凌驾
公共配置getConfiguration(final LoggerContext LoggerContext,final ConfigurationSource源){
返回getConfiguration(loggerContext,source.toString(),null);
}
@凌驾
公共配置getConfiguration(最终LoggerContext LoggerContext、最终字符串名称、最终URI configLocation){
ConfigurationBuilder=newConfigurationBuilder();
返回createConfiguration(名称、生成器);
}
@凌驾
受保护的字符串[]getSupportedTypes(){
返回新字符串[]{“*”};
}
}

可以在那里进行日志定制。

谢谢。成功了。但是ignite应该能够以编程方式提供记录器配置。不客气。根据社区的规则和传统,你可以考虑接受这个答案,以防它对你有所帮助。