Coverage Report

Created: 2025-07-11 07:00

/src/logging-log4cxx/src/main/cpp/class.cpp
Line
Count
Source (jump to first uncovered line)
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
}
Unexecuted instantiation: log4cxx::libraryVersion()
Unexecuted instantiation: log4cxx::libraryVersion()
90
}
91
92
#if LOG4CXX_ABI_VERSION <= 15
93
LOG4CXX_EXPORT uint32_t libraryVersion()
94
0
{
95
0
  return  LOG4CXX_NS::libraryVersion();
96
0
}
Unexecuted instantiation: libraryVersion()
Unexecuted instantiation: libraryVersion()
97
#endif
98
99
Class::Class()
100
3.53k
{
101
3.53k
}
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
3.54k
{
126
3.54k
  static WideLife<ClassMap> registry;
127
3.54k
  return registry;
128
3.54k
}
129
130
const Class& Class::forName(const LogString& className)
131
4
{
132
4
  LogString lowerName(StringHelper::toLowerCase(className));
133
  //
134
  //  check registry using full class name
135
  //
136
4
  const Class* clazz = getRegistry()[lowerName];
137
138
4
  if (clazz == 0)
139
4
  {
140
4
    LogString::size_type pos = className.find_last_of(LOG4CXX_STR(".$"));
141
142
4
    if (pos != LogString::npos)
143
4
    {
144
4
      LogString terminalName(lowerName, pos + 1, LogString::npos);
145
4
      clazz = getRegistry()[terminalName];
146
147
4
      if (clazz == 0)
148
0
      {
149
0
        registerClasses();
150
0
        clazz = getRegistry()[lowerName];
151
152
0
        if (clazz == 0)
153
0
        {
154
0
          clazz = getRegistry()[terminalName];
155
0
        }
156
0
      }
157
4
    }
158
0
    else
159
0
    {
160
0
      registerClasses();
161
0
      clazz = getRegistry()[lowerName];
162
0
    }
163
4
  }
164
165
4
  if (clazz == 0)
166
0
  {
167
0
    throw ClassNotFoundException(className);
168
0
  }
169
170
4
  return *clazz;
171
4
}
log4cxx::helpers::Class::forName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
131
2
{
132
2
  LogString lowerName(StringHelper::toLowerCase(className));
133
  //
134
  //  check registry using full class name
135
  //
136
2
  const Class* clazz = getRegistry()[lowerName];
137
138
2
  if (clazz == 0)
139
2
  {
140
2
    LogString::size_type pos = className.find_last_of(LOG4CXX_STR(".$"));
141
142
2
    if (pos != LogString::npos)
143
2
    {
144
2
      LogString terminalName(lowerName, pos + 1, LogString::npos);
145
2
      clazz = getRegistry()[terminalName];
146
147
2
      if (clazz == 0)
148
0
      {
149
0
        registerClasses();
150
0
        clazz = getRegistry()[lowerName];
151
152
0
        if (clazz == 0)
153
0
        {
154
0
          clazz = getRegistry()[terminalName];
155
0
        }
156
0
      }
157
2
    }
158
0
    else
159
0
    {
160
0
      registerClasses();
161
0
      clazz = getRegistry()[lowerName];
162
0
    }
163
2
  }
164
165
2
  if (clazz == 0)
166
0
  {
167
0
    throw ClassNotFoundException(className);
168
0
  }
169
170
2
  return *clazz;
171
2
}
log4cxx::helpers::Class::forName(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
131
2
{
132
2
  LogString lowerName(StringHelper::toLowerCase(className));
133
  //
134
  //  check registry using full class name
135
  //
136
2
  const Class* clazz = getRegistry()[lowerName];
137
138
2
  if (clazz == 0)
139
2
  {
140
2
    LogString::size_type pos = className.find_last_of(LOG4CXX_STR(".$"));
141
142
2
    if (pos != LogString::npos)
143
2
    {
144
2
      LogString terminalName(lowerName, pos + 1, LogString::npos);
145
2
      clazz = getRegistry()[terminalName];
146
147
2
      if (clazz == 0)
148
0
      {
149
0
        registerClasses();
150
0
        clazz = getRegistry()[lowerName];
151
152
0
        if (clazz == 0)
153
0
        {
154
0
          clazz = getRegistry()[terminalName];
155
0
        }
156
0
      }
157
2
    }
158
0
    else
159
0
    {
160
0
      registerClasses();
161
0
      clazz = getRegistry()[lowerName];
162
0
    }
163
2
  }
164
165
2
  if (clazz == 0)
166
0
  {
167
0
    throw ClassNotFoundException(className);
168
0
  }
169
170
2
  return *clazz;
171
2
}
172
173
bool Class::registerClass(const Class& newClass)
174
3.53k
{
175
3.53k
  getRegistry()[StringHelper::toLowerCase(newClass.getName())] = &newClass;
176
3.53k
  return true;
177
3.53k
}
178
179
void Class::registerClasses()
180
0
{
181
0
  AsyncAppender::registerClass();
182
0
  ConsoleAppender::registerClass();
183
0
  FileAppender::registerClass();
184
0
  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
0
  SMTPAppender::registerClass();
192
0
  JSONLayout::registerClass();
193
0
  HTMLLayout::registerClass();
194
#if LOG4CXX_HAS_FMT_LAYOUT
195
  FMTLayout::registerClass();
196
#endif
197
0
  PatternLayout::registerClass();
198
0
  SimpleLayout::registerClass();
199
0
  XMLLayout::registerClass();
200
0
  LevelMatchFilter::registerClass();
201
0
  LevelRangeFilter::registerClass();
202
0
  StringMatchFilter::registerClass();
203
0
  LocationInfoFilter::registerClass();
204
0
  LOG4CXX_NS::rolling::RollingFileAppender::registerClass();
205
#if LOG4CXX_HAS_MULTIPROCESS_ROLLING_FILE_APPENDER
206
  LOG4CXX_NS::rolling::MultiprocessRollingFileAppender::registerClass();
207
#endif
208
0
  LOG4CXX_NS::rolling::SizeBasedTriggeringPolicy::registerClass();
209
0
  LOG4CXX_NS::rolling::TimeBasedRollingPolicy::registerClass();
210
0
  LOG4CXX_NS::rolling::ManualTriggeringPolicy::registerClass();
211
0
  LOG4CXX_NS::rolling::FixedWindowRollingPolicy::registerClass();
212
0
  LOG4CXX_NS::rolling::FilterBasedTriggeringPolicy::registerClass();
213
0
#if LOG4CXX_HAS_DOMCONFIGURATOR
214
0
  LOG4CXX_NS::xml::DOMConfigurator::registerClass();
215
0
#endif
216
0
  LOG4CXX_NS::PropertyConfigurator::registerClass();
217
0
  LOG4CXX_NS::varia::FallbackErrorHandler::registerClass();
218
0
#if LOG4CXX_HAS_NETWORKING
219
0
  TelnetAppender::registerClass();
220
0
  XMLSocketAppender::registerClass();
221
0
  SyslogAppender::registerClass();
222
0
#endif
223
0
}
Unexecuted instantiation: log4cxx::helpers::Class::registerClasses()
Unexecuted instantiation: log4cxx::helpers::Class::registerClasses()
224