我可以在运行时更改 Log4Qt 配置的文件名吗?
Can I change the filename of a Log4Qt configuration at runtime?
我正在使用Log4qt,我按照官方步骤配置了日志文件。我想知道是否可以在运行时动态更改配置。假设默认文件是"myapp.log"
// Set logging level for Log4Qt to TRACE
s.beginGroup("Log4Qt");
s.setValue("Debug", "TRACE");
// Configure logging to log to the file C:/myapp.log using the level TRACE
s.beginGroup("Properties");
s.setValue("log4j.appender.A1", "org.apache.log4j.FileAppender");
s.setValue("log4j.appender.A1.file", "C:/myapp.log");
s.setValue("log4j.appender.A1.layout", "org.apache.log4j.TTCCLayout");
s.setValue("log4j.appender.A1.layout.DateFormat", "ISO8601");
s.setValue("log4j.rootLogger", "TRACE, A1");
// Log first message, which initialises Log4Qt
Log4Qt::Logger::logger("MyApplication")->info("Hello World");
我想在运行时更改文件名,像这样?
QSettings s;
s.beginGroup("Properties");
s.setValue("log4j.appender.A1.file", "C:/NewFile.log");
// Log first message, into new file
Log4Qt::Logger::logger("MyApplication")->info("Hello World");
看起来在你更改了你的QSettings之后,它们反映在那里,你需要使用:
Log4Qt::Properties::load()
或
Log4Qt::PropertyConfigurator::configure()
引用您的 QSettings 变量。 如果这不应用文件名更改,您可能需要寻找一种在 Log4Qt 单例上运行启动的方法。
希望有帮助。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 从命令行c++发送文本文件名
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 无法找到/读取配置文件.conf-FileIOException
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 为什么文件名被设置为一个点,而不是在读取矢量中的文件名时
- 一种在C++中读取TXT配置文件的简单方法
- 生成MRPT库时cmake配置失败
- FFMPEG配置文件级别id大小无效
- 如何通过Conan和CMake找到用于pkg配置的.pc文件
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 配置文件解析器仅返回以前的值
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- 是否可以配置提升日志刷新?
- 如何在CPP的给定目录中列出UTF编码的文件名?
- 如何配置Visual Studio Code以使用cygwin,cmake和gcc进行调试
- C/C++:打印(配置)头文件的内容
- 在Visual Studio 2019中保存时ReadDirectoryChangesW文件名的问题
- 我可以在运行时更改 Log4Qt 配置的文件名吗?