Coverage Report

Created: 2026-12-01 07:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/logmanager.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/logmanager.h>
19
#include <log4cxx/defaultconfigurator.h>
20
#include <log4cxx/spi/defaultrepositoryselector.h>
21
#include <log4cxx/hierarchy.h>
22
#include <log4cxx/spi/rootlogger.h>
23
#include <log4cxx/spi/loggerfactory.h>
24
#include <stdexcept>
25
#include <log4cxx/level.h>
26
#include <log4cxx/spi/loggerrepository.h>
27
#include <log4cxx/helpers/exception.h>
28
#include <log4cxx/helpers/optionconverter.h>
29
#include <log4cxx/helpers/loglog.h>
30
#include <log4cxx/helpers/threadutility.h>
31
32
#include <log4cxx/spi/loggingevent.h>
33
#include <log4cxx/file.h>
34
#include <log4cxx/helpers/transcoder.h>
35
#if !defined(LOG4CXX)
36
  #define LOG4CXX 1
37
#endif
38
#include <log4cxx/helpers/aprinitializer.h>
39
40
using namespace LOG4CXX_NS;
41
using namespace LOG4CXX_NS::spi;
42
using namespace LOG4CXX_NS::helpers;
43
44
IMPLEMENT_LOG4CXX_OBJECT(DefaultRepositorySelector)
45
46
void* LogManager::guard = 0;
47
48
RepositorySelectorPtr LogManager::getRepositorySelector()
49
31.0k
{
50
31.0k
  auto result = APRInitializer::getOrAddUnique<spi::RepositorySelector>( []() -> ObjectPtr
51
31.0k
    {
52
9
      LoggerRepositoryPtr hierarchy = Hierarchy::create();
53
9
      return std::make_shared<DefaultRepositorySelector>(hierarchy);
54
9
    }
55
31.0k
  );
56
31.0k
  return result;
57
31.0k
}
58
59
void LogManager::setRepositorySelector(const spi::RepositorySelectorPtr& selector, void* guard1)
60
0
{
61
0
  if ((LogManager::guard != 0) && (LogManager::guard != guard1))
62
0
  {
63
0
    throw IllegalArgumentException(LOG4CXX_STR("Attempted to reset the LoggerFactory without possessing the guard."));
64
0
  }
65
66
0
  if (selector == 0)
67
0
  {
68
0
    throw NullPointerException(LOG4CXX_STR("RepositorySelector"));
69
0
  }
70
71
0
  LogManager::guard = guard1;
72
0
  APRInitializer::setUnique<spi::RepositorySelector>(selector);
73
0
}
74
75
LoggerRepositoryPtr LogManager::getLoggerRepository()
76
31.0k
{
77
31.0k
  return getRepositorySelector()->getLoggerRepository();
78
31.0k
}
79
80
LoggerPtr LogManager::getRootLogger()
81
6.29k
{
82
  // Delegate the actual manufacturing of the logger to the logger repository.
83
6.29k
  auto r = getLoggerRepository();
84
6.29k
  r->ensureIsConfigured(std::bind(DefaultConfigurator::configure, r));
85
6.29k
  return r->getRootLogger();
86
6.29k
}
87
88
/**
89
Retrieve the appropriate Logger instance.
90
*/
91
LoggerPtr LogManager::getLoggerLS(const LogString& name,
92
  const spi::LoggerFactoryPtr& factory)
93
1.08k
{
94
  // Delegate the actual manufacturing of the logger to the logger repository.
95
1.08k
  auto r = getLoggerRepository();
96
1.08k
  r->ensureIsConfigured(std::bind(DefaultConfigurator::configure, r));
97
1.08k
  return r->getLogger(name, factory);
98
1.08k
}
log4cxx::LogManager::getLoggerLS(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::shared_ptr<log4cxx::spi::LoggerFactory> const&)
Line
Count
Source
93
902
{
94
  // Delegate the actual manufacturing of the logger to the logger repository.
95
902
  auto r = getLoggerRepository();
96
902
  r->ensureIsConfigured(std::bind(DefaultConfigurator::configure, r));
97
902
  return r->getLogger(name, factory);
98
902
}
log4cxx::LogManager::getLoggerLS(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<log4cxx::spi::LoggerFactory> const&)
Line
Count
Source
93
180
{
94
  // Delegate the actual manufacturing of the logger to the logger repository.
95
180
  auto r = getLoggerRepository();
96
180
  r->ensureIsConfigured(std::bind(DefaultConfigurator::configure, r));
97
180
  return r->getLogger(name, factory);
98
180
}
99
100
LoggerPtr LogManager::getLogger(const std::string& name,
101
  const spi::LoggerFactoryPtr& factory)
102
1.77k
{
103
1.77k
  LOG4CXX_DECODE_CHAR(n, name);
104
1.77k
  return getLoggerLS(n, factory);
105
1.77k
}
log4cxx::LogManager::getLogger(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<log4cxx::spi::LoggerFactory> const&)
Line
Count
Source
102
889
{
103
889
  LOG4CXX_DECODE_CHAR(n, name);
104
889
  return getLoggerLS(n, factory);
105
889
}
log4cxx::LogManager::getLogger(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<log4cxx::spi::LoggerFactory> const&)
Line
Count
Source
102
889
{
103
889
  LOG4CXX_DECODE_CHAR(n, name);
104
889
  return getLoggerLS(n, factory);
105
889
}
106
107
LoggerPtr LogManager::exists(const std::string& name)
108
0
{
109
0
  LOG4CXX_DECODE_CHAR(n, name);
110
0
  return existsLS(n);
111
0
}
Unexecuted instantiation: log4cxx::LogManager::exists(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Unexecuted instantiation: log4cxx::LogManager::exists(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
112
113
#if LOG4CXX_WCHAR_T_API
114
LoggerPtr LogManager::getLogger(const std::wstring& name,
115
  const spi::LoggerFactoryPtr& factory)
116
386
{
117
386
  LOG4CXX_DECODE_WCHAR(n, name);
118
386
  return getLoggerLS(n, factory);
119
386
}
log4cxx::LogManager::getLogger(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::shared_ptr<log4cxx::spi::LoggerFactory> const&)
Line
Count
Source
116
193
{
117
193
  LOG4CXX_DECODE_WCHAR(n, name);
118
193
  return getLoggerLS(n, factory);
119
193
}
log4cxx::LogManager::getLogger(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::shared_ptr<log4cxx::spi::LoggerFactory> const&)
Line
Count
Source
116
193
{
117
193
  LOG4CXX_DECODE_WCHAR(n, name);
118
193
  return getLoggerLS(n, factory);
119
193
}
120
121
LoggerPtr LogManager::exists(const std::wstring& name)
122
0
{
123
0
  LOG4CXX_DECODE_WCHAR(n, name);
124
0
  return existsLS(n);
125
0
}
Unexecuted instantiation: log4cxx::LogManager::exists(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Unexecuted instantiation: log4cxx::LogManager::exists(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
126
#endif
127
128
129
#if LOG4CXX_CFSTRING_API
130
LoggerPtr LogManager::getLogger(const CFStringRef& name,
131
  const spi::LoggerFactoryPtr& factory)
132
{
133
  LOG4CXX_DECODE_CFSTRING(n, name);
134
  return getLoggerLS(n, factory);
135
}
136
137
LoggerPtr LogManager::exists(const CFStringRef& name)
138
{
139
  LOG4CXX_DECODE_CFSTRING(n, name);
140
  return existsLS(n);
141
}
142
#endif
143
144
LoggerPtr LogManager::existsLS(const LogString& name)
145
0
{
146
0
  return getLoggerRepository()->exists(name);
147
0
}
Unexecuted instantiation: log4cxx::LogManager::existsLS(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Unexecuted instantiation: log4cxx::LogManager::existsLS(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
148
149
LoggerList LogManager::getCurrentLoggers()
150
0
{
151
0
  return getLoggerRepository()->getCurrentLoggers();
152
0
}
153
154
void LogManager::shutdown()
155
709
{
156
709
  ThreadUtility::instance()->removeAllPeriodicTasks();
157
709
  getLoggerRepository()->shutdown();
158
709
}
159
160
void LogManager::resetConfiguration()
161
11.1k
{
162
11.1k
  getLoggerRepository()->resetConfiguration();
163
11.1k
}
164
165
bool LogManager::removeLogger(const LogString& name, bool ifNotUsed)
166
0
{
167
0
  return getLoggerRepository()->removeLogger(name, ifNotUsed);
168
0
}
Unexecuted instantiation: log4cxx::LogManager::removeLogger(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, bool)
Unexecuted instantiation: log4cxx::LogManager::removeLogger(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)