Coverage Report

Created: 2025-12-31 07:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/log4cplus/src/logger.cxx
Line
Count
Source
1
// Module:  Log4CPLUS
2
// File:    logger.cxx
3
// Created: 6/2001
4
// Author:  Tad E. Smith
5
//
6
//
7
// Copyright 2001-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/logger.h>
22
#include <log4cplus/appender.h>
23
#include <log4cplus/hierarchy.h>
24
#include <log4cplus/helpers/loglog.h>
25
#include <log4cplus/spi/loggerimpl.h>
26
#include <utility>
27
28
29
namespace log4cplus
30
{
31
32
33
Logger
34
DefaultLoggerFactory::makeNewLoggerInstance (const log4cplus::tstring & name,
35
    Hierarchy& h)
36
162
{
37
162
    return Logger (makeNewLoggerImplInstance(name, h));
38
162
}
39
40
41
spi::LoggerImpl *
42
DefaultLoggerFactory::makeNewLoggerImplInstance(const log4cplus::tstring& name,
43
    Hierarchy& h)
44
162
{
45
162
    return new spi::LoggerImpl (name, h);
46
162
}
47
48
49
//////////////////////////////////////////////////////////////////////////////
50
// static Logger Methods
51
//////////////////////////////////////////////////////////////////////////////
52
//
53
Hierarchy &
54
Logger::getDefaultHierarchy ()
55
1.08M
{
56
1.08M
    return log4cplus::getDefaultHierarchy ();
57
1.08M
}
58
59
60
bool
61
Logger::exists (const log4cplus::tstring & name)
62
0
{
63
0
    return getDefaultHierarchy().exists(name);
64
0
}
65
66
67
LoggerList
68
Logger::getCurrentLoggers ()
69
102k
{
70
102k
    return getDefaultHierarchy ().getCurrentLoggers ();
71
102k
}
72
73
74
Logger
75
Logger::getInstance (const log4cplus::tstring& name)
76
303k
{
77
303k
    return getDefaultHierarchy().getInstance(name);
78
303k
}
79
80
81
Logger
82
Logger::getInstance (const log4cplus::tstring& name,
83
    spi::LoggerFactory& factory)
84
0
{
85
0
    return getDefaultHierarchy().getInstance(name, factory);
86
0
}
87
88
89
Logger
90
Logger::getRoot ()
91
226k
{
92
226k
    return getDefaultHierarchy ().getRoot ();
93
226k
}
94
95
96
void
97
Logger::shutdown ()
98
0
{
99
0
    getDefaultHierarchy ().shutdown ();
100
0
}
101
102
103
//////////////////////////////////////////////////////////////////////////////
104
// Logger ctors and dtor
105
//////////////////////////////////////////////////////////////////////////////
106
107
Logger::Logger () LOG4CPLUS_NOEXCEPT
108
303k
{ }
109
110
111
Logger::Logger (spi::LoggerImpl * ptr) LOG4CPLUS_NOEXCEPT
112
302
    : value (ptr)
113
302
{
114
302
    if (value)
115
232
        value->addReference ();
116
302
}
117
118
119
Logger::Logger (const Logger& rhs) LOG4CPLUS_NOEXCEPT
120
5.53M
    : spi::AppenderAttachable (rhs)
121
5.53M
    , value (rhs.value)
122
5.53M
{
123
5.53M
    if (value)
124
5.53M
        value->addReference ();
125
5.53M
}
126
127
128
Logger &
129
Logger::operator = (const Logger& rhs) LOG4CPLUS_NOEXCEPT
130
303k
{
131
303k
    Logger (rhs).swap (*this);
132
303k
    return *this;
133
303k
}
134
135
136
Logger::Logger (Logger && rhs) LOG4CPLUS_NOEXCEPT
137
232
    : spi::AppenderAttachable (std::move (rhs))
138
232
    , value (rhs.value)
139
232
{
140
232
    rhs.value = nullptr;
141
232
}
142
143
144
Logger &
145
Logger::operator = (Logger && rhs) LOG4CPLUS_NOEXCEPT
146
232
{
147
232
    Logger (std::move (rhs)).swap (*this);
148
232
    return *this;
149
232
}
150
151
152
Logger::~Logger ()
153
5.83M
{
154
5.83M
    if (value)
155
5.53M
        value->removeReference ();
156
5.83M
}
157
158
159
//////////////////////////////////////////////////////////////////////////////
160
// Logger Methods
161
//////////////////////////////////////////////////////////////////////////////
162
163
void
164
Logger::swap (Logger & other) LOG4CPLUS_NOEXCEPT
165
303k
{
166
303k
    std::swap (value, other.value);
167
303k
}
168
169
170
Logger
171
Logger::getParent () const
172
0
{
173
0
    if (value->parent)
174
0
        return Logger (value->parent.get ());
175
0
    else
176
0
    {
177
0
        helpers::getLogLog().error(
178
0
            LOG4CPLUS_TEXT("********* This logger has no parent: ")
179
0
            + getName());
180
0
        return *this;
181
0
    }
182
0
}
183
184
185
void
186
Logger::addAppender (SharedAppenderPtr newAppender)
187
426k
{
188
426k
    value->addAppender(newAppender);
189
426k
}
190
191
192
SharedAppenderPtrList
193
Logger::getAllAppenders ()
194
2.23M
{
195
2.23M
    return value->getAllAppenders();
196
2.23M
}
197
198
199
SharedAppenderPtr
200
Logger::getAppender (const log4cplus::tstring& name)
201
626k
{
202
626k
    return value->getAppender (name);
203
626k
}
204
205
206
void
207
Logger::removeAllAppenders ()
208
2.43M
{
209
2.43M
    value->removeAllAppenders ();
210
2.43M
}
211
212
213
void
214
Logger::removeAppender (SharedAppenderPtr appender)
215
0
{
216
0
    value->removeAppender(appender);
217
0
}
218
219
220
void
221
Logger::removeAppender (const log4cplus::tstring& name)
222
0
{
223
0
    value->removeAppender (name);
224
0
}
225
226
227
void
228
Logger::assertion (bool assertionVal, const log4cplus::tstring& msg) const
229
0
{
230
0
    if (! assertionVal)
231
0
        log (FATAL_LOG_LEVEL, msg, nullptr, -1);
232
0
}
233
234
235
void
236
Logger::closeNestedAppenders () const
237
2.23M
{
238
2.23M
    value->closeNestedAppenders ();
239
2.23M
}
240
241
242
bool
243
Logger::isEnabledFor (LogLevel ll) const
244
4.95M
{
245
4.95M
    return value->isEnabledFor (ll);
246
4.95M
}
247
248
249
void
250
Logger::log (LogLevel ll, const log4cplus::tstring& message, const char* file,
251
    int line, const char* function) const
252
0
{
253
0
    value->log (ll, message, file, line, function ? function : "");
254
0
}
255
256
257
void
258
Logger::log (spi::InternalLoggingEvent const & ev) const
259
0
{
260
0
    value->log (ev);
261
0
}
262
263
264
void
265
Logger::forcedLog (LogLevel ll, const log4cplus::tstring& message,
266
    const char* file, int line, const char* function) const
267
0
{
268
0
    value->forcedLog (ll, message, file, line, function ? function : "");
269
0
}
270
271
272
void
273
Logger::forcedLog (spi::InternalLoggingEvent const & ev) const
274
773k
{
275
773k
    value->forcedLog (ev);
276
773k
}
277
278
279
void
280
Logger::callAppenders (const spi::InternalLoggingEvent& event) const
281
0
{
282
0
    value->callAppenders (event);
283
0
}
284
285
286
LogLevel
287
Logger::getChainedLogLevel () const
288
0
{
289
0
    return value->getChainedLogLevel ();
290
0
}
291
292
293
LogLevel
294
Logger::getLogLevel() const
295
0
{
296
0
    return value->getLogLevel ();
297
0
}
298
299
300
void
301
Logger::setLogLevel (LogLevel ll)
302
2.88M
{
303
2.88M
    value->setLogLevel (ll);
304
2.88M
}
305
306
307
Hierarchy &
308
Logger::getHierarchy () const
309
0
{
310
0
    return value->getHierarchy ();
311
0
}
312
313
314
log4cplus::tstring const &
315
Logger::getName () const
316
773k
{
317
773k
    return value->getName ();
318
773k
}
319
320
321
bool
322
Logger::getAdditivity () const
323
0
{
324
0
    return value->getAdditivity ();
325
0
}
326
327
328
void
329
Logger::setAdditivity (bool additive)
330
1.97M
{
331
1.97M
    value->setAdditivity (additive);
332
1.97M
}
333
334
335
} // namespace log4cplus