我实际上是在项目中添加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!不知道为什么!