【问题标题】:Poco::Logger is not logging trace or debug level logs, only information level and abovePoco::Logger 不记录跟踪或调试级别的日志,仅记录信息级别及以上
【发布时间】:2016-02-03 19:26:55
【问题描述】:

我在尝试启用 poco_trace 和 poco_debug 日志记录时遇到问题。我使用 Logger::setLevel() 设置 PRIO_TRACE 级别,但我仍然没有看到任何优先级低于 PRIO_INFORMATION 的内容写入我的日志。这是相关代码。

//  ... In the constructor  of my main class
//  All Loggers in the program inherit from the Logger found here.

getLogger().setChannel( channel );
getLogger().setLevel( Poco::Message::PRIO_TRACE );

//  This prints "Level is 8" to the log, 8 being Message::PRIO_TRACE.
poco_information_f1( getLogger(), "Level is %i", getLogger().getLevel() );
//  This however is not printed to the log.
poco_trace( getLogger(), "Trace logging is enabled" );

//  ...

//  Definition of getLogger()
inline Poco::Logger& Application::getLogger() const
{   
    //  Where logger is a class member of type Poco::Logger*
    poco_check_ptr( logger );
    return *logger;
}

据我查看 Poco 文档可知,这应该足够了。是否有我遗漏的步骤,或者此设置存在固有问题?

【问题讨论】:

    标签: c++ poco-libraries


    【解决方案1】:

    仔细阅读 Poco::Logger.h 后,我发现 poco_trace 和 poco_debug 宏被 #if defined(_DEBUG) 块包围,这意味着它们只会在 Poco 本身以调试模式构建时打印到日志。

    这感觉像是一个奇怪的决定,因为 Logger::trace()、Logger:debug() 和 Logger::log( Message ) 都会写入日志,只要适当地设置了记录器的级别。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      相关资源
      最近更新 更多