我有一个愚蠢的java日志记录问题:我正在从我的应用程序配置文件加载日志记录配置 - 但它只是在读取文件后没有记录任何内容(这看起来很像你将在网上找到的例子,除了额外的应用程序配置 - 删除它也没有帮助)."初始化..."日志行显得很好,但"启动应用程序"和任何其他消息既没有记录到控制台,也没有创建日志文件.我在这里错过了什么?
Logger代码如下所示:
...
Logger log = Logger.getLogger("myApp");
log.setLevel(Level.ALL);
log.info("initializing - trying to load configuration file ...");
Properties preferences = new Properties();
try {
FileInputStream configFile = new FileInputStream("/path/to/app.properties");
preferences.load(configFile);
LogManager.getLogManager().readConfiguration(configFile);
} catch (IOException ex)
{
System.out.println("WARNING: Could not open configuration file");
System.out.println("WARNING: Logging not configured (console output only)");
}
log.info("starting myApp");
...
Run Code Online (Sandbox Code Playgroud)
这是配置文件:
appconfig1 = foo
appconfig2 = bar
# Logging
handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler
.level = ALL
# File Logging
java.util.logging.FileHandler.pattern = %h/myApp.log
java.util.logging.FileHandler.formatter = …Run Code Online (Sandbox Code Playgroud)