Go to the documentation of this file.00001 #include <log4cpp/AppendersFactory.hh>
00002 #include <stdexcept>
00003
00004 namespace log4cpp
00005 {
00006 static AppendersFactory* appenders_factory_ = 0;
00007
00008 std::auto_ptr<Appender> create_file_appender(const FactoryParams&);
00009 std::auto_ptr<Appender> create_roll_file_appender(const FactoryParams&);
00010 std::auto_ptr<Appender> create_generation_file_appender(const FactoryParams&);
00011 std::auto_ptr<Appender> create_idsa_appender(const FactoryParams&);
00012 std::auto_ptr<Appender> create_nt_event_log_appender(const FactoryParams&);
00013 std::auto_ptr<Appender> create_remote_syslog_appender(const FactoryParams&);
00014 std::auto_ptr<Appender> create_syslog_appender(const FactoryParams&);
00015 std::auto_ptr<Appender> create_win32_debug_appender(const FactoryParams&);
00016 std::auto_ptr<Appender> create_abort_appender(const FactoryParams&);
00017 std::auto_ptr<Appender> create_smtp_appender(const FactoryParams&);
00018
00019 AppendersFactory& AppendersFactory::getInstance()
00020 {
00021 if (!appenders_factory_)
00022 {
00023 std::auto_ptr<AppendersFactory> af(new AppendersFactory);
00024
00025 af->registerCreator("file", &create_file_appender);
00026 af->registerCreator("roll file", &create_roll_file_appender);
00027 af->registerCreator("generation file", &create_generation_file_appender);
00028 af->registerCreator("remote syslog", &create_remote_syslog_appender);
00029 af->registerCreator("abort", &create_abort_appender);
00030
00031 #if defined(LOG4CPP_HAVE_LIBIDSA)
00032 af->registerCreator("idsa", &create_idsa_appender);
00033 #endif
00034
00035 #if defined(LOG4CPP_HAVE_SYSLOG)
00036 af->registerCreator("syslog", &create_syslog_appender);
00037 #endif
00038
00039 #if defined(WIN32)
00040 af->registerCreator("win32 debug", &create_win32_debug_appender);
00041 af->registerCreator("nt event log", &create_nt_event_log_appender);
00042 #endif
00043
00044 #if defined(LOG4CPP_HAVE_BOOST)
00045 #include <boost/version.hpp>
00046 #if BOOST_VERSION >= 103500
00047 af->registerCreator("smtp", &create_smtp_appender);
00048 #endif // LOG4CPP_HAVE_BOOST
00049 #endif // BOOST_VERSION >= 103500
00050
00051 appenders_factory_ = af.release();
00052 }
00053
00054 return *appenders_factory_;
00055 }
00056
00057 void AppendersFactory::registerCreator(const std::string& class_name, create_function_t create_function)
00058 {
00059 const_iterator i = creators_.find(class_name);
00060 if (i != creators_.end())
00061 throw std::invalid_argument("Appender creator for type name '" + class_name + "' allready registered");
00062
00063 creators_[class_name] = create_function;
00064 }
00065
00066 std::auto_ptr<Appender> AppendersFactory::create(const std::string& class_name, const params_t& params)
00067 {
00068 const_iterator i = creators_.find(class_name);
00069 if (i == creators_.end())
00070 throw std::invalid_argument("There is no appender with type name '" + class_name + "'");
00071
00072 return (*i->second)(params);
00073 }
00074
00075 bool AppendersFactory::registered(const std::string& class_name) const
00076 {
00077 return creators_.end() != creators_.find(class_name);
00078 }
00079 }
log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sat Jun 8 2019 18:45:46