tinylog - tinylog2 - 在运行期间重新配置
问题描述
在我已经记录了一些行之后,有没有办法重新配置 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
谢谢!
解决方案
tinylog 的本机日志记录提供程序不支持在发布第一个日志条目后更改配置。但是,您可以通过扩展或包装 tinylog 的本机日志记录提供程序TinylogLoggingProvider来创建自定义日志记录实现,并自行添加所需的运行时更改逻辑。
您可以在 tinylog 网站上找到如何注册和使用自定义日志记录提供程序的文档:https ://tinylog.org/v2/extending/#custom-logging-provider
推荐阅读
- python - 考虑像素的alpha值的python cv2.findNonZero像素
- python - 函数调用堆栈:test_function -> test_function -> GPU 上的 test_function 但不在 CPU 上
- css - 如何在引导多个项目轮播列与上一个和下一个按钮之间放置间隙
- reactjs - 我可以为酶浅渲染中的变量指定一个值吗?
- r - R 不允许我将代码编织成 word 格式
- java - 问题创建 NotificationCompat 任何打开的应用程序
- javascript - 有没有其他优雅的方式从 JSON 中获取数据并将其呈现给 DOM?
- typescript - 结合联合类型对象构建
- python - 如何将列表中的字符串与列表理解结合起来?
- python - Kivy:按下按钮时更新TextInput