BitShares-Core  4.0.0
BitShares blockchain implementation and command-line interface 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
modified spin-lock that yields on failure, but becomes a &#39;spin lock&#39; if there are no other tasks to y...
Definition: spin_lock.hpp:20
static appender::ptr create(const std::string &name, const std::string &type, const variant &args)
Definition: appender.cpp:35
static appender::ptr get(const std::string &name)
Definition: appender.cpp:25
std::shared_ptr< appender > ptr
Definition: appender.hpp:30
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object&#39;s.
Definition: variant.hpp:198
static bool register_appender(const std::string &type)
Definition: appender.hpp:33
std::unordered_map< std::string, appender::ptr > & get_appender_map()
Definition: appender.cpp:17
std::unordered_map< std::string, appender_factory::ptr > & get_appender_factory_map()
Definition: appender.cpp:21
Definition: api.hpp:15
std::shared_ptr< appender_factory > ptr
Definition: appender.hpp:12