Menu

[2d617b]: / src / AppendersFactory.cpp  Maximize  Restore  History

Download this file

91 lines (73 with data), 3.3 kB

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