问题描述
我们正在构建一个模块,该模块是完整嵌入式 Linux 操作系统的一部分。我们正在使用 log4cplus 进行诊断。
log.properties 包含:
log4cplus.logger.Companyglue=TRACE,console
cm_bind_helper.h 包含比这复杂得多的内容。所有 DBG_XXX 消息都显示在控制台上。
#include "qobject.h"
#include "log4cplus/dbglog.h"
class bind_helper : public QObject
{
protected:
const char *debugModuleName = "Companyglue";
log4cplus::Logger debugModule { Logger::getInstance(debugModuleName) };
bool set_value(CMPath path,PType &input)
{
auto old_value = CMRoot()->getValue(path);
if (input != old_value) {
DBG_DEBUG("Changing " << path << " to " << input);
}
}
}
cm_bridge.cpp 包含的代码比这多得多。但是,控制台上没有显示任何 DBG_XXX 消息。
#include "cm_bridge.h"
#include "cm_bind_helpers.h"
struct CompanyContentModelBridge::detail_ : public bind_helper
{
std::shared_ptr<company::device_base> base;
detail_(QObject *parent)
: bind_helper(parent)
{
configure_system_advanced_control();
}
void configure_system_advanced_control();
std::string get_exported_file_size();
}
using detail_ = CompanyContentModelBridge::detail_;
void detail_::configure_system_advanced_control()
{
base->add_get_only_entry<std::string>("SPDSZ",get_exported_file_size());
}
std::string detail_::get_exported_file_size()
{
DBG_INFO("get exported file size");
//diag("exported file size");
}
我尝试了多种方法在cm_bridge.cpp中配置log4cplus,包括cm_bind_helpers.h中相同的两行,如下所示。假设继承会处理它,我还删除了它们。 DBG_XXX 消息没有显示。
DBG_IMPL_DEBUG_MODULE(Companyglue);
最终,我将此函数添加到 cm_bind_helpers.h。它在从它自己的类调用时有效,但在从 get_exported_file_size() 调用时失败(已删除注释)。
void diag(std::string_view what) {
DBG_DEBUG("bind helper diag " << what);
}
我被难住了。我不知道为什么从一个文件中抑制消息而不是另一个文件。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)