Coverage Report

Created: 2026-05-16 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dcmtk/oflog/libsrc/logimpl.cc
Line
Count
Source
1
// Module:  Log4CPLUS
2
// File:    loggerimpl.cxx
3
// Created: 6/2001
4
// Author:  Tad E. Smith
5
//
6
//
7
// Copyright 2001-2010 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 "dcmtk/oflog/internal/internal.h"
22
#include "dcmtk/oflog/spi/logimpl.h"
23
#include "dcmtk/oflog/appender.h"
24
#include "dcmtk/oflog/hierarchy.h"
25
#include "dcmtk/oflog/helpers/loglog.h"
26
#include "dcmtk/oflog/spi/logevent.h"
27
#include "dcmtk/oflog/spi/rootlog.h"
28
#include "dcmtk/oflog/thread/syncpub.h"
29
30
31
namespace dcmtk {
32
namespace log4cplus { namespace spi {
33
34
//////////////////////////////////////////////////////////////////////////////
35
// Logger Constructors and Destructor
36
//////////////////////////////////////////////////////////////////////////////
37
LoggerImpl::LoggerImpl(const log4cplus::tstring& name_, Hierarchy& h)
38
6
  : name(name_),
39
6
    ll(NOT_SET_LOG_LEVEL),
40
6
    parent(NULL),
41
6
    additive(true), 
42
6
    hierarchy(h)
43
6
{
44
6
}
dcmtk::log4cplus::spi::LoggerImpl::LoggerImpl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, dcmtk::log4cplus::Hierarchy&)
Line
Count
Source
38
3
  : name(name_),
39
3
    ll(NOT_SET_LOG_LEVEL),
40
3
    parent(NULL),
41
3
    additive(true), 
42
3
    hierarchy(h)
43
3
{
44
3
}
dcmtk::log4cplus::spi::LoggerImpl::LoggerImpl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, dcmtk::log4cplus::Hierarchy&)
Line
Count
Source
38
3
  : name(name_),
39
3
    ll(NOT_SET_LOG_LEVEL),
40
3
    parent(NULL),
41
3
    additive(true), 
42
3
    hierarchy(h)
43
3
{
44
3
}
45
46
47
LoggerImpl::~LoggerImpl() 
48
0
{ 
49
0
}
50
51
52
//////////////////////////////////////////////////////////////////////////////
53
// Logger Methods
54
//////////////////////////////////////////////////////////////////////////////
55
56
void 
57
LoggerImpl::callAppenders(const InternalLoggingEvent& event)
58
0
{
59
0
    int writes = 0;
60
0
    for(const LoggerImpl* c = this; c != NULL; c=c->parent.get()) {
61
0
        writes += c->appendLoopOnAppenders(event);
62
0
        if(!c->additive) {
63
0
            break;
64
0
        }
65
0
    }
66
67
    // No appenders in hierarchy, warn user only once.
68
0
    if(!hierarchy.emittedNoAppenderWarning && writes == 0) {
69
0
        helpers::getLogLog().error(
70
0
            DCMTK_LOG4CPLUS_TEXT("No appenders could be found for logger (") 
71
0
            + getName() 
72
0
            + DCMTK_LOG4CPLUS_TEXT(")."));
73
0
        helpers::getLogLog().error(
74
0
            DCMTK_LOG4CPLUS_TEXT("Please initialize the log4cplus system properly."));
75
0
        hierarchy.emittedNoAppenderWarning = true;
76
0
    }
77
0
}
78
79
80
void 
81
LoggerImpl::closeNestedAppenders()
82
0
{
83
0
    SharedAppenderPtrList appenders = getAllAppenders();
84
0
    for(SharedAppenderPtrList::iterator it=appenders.begin(); it!=appenders.end(); ++it)
85
0
    {
86
0
        (*it)->close();
87
0
    }
88
0
}
89
90
91
bool 
92
LoggerImpl::isEnabledFor(LogLevel loglevel) const
93
0
{
94
0
    if(hierarchy.disableValue >= loglevel) {
95
0
        return false;
96
0
    }
97
0
    return loglevel >= getChainedLogLevel();
98
0
}
99
100
101
void 
102
LoggerImpl::log(LogLevel loglevel, 
103
                const log4cplus::tstring& message,
104
                const char* file, 
105
                int line)
106
0
{
107
0
    if(isEnabledFor(loglevel)) {
108
0
        forcedLog(loglevel, message, file, line);
109
0
    }
110
0
}
111
112
113
void 
114
LoggerImpl::log(spi::InternalLoggingEvent const & ev)
115
0
{
116
0
    if (isEnabledFor(ev.getLogLevel ()))
117
0
        forcedLog(ev);
118
0
}
119
120
121
LogLevel 
122
LoggerImpl::getChainedLogLevel() const
123
0
{
124
0
    for(const LoggerImpl *c=this; c != NULL; c=c->parent.get()) {
125
0
        if(c->ll != NOT_SET_LOG_LEVEL) {
126
0
            return c->ll;
127
0
        }
128
0
    }
129
130
0
    helpers::getLogLog().error(
131
0
        DCMTK_LOG4CPLUS_TEXT("LoggerImpl::getChainedLogLevel()- No valid LogLevel found"),
132
0
        true);
133
0
    return NOT_SET_LOG_LEVEL;
134
0
}
135
136
137
Hierarchy& 
138
LoggerImpl::getHierarchy() const
139
0
{ 
140
0
    return hierarchy; 
141
0
}
142
143
144
bool 
145
LoggerImpl::getAdditivity() const
146
0
{ 
147
0
    return additive; 
148
0
}
149
150
151
void 
152
LoggerImpl::setAdditivity(bool additive_) 
153
0
{ 
154
0
    additive = additive_; 
155
0
}
156
157
158
void 
159
LoggerImpl::forcedLog(LogLevel loglevel,
160
                      const log4cplus::tstring& message,
161
                      const char* file, 
162
                      int line)
163
0
{
164
0
    spi::InternalLoggingEvent & ev = internal::get_ptd ()->forced_log_ev;
165
0
    ev.setLoggingEvent (this->getName(), loglevel, message, file, line);
166
0
    callAppenders(ev);
167
0
}
168
169
170
void 
171
LoggerImpl::forcedLog(spi::InternalLoggingEvent const & ev)
172
0
{
173
0
    callAppenders(ev);
174
0
}
175
176
177
} } // namespace log4cplus { namespace spi {
178
} // end namespace dcmtk