BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
appender.cpp
Go to the documentation of this file.
1 #include <fc/log/appender.hpp>
2 #include <fc/log/logger.hpp>
4 #include <unordered_map>
5 #include <string>
10 #include <fc/log/gelf_appender.hpp>
11 #include <fc/variant.hpp>
12 #include "console_defines.h"
13 
14 
15 namespace fc {
16 
17  std::unordered_map<std::string,appender::ptr>& get_appender_map() {
18  static std::unordered_map<std::string,appender::ptr> lm;
19  return lm;
20  }
21  std::unordered_map<std::string,appender_factory::ptr>& get_appender_factory_map() {
22  static std::unordered_map<std::string,appender_factory::ptr> lm;
23  return lm;
24  }
25  appender::ptr appender::get( const std::string& s ) {
26  static fc::spin_lock appender_spinlock;
27  scoped_lock<spin_lock> lock(appender_spinlock);
28  return get_appender_map()[s];
29  }
30  bool appender::register_appender( const std::string& type, const appender_factory::ptr& f )
31  {
32  get_appender_factory_map()[type] = f;
33  return true;
34  }
35  appender::ptr appender::create( const std::string& name, const std::string& type, const variant& args )
36  {
37  auto fact_itr = get_appender_factory_map().find(type);
38  if( fact_itr == get_appender_factory_map().end() ) {
39  //wlog( "Unknown appender type '%s'", type.c_str() );
40  return appender::ptr();
41  }
42  auto ap = fact_itr->second->create( args );
43  get_appender_map()[name] = ap;
44  return ap;
45  }
46 
47  static bool reg_console_appender = appender::register_appender<console_appender>( "console" );
48  static bool reg_file_appender = appender::register_appender<file_appender>( "file" );
49  static bool reg_gelf_appender = appender::register_appender<gelf_appender>( "gelf" );
50 
51 } // namespace fc
fc::appender::create
static appender::ptr create(const std::string &name, const std::string &type, const variant &args)
Definition: appender.cpp:35
appender.hpp
fc::get_appender_map
std::unordered_map< std::string, appender::ptr > & get_appender_map()
Definition: appender.cpp:17
fc::scoped_lock
Definition: scoped_lock.hpp:5
fc::spin_lock
modified spin-lock that yields on failure, but becomes a 'spin lock' if there are no other tasks to y...
Definition: spin_lock.hpp:20
fc
Definition: api.hpp:15
fc::get_appender_factory_map
std::unordered_map< std::string, appender_factory::ptr > & get_appender_factory_map()
Definition: appender.cpp:21
scoped_lock.hpp
fc::appender::get
static appender::ptr get(const std::string &name)
Definition: appender.cpp:25
spin_lock.hpp
file_appender.hpp
unique_lock.hpp
console_appender.hpp
fc::appender::ptr
std::shared_ptr< appender > ptr
Definition: appender.hpp:30
fc::appender_factory::ptr
std::shared_ptr< appender_factory > ptr
Definition: appender.hpp:12
fc::variant
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition: variant.hpp:198
logger.hpp
variant.hpp
gelf_appender.hpp
fc::appender::register_appender
static bool register_appender(const std::string &type)
Definition: appender.hpp:33