Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide default log level of info for non-configured loggers. #110

Merged
merged 7 commits into from
Aug 22, 2019
Merged
12 changes: 6 additions & 6 deletions include/fc/log/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#include <fc/time.hpp>
#include <fc/log/log_message.hpp>

namespace fc
#ifndef DEFAULT_LOGGER
#define DEFAULT_LOGGER "default"
#endif

namespace fc
{

class appender;
Expand All @@ -21,7 +25,7 @@ namespace fc
class logger
{
public:
static logger get( const fc::string& name = "default");
static logger get( const fc::string& name = DEFAULT_LOGGER );
arhag marked this conversation as resolved.
Show resolved Hide resolved
static void update( const fc::string& name, logger& log );

logger();
Expand Down Expand Up @@ -57,10 +61,6 @@ namespace fc

} // namespace fc

#ifndef DEFAULT_LOGGER
#define DEFAULT_LOGGER
#endif

// suppress warning "conditional expression is constant" in the while(0) for visual c++
// http://cnicholson.net/2009/03/stupid-c-tricks-dowhile0-and-c4127/
#define FC_MULTILINE_MACRO_BEGIN do {
Expand Down
11 changes: 9 additions & 2 deletions src/log/logger_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ namespace fc {

void log_config::update_logger( const fc::string& name, logger& log ) {
std::lock_guard g( log_config::get().log_mutex );
if( log_config::get().logger_map.find( name ) != log_config::get().logger_map.end() )
if( log_config::get().logger_map.find( name ) != log_config::get().logger_map.end() ) {
log = log_config::get().logger_map[name];
} else {
// no entry for logger, so setup with default logger if it exists, otherwise do nothing since default logger not configured
if( log_config::get().logger_map.find( DEFAULT_LOGGER ) != log_config::get().logger_map.end() ) {
log = log_config::get().logger_map[DEFAULT_LOGGER];
log_config::get().logger_map.emplace( name, log );
}
}
}

void log_config::initialize_appenders( boost::asio::io_service& ios ) {
Expand Down Expand Up @@ -115,7 +122,7 @@ namespace fc {
) );

logger_config dlc;
dlc.name = "default";
dlc.name = DEFAULT_LOGGER;
dlc.level = log_level::info;
dlc.appenders.push_back("stderr");
cfg.loggers.push_back( dlc );
Expand Down