我的logging.properties定制格式化程序不起作用

问题描述 投票:0回答:1

我实际上是在项目中添加Java日志记录(不能使用其他框架)。我在.war上构建我的应用程序,并通过Weblogic进行了部署,该记录程序正在使用我的logging.properties配置,但格式化程序除外,我不知道为什么应用程序会忽略它。

这是我准备记录器的班级;

public class CtgLogger {
private static final String LOAD_ERROR = "Properties could not be loaded.";

private static final Map<String, Level> LEVEL_MAP;
private static final Logger LOGGER = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
static {

    final InputStream inputStream = CtgLogger.class.getResourceAsStream("/logging.properties");
    try {
        LogManager.getLogManager().readConfiguration(inputStream);
    } catch (Exception e) {
        Logger.getAnonymousLogger().severe(LOAD_ERROR);
        Logger.getAnonymousLogger().severe(e.getMessage());
    }
    // and I add the LEVEL_MAP to the logger...

这是我的财产...

handlers = java.util.logging.FileHandler
java.util.logging.FileHandler.pattern=logsfolder/CTGLOG_%g.log
java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.limit=3000
java.util.logging.FileHandler.count=6
#java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
#If I use the SimpleFormatter, apps goes well with it format. 
java.util.logging.FileHandler.formatter = com.package.my.log.JsonCustomFormatter
#If I use my custom formatter, the weblogic works with a XMLFormatter (default)

我知道.properties在工作,因为记录器正在使用我设置的模式,限制和计数。

PD:如果我使用JUnit运行我的应用程序,则日志正在使用我的自定义格式化程序,但不能在weblogic上运行!不知道为什么!

java logging weblogic formatter
1个回答
0
投票

Weblogic将具有多个类加载器。标准LogManager can only see classes loaded via the system class loader。检查Server Log中与找不到自定义类有关的错误。如果是这种情况,则必须将格式程序移动到系统类加载器。否则,您必须使用代码从运行在子类加载器中的Web应用程序安装格式化程序。

也有bugs in the LogManager.readConfiguration and alternative methods to use in JDK9 and later

© www.soinside.com 2019 - 2024. All rights reserved.