MildWolfie
MildWolfie

Reputation: 2532

Poco::Logger is not logging trace or debug level logs, only information level and above

I'm having an issue trying to enable poco_trace and poco_debug logging. I use Logger::setLevel() to set a level of PRIO_TRACE, but I still am not seeing anything of priority lower than PRIO_INFORMATION written to my logs. Here is the relevant code.

//  ... 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;
}

As far as I can tell from looking at the Poco documentation this should be enough. Is there a step I'm missing, or is something inherently wrong with this setup?

Upvotes: 4

Views: 2172

Answers (1)

MildWolfie
MildWolfie

Reputation: 2532

After perusing the Poco::Logger.h, I discovered that the poco_trace and poco_debug macros are enclosed by a #if defined(_DEBUG) block, meaning they'll only print to log when Poco itself is built in debug mode.

This feels like an odd decision as Logger::trace(), Logger:debug() and Logger::log( Message ) will all write to the log as long as the level of the logger has been set appropriately.

Upvotes: 5

Related Questions