代码之家  ›  专栏  ›  技术社区  ›  MildWolfie

Poco::Logger不记录跟踪或调试级别日志,仅记录信息级别及以上

  •  4
  • MildWolfie  · 技术社区  · 9 年前

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

    //  ... 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文档所知,这已经足够了。我是否遗漏了一个步骤,或者这个设置本身有什么问题?

    1 回复  |  直到 9 年前
        1
  •  5
  •   MildWolfie    9 年前

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

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