我尝试写入登录文件但文件始终为空并且吊销不显示信息。为什么会有问题?
private static final Logger logger = Logger.getLogger(MyClass.class.getName());
public String book(){
Properties properties = new Properties();
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream("/home/user/Workspace/project/src/main/resources/logger.properties");
properties.load(fileInputStream);
LogManager.getLogManager().readConfiguration(fileInputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
logger.info("INFO INFO");
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
logger.properties
# Logging
handlers = java.util.logging.FileHandler
java.util.logging.ConsoleHandler.level = ALL
# File Logging
java.util.logging.FileHandler.pattern = /home/user/Workspace/project/super.txt
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level = INFO
# Console Logging
# java.util.logging.ConsoleHandler.level = ALL
答案 0 :(得分:1)
您的配置未将ConsoleHandler附加到任何记录器。
handlers = java.util.logging.FileHandler
应该是:
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler