Skip to content

Commit

Permalink
Merge pull request #110 from EOSIO/default-logger
Browse files Browse the repository at this point in the history
Provide default log level of info for non-configured loggers.
  • Loading branch information
heifner authored Aug 22, 2019
2 parents c9e0e66 + 3892fb5 commit c9e7389
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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 );
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

0 comments on commit c9e7389

Please sign in to comment.