我正在使用API Rest,我需要一个名为my organization的特定日志文件。当我创建或编辑组织时,我的API必须创建其文件(如果不存在),然后保存其数据。我已经在application.properties中使用默认路径文件中的这些参数。
logging.file=/Users/xxxxxxxxx/application.log
在我的Java类中,特别是在我的编辑方法中,如果没有创建,我正在创建文件。
String fileLog = "/Users/xxxxxxxxxxxx/logs/" + orgId + ".log";
File file = new File(fileLog);
BufferedWriter bw;
if (!file.exists()) {
// crea el archivo para la Org si no existe
bw = new BufferedWriter(new FileWriter(file));
}
最后,我设置了my(logging.file)的默认定义,为该组织定义了新的日志文件。
PropertiesConfiguration config = new
PropertiesConfiguration("/Users/xxxxxxxx/application.properties");
config.setProperty("logging.file", "/Users/xxxxxxxxxxxx/logs/" +
orgId + ".log");
config.save();
我的最后一个问题是:如何在不重启服务器的情况下重置日志管理器?
最简单的方法是使用application.properties。最常定制的是:
logging.file= # Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.
logging.file.max-history=0 # Maximum of archive log files to keep. Only supported with the default logback setup.
logging.file.max-size=10MB # Maximum log file size. Only supported with the default logback setup.