Coverage Report

Created: 2025-10-27 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/class.cpp
Line
Count
Source
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
#include <log4cxx/logstring.h>
19
#include <log4cxx/helpers/class.h>
20
#include <log4cxx/helpers/exception.h>
21
#include <log4cxx/helpers/object.h>
22
#include <map>
23
#include <log4cxx/helpers/stringhelper.h>
24
#include <log4cxx/log4cxx.h>
25
#if !defined(LOG4CXX)
26
  #define LOG4CXX 1
27
#endif
28
#include <log4cxx/private/log4cxx_private.h>
29
30
31
#include <log4cxx/asyncappender.h>
32
#include <log4cxx/consoleappender.h>
33
#include <log4cxx/fileappender.h>
34
#include <log4cxx/db/odbcappender.h>
35
#if defined(WIN32) || defined(_WIN32)
36
  #if !defined(_WIN32_WCE)
37
    #include <log4cxx/nt/nteventlogappender.h>
38
  #endif
39
  #include <log4cxx/nt/outputdebugstringappender.h>
40
#endif
41
#include <log4cxx/net/smtpappender.h>
42
#if LOG4CXX_HAS_MULTIPROCESS_ROLLING_FILE_APPENDER
43
#include <log4cxx/rolling/multiprocessrollingfileappender.h>
44
#endif
45
#include <log4cxx/helpers/datagramsocket.h>
46
#include <log4cxx/net/syslogappender.h>
47
#include <log4cxx/net/telnetappender.h>
48
#include <log4cxx/writerappender.h>
49
#include <log4cxx/net/xmlsocketappender.h>
50
#include <log4cxx/layout.h>
51
#include <log4cxx/patternlayout.h>
52
#include <log4cxx/jsonlayout.h>
53
#include <log4cxx/htmllayout.h>
54
#include <log4cxx/simplelayout.h>
55
#include <log4cxx/xml/xmllayout.h>
56
#if LOG4CXX_HAS_FMT_LAYOUT
57
#include <log4cxx/fmtlayout.h>
58
#endif
59
60
#include <log4cxx/filter/levelmatchfilter.h>
61
#include <log4cxx/filter/levelrangefilter.h>
62
#include <log4cxx/filter/stringmatchfilter.h>
63
#include <log4cxx/filter/locationinfofilter.h>
64
#include <log4cxx/rolling/filterbasedtriggeringpolicy.h>
65
#include <log4cxx/rolling/fixedwindowrollingpolicy.h>
66
#include <log4cxx/rolling/manualtriggeringpolicy.h>
67
#include <log4cxx/rolling/rollingfileappender.h>
68
#include <log4cxx/rolling/sizebasedtriggeringpolicy.h>
69
#include <log4cxx/rolling/timebasedrollingpolicy.h>
70
71
#include <log4cxx/xml/domconfigurator.h>
72
#include <log4cxx/propertyconfigurator.h>
73
#include <log4cxx/varia/fallbackerrorhandler.h>
74
75
76
using namespace LOG4CXX_NS;
77
using namespace LOG4CXX_NS::helpers;
78
using namespace LOG4CXX_NS::net;
79
using namespace LOG4CXX_NS::filter;
80
using namespace LOG4CXX_NS::xml;
81
using namespace LOG4CXX_NS::rolling;
82
83
namespace LOG4CXX_NS
84
{
85
uint32_t libraryVersion()
86
0
{
87
  // This function defined in log4cxx.h
88
0
  return LOG4CXX_VERSION;
89
0
}
90
}
91
92
#if LOG4CXX_ABI_VERSION <= 15
93
LOG4CXX_EXPORT uint32_t libraryVersion()
94
0
{
95
0
  return  LOG4CXX_NS::libraryVersion();
96
0
}
97
#endif
98
99
Class::Class()
100
228
{
101
228
}
102
103
Class::~Class()
104
0
{
105
0
}
106
107
#if LOG4CXX_ABI_VERSION <= 15
108
LogString Class::toString() const
109
0
{
110
0
  return getName();
111
0
}
112
#endif
113
114
Object* Class::newInstance() const
115
0
{
116
0
  throw InstantiationException(LOG4CXX_STR("Cannot create new instances of Class."));
117
#if LOG4CXX_RETURN_AFTER_THROW
118
  return 0;
119
#endif
120
0
}
121
122
123
124
Class::ClassMap& Class::getRegistry()
125
679
{
126
679
  static WideLife<ClassMap> registry;
127
679
  return registry;
128
679
}
129
130
const Class& Class::forName(const LogString& className)
131
126
{
132
126
  LogString lowerName(StringHelper::toLowerCase(className));
133
  //
134
  //  check registry using full class name
135
  //
136
126
  const Class* clazz = getRegistry()[lowerName];
137
138
126
  if (clazz == 0)
139
123
  {
140
123
    LogString::size_type pos = className.find_last_of(LOG4CXX_STR(".$"));
141
142
123
    if (pos != LogString::npos)
143
103
    {
144
103
      LogString terminalName(lowerName, pos + 1, LogString::npos);
145
103
      clazz = getRegistry()[terminalName];
146
147
103
      if (clazz == 0)
148
101
      {
149
101
        registerClasses();
150
101
        clazz = getRegistry()[lowerName];
151
152
101
        if (clazz == 0)
153
101
        {
154
101
          clazz = getRegistry()[terminalName];
155
101
        }
156
101
      }
157
103
    }
158
20
    else
159
20
    {
160
20
      registerClasses();
161
20
      clazz = getRegistry()[lowerName];
162
20
    }
163
123
  }
164
165
126
  if (clazz == 0)
166
121
  {
167
121
    throw ClassNotFoundException(className);
168
121
  }
169
170
5
  return *clazz;
171
126
}
172
173
bool Class::registerClass(const Class& newClass)
174
228
{
175
228
  getRegistry()[StringHelper::toLowerCase(newClass.getName())] = &newClass;
176
228
  return true;
177
228
}
178
179
void Class::registerClasses()
180
121
{
181
121
  AsyncAppender::registerClass();
182
121
  ConsoleAppender::registerClass();
183
121
  FileAppender::registerClass();
184
121
  LOG4CXX_NS::db::ODBCAppender::registerClass();
185
#if (defined(WIN32) || defined(_WIN32))
186
#if !defined(_WIN32_WCE)
187
  LOG4CXX_NS::nt::NTEventLogAppender::registerClass();
188
#endif
189
  LOG4CXX_NS::nt::OutputDebugStringAppender::registerClass();
190
#endif
191
121
  SMTPAppender::registerClass();
192
121
  JSONLayout::registerClass();
193
121
  HTMLLayout::registerClass();
194
#if LOG4CXX_HAS_FMT_LAYOUT
195
  FMTLayout::registerClass();
196
#endif
197
121
  PatternLayout::registerClass();
198
121
  SimpleLayout::registerClass();
199
121
  XMLLayout::registerClass();
200
121
  LevelMatchFilter::registerClass();
201
121
  LevelRangeFilter::registerClass();
202
121
  StringMatchFilter::registerClass();
203
121
  LocationInfoFilter::registerClass();
204
121
  LOG4CXX_NS::rolling::RollingFileAppender::registerClass();
205
#if LOG4CXX_HAS_MULTIPROCESS_ROLLING_FILE_APPENDER
206
  LOG4CXX_NS::rolling::MultiprocessRollingFileAppender::registerClass();
207
#endif
208
121
  LOG4CXX_NS::rolling::SizeBasedTriggeringPolicy::registerClass();
209
121
  LOG4CXX_NS::rolling::TimeBasedRollingPolicy::registerClass();
210
121
  LOG4CXX_NS::rolling::ManualTriggeringPolicy::registerClass();
211
121
  LOG4CXX_NS::rolling::FixedWindowRollingPolicy::registerClass();
212
121
  LOG4CXX_NS::rolling::FilterBasedTriggeringPolicy::registerClass();
213
121
#if LOG4CXX_HAS_DOMCONFIGURATOR
214
121
  LOG4CXX_NS::xml::DOMConfigurator::registerClass();
215
121
#endif
216
121
  LOG4CXX_NS::PropertyConfigurator::registerClass();
217
121
  LOG4CXX_NS::varia::FallbackErrorHandler::registerClass();
218
121
#if LOG4CXX_HAS_NETWORKING
219
121
  TelnetAppender::registerClass();
220
121
  XMLSocketAppender::registerClass();
221
121
  SyslogAppender::registerClass();
222
121
#endif
223
121
}
224