/src/log4cplus/src/factory.cxx
Line | Count | Source |
1 | | // Module: Log4CPLUS |
2 | | // File: factory.cxx |
3 | | // Created: 2/2002 |
4 | | // Author: Tad E. Smith |
5 | | // |
6 | | // |
7 | | // Copyright 2002-2017 Tad E. Smith |
8 | | // |
9 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | // you may not use this file except in compliance with the License. |
11 | | // You may obtain a copy of the License at |
12 | | // |
13 | | // http://www.apache.org/licenses/LICENSE-2.0 |
14 | | // |
15 | | // Unless required by applicable law or agreed to in writing, software |
16 | | // distributed under the License is distributed on an "AS IS" BASIS, |
17 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | // See the License for the specific language governing permissions and |
19 | | // limitations under the License. |
20 | | |
21 | | #include <log4cplus/spi/factory.h> |
22 | | #include <log4cplus/spi/loggerfactory.h> |
23 | | #include <log4cplus/helpers/loglog.h> |
24 | | #include <log4cplus/helpers/thread-config.h> |
25 | | #include <log4cplus/helpers/property.h> |
26 | | #include <log4cplus/asyncappender.h> |
27 | | #include <log4cplus/consoleappender.h> |
28 | | #include <log4cplus/fileappender.h> |
29 | | #include <log4cplus/nteventlogappender.h> |
30 | | #include <log4cplus/nullappender.h> |
31 | | #include <log4cplus/socketappender.h> |
32 | | #include <log4cplus/syslogappender.h> |
33 | | #include <log4cplus/win32debugappender.h> |
34 | | #include <log4cplus/win32consoleappender.h> |
35 | | #include <log4cplus/log4judpappender.h> |
36 | | |
37 | | |
38 | | /////////////////////////////////////////////////////////////////////////////// |
39 | | // LOCAL file class definitions |
40 | | /////////////////////////////////////////////////////////////////////////////// |
41 | | |
42 | | namespace log4cplus { |
43 | | |
44 | | namespace spi { |
45 | | |
46 | | BaseFactory::~BaseFactory() |
47 | 0 | { } |
48 | | |
49 | | |
50 | | AppenderFactory::AppenderFactory() |
51 | 700 | { } |
52 | | |
53 | | AppenderFactory::~AppenderFactory() |
54 | | { } |
55 | | |
56 | | |
57 | | LayoutFactory::LayoutFactory() |
58 | 210 | { } |
59 | | |
60 | | LayoutFactory::~LayoutFactory() |
61 | | { } |
62 | | |
63 | | |
64 | | FilterFactory::FilterFactory() |
65 | 420 | { } |
66 | | |
67 | | FilterFactory::~FilterFactory() |
68 | | { } |
69 | | |
70 | | |
71 | | LocaleFactory::LocaleFactory() |
72 | 280 | { } |
73 | | |
74 | | LocaleFactory::~LocaleFactory() |
75 | | { } |
76 | | |
77 | | |
78 | | LoggerFactory::~LoggerFactory() |
79 | 0 | { } |
80 | | |
81 | | |
82 | | namespace |
83 | | { |
84 | | |
85 | | class GlobalLocale |
86 | | : public LocalFactoryBase<LocaleFactory> |
87 | | { |
88 | | public: |
89 | | explicit |
90 | | GlobalLocale (tchar const * n) |
91 | 140 | : LocalFactoryBase<LocaleFactory> (n) |
92 | 140 | { } |
93 | | |
94 | | ProductPtr |
95 | | createObject (const log4cplus::helpers::Properties &) override |
96 | 61.9k | { |
97 | 61.9k | return std::locale (); |
98 | 61.9k | } |
99 | | }; |
100 | | |
101 | | |
102 | | class UserLocale |
103 | | : public LocalFactoryBase<LocaleFactory> |
104 | | { |
105 | | public: |
106 | | explicit |
107 | | UserLocale (tchar const * n) |
108 | 70 | : LocalFactoryBase<LocaleFactory> (n) |
109 | 70 | { } |
110 | | |
111 | | ProductPtr |
112 | | createObject (const log4cplus::helpers::Properties &) override |
113 | 0 | { |
114 | 0 | return std::locale (""); |
115 | 0 | } |
116 | | }; |
117 | | |
118 | | |
119 | | class ClassicLocale |
120 | | : public LocalFactoryBase<LocaleFactory> |
121 | | { |
122 | | public: |
123 | | explicit |
124 | | ClassicLocale (tchar const * n) |
125 | 70 | : LocalFactoryBase<LocaleFactory> (n) |
126 | 70 | { } |
127 | | |
128 | | ProductPtr |
129 | | createObject (const log4cplus::helpers::Properties &) override |
130 | 0 | { |
131 | 0 | return std::locale::classic (); |
132 | 0 | } |
133 | | }; |
134 | | |
135 | | |
136 | | } // namespace |
137 | | |
138 | | |
139 | | |
140 | | |
141 | | } // namespace spi |
142 | | |
143 | | |
144 | | namespace |
145 | | { |
146 | | |
147 | | template <typename Factory> |
148 | | struct DisableFactoryLocking |
149 | | { |
150 | | typedef Factory factory_type; |
151 | | |
152 | | explicit |
153 | | DisableFactoryLocking (factory_type & f) |
154 | 280 | : factory (f) |
155 | 280 | { |
156 | 280 | factory._enableLocking (false); |
157 | 280 | } factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::AppenderFactory> >::DisableFactoryLocking(log4cplus::spi::FactoryRegistry<log4cplus::spi::AppenderFactory>&) Line | Count | Source | 154 | 70 | : factory (f) | 155 | 70 | { | 156 | 70 | factory._enableLocking (false); | 157 | 70 | } |
factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::LayoutFactory> >::DisableFactoryLocking(log4cplus::spi::FactoryRegistry<log4cplus::spi::LayoutFactory>&) Line | Count | Source | 154 | 70 | : factory (f) | 155 | 70 | { | 156 | 70 | factory._enableLocking (false); | 157 | 70 | } |
factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::FilterFactory> >::DisableFactoryLocking(log4cplus::spi::FactoryRegistry<log4cplus::spi::FilterFactory>&) Line | Count | Source | 154 | 70 | : factory (f) | 155 | 70 | { | 156 | 70 | factory._enableLocking (false); | 157 | 70 | } |
factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::LocaleFactory> >::DisableFactoryLocking(log4cplus::spi::FactoryRegistry<log4cplus::spi::LocaleFactory>&) Line | Count | Source | 154 | 70 | : factory (f) | 155 | 70 | { | 156 | 70 | factory._enableLocking (false); | 157 | 70 | } |
|
158 | | |
159 | | ~DisableFactoryLocking () |
160 | 280 | { |
161 | 280 | factory._enableLocking (true); |
162 | 280 | } factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::AppenderFactory> >::~DisableFactoryLocking() Line | Count | Source | 160 | 70 | { | 161 | 70 | factory._enableLocking (true); | 162 | 70 | } |
factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::LayoutFactory> >::~DisableFactoryLocking() Line | Count | Source | 160 | 70 | { | 161 | 70 | factory._enableLocking (true); | 162 | 70 | } |
factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::FilterFactory> >::~DisableFactoryLocking() Line | Count | Source | 160 | 70 | { | 161 | 70 | factory._enableLocking (true); | 162 | 70 | } |
factory.cxx:log4cplus::(anonymous namespace)::DisableFactoryLocking<log4cplus::spi::FactoryRegistry<log4cplus::spi::LocaleFactory> >::~DisableFactoryLocking() Line | Count | Source | 160 | 70 | { | 161 | 70 | factory._enableLocking (true); | 162 | 70 | } |
|
163 | | |
164 | | factory_type & factory; |
165 | | }; |
166 | | |
167 | | } // namespace |
168 | | |
169 | | |
170 | | void initializeFactoryRegistry() |
171 | 70 | { |
172 | 70 | spi::AppenderFactoryRegistry& reg = spi::getAppenderFactoryRegistry(); |
173 | 70 | DisableFactoryLocking<spi::AppenderFactoryRegistry> dfl_reg (reg); |
174 | 70 | LOG4CPLUS_REG_APPENDER (reg, ConsoleAppender); |
175 | 70 | LOG4CPLUS_REG_APPENDER (reg, NullAppender); |
176 | 70 | LOG4CPLUS_REG_APPENDER (reg, FileAppender); |
177 | 70 | LOG4CPLUS_REG_APPENDER (reg, RollingFileAppender); |
178 | 70 | LOG4CPLUS_REG_APPENDER (reg, DailyRollingFileAppender); |
179 | 70 | LOG4CPLUS_REG_APPENDER (reg, TimeBasedRollingFileAppender); |
180 | 70 | LOG4CPLUS_REG_APPENDER (reg, SocketAppender); |
181 | | #if defined(_WIN32) |
182 | | # if defined(LOG4CPLUS_HAVE_NT_EVENT_LOG) |
183 | | LOG4CPLUS_REG_APPENDER (reg, NTEventLogAppender); |
184 | | # endif |
185 | | # if defined(LOG4CPLUS_HAVE_WIN32_CONSOLE) |
186 | | LOG4CPLUS_REG_APPENDER (reg, Win32ConsoleAppender); |
187 | | # endif |
188 | | LOG4CPLUS_REG_APPENDER (reg, Win32DebugAppender); |
189 | | #endif |
190 | 70 | LOG4CPLUS_REG_APPENDER (reg, SysLogAppender); |
191 | 70 | #ifndef LOG4CPLUS_SINGLE_THREADED |
192 | 70 | LOG4CPLUS_REG_APPENDER (reg, AsyncAppender); |
193 | 70 | #endif |
194 | 70 | LOG4CPLUS_REG_APPENDER (reg, Log4jUdpAppender); |
195 | | |
196 | 70 | spi::LayoutFactoryRegistry& reg2 = spi::getLayoutFactoryRegistry(); |
197 | 70 | DisableFactoryLocking<spi::LayoutFactoryRegistry> dfl_reg2 (reg2); |
198 | 70 | LOG4CPLUS_REG_LAYOUT (reg2, SimpleLayout); |
199 | 70 | LOG4CPLUS_REG_LAYOUT (reg2, TTCCLayout); |
200 | 70 | LOG4CPLUS_REG_LAYOUT (reg2, PatternLayout); |
201 | | |
202 | 70 | spi::FilterFactoryRegistry& reg3 = spi::getFilterFactoryRegistry(); |
203 | 70 | DisableFactoryLocking<spi::FilterFactoryRegistry> dfl_reg3 (reg3); |
204 | 70 | LOG4CPLUS_REG_FILTER (reg3, DenyAllFilter); |
205 | 70 | LOG4CPLUS_REG_FILTER (reg3, LogLevelMatchFilter); |
206 | 70 | LOG4CPLUS_REG_FILTER (reg3, LogLevelRangeFilter); |
207 | 70 | LOG4CPLUS_REG_FILTER (reg3, StringMatchFilter); |
208 | 70 | LOG4CPLUS_REG_FILTER (reg3, NDCMatchFilter); |
209 | 70 | LOG4CPLUS_REG_FILTER (reg3, MDCMatchFilter); |
210 | | |
211 | 70 | spi::LocaleFactoryRegistry& reg4 = spi::getLocaleFactoryRegistry(); |
212 | 70 | DisableFactoryLocking<spi::LocaleFactoryRegistry> dfl_reg4 (reg4); |
213 | 70 | LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("GLOBAL"), spi::GlobalLocale); |
214 | 70 | LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("DEFAULT"), spi::GlobalLocale); |
215 | 70 | LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("USER"), spi::UserLocale); |
216 | 70 | LOG4CPLUS_REG_LOCALE (reg4, LOG4CPLUS_TEXT("CLASSIC"), spi::ClassicLocale); |
217 | 70 | } |
218 | | |
219 | | |
220 | | } // namespace log4cplus |