在我已经记录了一些行之后,有没有办法重新配置tinylog2属性?当用户更改选择(处理不同的文件)时,我希望在运行期间更改日志文件名,而无需重新启动我的程序。
我的代码只在第一次运行:
private void initLogger(String fileName) {
// log to file
Configuration.set("writer","file");
// set log file name
if (inFileCheckBox.isSelected()){ // log file name is working file name
Configuration.set("writer.file",fileName);
}else{ // log file name by month (MM-YYYY)
Configuration.set("writer.file", new SimpleDateFormat("MM-yyyy").format(new Date()));
}
Logger.info("yow it's : {}", fileName);
}我试着在改变参数之前手动关闭它,但没有帮助:
ProviderRegistry.getLoggingProvider().shutdown();这是我第二次运行该方法时得到的错误:
Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Configuration cannot be changed after applying to tinylog谢谢!
发布于 2021-06-28 17:06:03
tinylog的本地日志提供程序不支持在发出第一个日志条目后更改配置。但是,您可以通过扩展或包装tinylog的本地日志提供程序TinylogLoggingProvider来创建自定义日志实现,并自行添加所需的运行时更改逻辑。
您可以在tinylog网站上找到如何注册和使用自定义日志提供程序的文档:https://tinylog.org/v2/extending/#custom-logging-provider
https://stackoverflow.com/questions/67971901
复制相似问题