AppendersFactory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2002, Log4cpp Project. All rights reserved.
3  *
4  * See the COPYING file for the terms of usage and distribution.
5  */
6 
7 
9 #include <stdexcept>
10 
11 namespace log4cpp
12 {
14 
15  std::auto_ptr<Appender> create_file_appender(const FactoryParams&);
16  std::auto_ptr<Appender> create_roll_file_appender(const FactoryParams&);
17  std::auto_ptr<Appender> create_generation_file_appender(const FactoryParams&);
18  std::auto_ptr<Appender> create_daily_roll_file_appender(const FactoryParams&);
19  std::auto_ptr<Appender> create_idsa_appender(const FactoryParams&);
20  std::auto_ptr<Appender> create_nt_event_log_appender(const FactoryParams&);
21  std::auto_ptr<Appender> create_remote_syslog_appender(const FactoryParams&);
22  std::auto_ptr<Appender> create_syslog_appender(const FactoryParams&);
23  std::auto_ptr<Appender> create_win32_debug_appender(const FactoryParams&);
24  std::auto_ptr<Appender> create_abort_appender(const FactoryParams&);
25  std::auto_ptr<Appender> create_smtp_appender(const FactoryParams&);
26 
28  {
29  if (!appenders_factory_)
30  {
31  std::auto_ptr<AppendersFactory> af(new AppendersFactory);
32 
33  af->registerCreator("file", &create_file_appender);
34  af->registerCreator("roll file", &create_roll_file_appender);
35  af->registerCreator("generation file", &create_generation_file_appender);
36  af->registerCreator("daily roll file", &create_daily_roll_file_appender);
37 #if !defined(LOG4CPP_DISABLE_REMOTE_SYSLOG)
38  af->registerCreator("remote syslog", &create_remote_syslog_appender);
39 #endif
40  af->registerCreator("abort", &create_abort_appender);
41 
42 #if defined(LOG4CPP_HAVE_LIBIDSA)
43  af->registerCreator("idsa", &create_idsa_appender);
44 #endif
45 
46 #if defined(LOG4CPP_HAVE_SYSLOG)
47  af->registerCreator("syslog", &create_syslog_appender);
48 #endif
49 
50 #if defined(WIN32)
51  af->registerCreator("win32 debug", &create_win32_debug_appender);
52  af->registerCreator("nt event log", &create_nt_event_log_appender);
53 #endif
54 
55 #if !defined(LOG4CPP_DISABLE_SMTP)
56 #if defined(LOG4CPP_HAVE_BOOST)
57 #include <boost/version.hpp>
58 #if BOOST_VERSION >= 103500
59  af->registerCreator("smtp", &create_smtp_appender);
60 #endif // BOOST_VERSION >= 103500
61 #endif // LOG4CPP_HAVE_BOOST
62 #endif // LOG4CPP_DISABLE_SMTP
63 
64  appenders_factory_ = af.release();
65  }
66 
67  return *appenders_factory_;
68  }
69 
70  void AppendersFactory::registerCreator(const std::string& class_name, create_function_t create_function)
71  {
72  const_iterator i = creators_.find(class_name);
73  if (i != creators_.end())
74  throw std::invalid_argument("Appender creator for type name '" + class_name + "' already registered");
75 
76  creators_[class_name] = create_function;
77  }
78 
79  std::auto_ptr<Appender> AppendersFactory::create(const std::string& class_name, const params_t& params)
80  {
81  const_iterator i = creators_.find(class_name);
82  if (i == creators_.end())
83  throw std::invalid_argument("There is no appender with type name '" + class_name + "'");
84 
85  return (*i->second)(params);
86  }
87 
88  bool AppendersFactory::registered(const std::string& class_name) const
89  {
90  return creators_.end() != creators_.find(class_name);
91  }
92 }
std::auto_ptr< Appender > create_generation_file_appender(const FactoryParams &)
std::auto_ptr< Appender > create_abort_appender(const FactoryParams &params)
creators_t::const_iterator const_iterator
std::auto_ptr< Appender > create_syslog_appender(const FactoryParams &)
std::auto_ptr< Appender > create(const std::string &class_name, const params_t &params)
std::auto_ptr< Appender > create_idsa_appender(const FactoryParams &)
std::auto_ptr< Appender >(* create_function_t)(const params_t &params)
std::auto_ptr< Appender > create_remote_syslog_appender(const FactoryParams &)
static AppendersFactory & getInstance()
void registerCreator(const std::string &class_name, create_function_t create_function)
std::auto_ptr< Appender > create_nt_event_log_appender(const FactoryParams &)
std::auto_ptr< Appender > create_roll_file_appender(const FactoryParams &)
std::auto_ptr< Appender > create_smtp_appender(const FactoryParams &)
bool registered(const std::string &class_name) const
std::auto_ptr< Appender > create_file_appender(const FactoryParams &)
static AppendersFactory * appenders_factory_
std::auto_ptr< Appender > create_win32_debug_appender(const FactoryParams &)
std::auto_ptr< Appender > create_daily_roll_file_appender(const FactoryParams &)


log4cpp
Author(s): Stephen Roderick, Bastiaan Bakker, Cedric Le Goater, Steve Ostlind, Marcel Harkema, Walter Stroebel, Glenn Scott and Tony Cheung
autogenerated on Sun Jun 23 2019 19:10:00