5#include <unordered_map>
15 log_config& log_config::get() {
17 static log_config* the =
new log_config;
23 std::lock_guard g( log_config::get().log_mutex );
24 log_config::get().appender_factory_map[
type] =
f;
29 std::lock_guard g( log_config::get().log_mutex );
30 return log_config::get().logger_map[
name];
34 std::lock_guard g( log_config::get().log_mutex );
35 if( log_config::get().logger_map.find(
name ) != log_config::get().logger_map.end() ) {
36 log = log_config::get().logger_map[
name];
39 if( log_config::get().logger_map.find(
DEFAULT_LOGGER ) != log_config::get().logger_map.end() ) {
41 log_config::get().logger_map.emplace(
name, log );
47 std::lock_guard g( log_config::get().log_mutex );
48 for(
auto& iter : log_config::get().appender_map )
49 iter.second->initialize( ios );
65 std::lock_guard g( log_config::get().log_mutex );
66 log_config::get().logger_map.clear();
67 log_config::get().appender_map.clear();
69 for(
size_t i = 0; i < cfg.
appenders.size(); ++i ) {
71 auto fact_itr = log_config::get().appender_factory_map.find( cfg.
appenders[i].type );
72 if( fact_itr == log_config::get().appender_factory_map.end() ) {
76 auto ap = fact_itr->second->create( cfg.
appenders[i].args );
77 log_config::get().appender_map[cfg.
appenders[i].name] = ap;
79 for(
size_t i = 0; i < cfg.
loggers.size(); ++i ) {
80 auto lgr = log_config::get().logger_map[cfg.
loggers[i].name];
84 lgr.set_parent( log_config::get().logger_map[*cfg.
loggers[i].parent] );
86 lgr.set_name(cfg.
loggers[i].name);
87 if( cfg.
loggers[i].level ) lgr.set_log_level( *cfg.
loggers[i].level );
90 for(
auto a = cfg.
loggers[i].appenders.begin();
a != cfg.
loggers[i].appenders.end(); ++
a ){
91 auto ap_it = log_config::get().appender_map.find(*
a);
92 if( ap_it != log_config::get().appender_map.end() ) {
93 lgr.add_appender( ap_it->second );
97 return reg_console_appender || reg_gelf_appender || reg_dmlog_appender;
117 (
"stream",
"std_error")
118 (
"level_colors", c )
123 (
"stream",
"std_out")
124 (
"level_colors", c )
135 static thread_local std::string thread_name;
137#ifdef FC_USE_PTHREAD_NAME_NP
138 pthread_setname_np( pthread_self(),
name.c_str() );
145 if( thread_name.empty() ) {
146#ifdef FC_USE_PTHREAD_NAME_NP
148 int rc = pthread_getname_np( pthread_self(), thr_name, 64 );
150 thread_name = thr_name;
153 static int thread_count = 0;
std::shared_ptr< appender_factory > ptr
Used to generate a useful error report when an exception is thrown.
std::string to_detail_string(log_level ll=log_level::all) const
static variant from_file(const fc::path &p, const parse_type ptype=parse_type::legacy_parser, const uint32_t max_depth=DEFAULT_MAX_RECURSION_DEPTH)
An order-preserving dictionary of variants.
wraps boost::filesystem::path to provide platform independent path manipulation.
Defines exception's used by fc.
fc::string to_string(double)
void set_thread_name(const string &name)
const string & get_thread_name()
std::vector< fc::variant > variants
void set_os_thread_name(const string &name)
void configure_logging(const fc::path &log_config)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
static void initialize_appenders(boost::asio::io_service &ios)
static logger get_logger(const fc::string &name)
static bool configure_logging(const logging_config &l)
static void update_logger(const fc::string &name, logger &log)
static bool register_appender(const fc::string &type)
std::vector< string > appenders
std::optional< log_level > level
if not set, then parents level is used.
std::vector< logger_config > loggers
static logging_config default_config()
std::vector< appender_config > appenders