Coverage Report

Created: 2025-12-08 07:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/log4cplus/include/log4cplus/spi/loggerimpl.h
Line
Count
Source
1
// -*- C++ -*-
2
// Module:  Log4CPLUS
3
// File:    loggerimpl.h
4
// Created: 6/2001
5
// Author:  Tad E. Smith
6
//
7
//
8
// Copyright 2001-2017 Tad E. Smith
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License");
11
// you may not use this file except in compliance with the License.
12
// You may obtain a copy of the License at
13
//
14
//     http://www.apache.org/licenses/LICENSE-2.0
15
//
16
// Unless required by applicable law or agreed to in writing, software
17
// distributed under the License is distributed on an "AS IS" BASIS,
18
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
// See the License for the specific language governing permissions and
20
// limitations under the License.
21
22
/** @file */
23
24
#ifndef LOG4CPLUS_SPI_LOGGER_HEADER_
25
#define LOG4CPLUS_SPI_LOGGER_HEADER_
26
27
#include <log4cplus/config.hxx>
28
29
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30
#pragma once
31
#endif
32
33
#include <log4cplus/tstring.h>
34
#include <log4cplus/helpers/appenderattachableimpl.h>
35
#include <log4cplus/helpers/pointer.h>
36
#include <log4cplus/spi/loggerfactory.h>
37
#include <memory>
38
#include <vector>
39
40
41
namespace log4cplus {
42
    class DefaultLoggerFactory;
43
44
    namespace spi {
45
46
        /**
47
         * This is the central class in the log4cplus package. One of the
48
         * distintive features of log4cplus are hierarchical loggers and their
49
         * evaluation.
50
         */
51
        class LOG4CPLUS_EXPORT LoggerImpl
52
            : public virtual log4cplus::helpers::SharedObject,
53
              public log4cplus::helpers::AppenderAttachableImpl
54
        {
55
        public:
56
            typedef helpers::SharedObjectPtr<LoggerImpl> SharedLoggerImplPtr;
57
58
          // Methods
59
60
            /**
61
             * Call the appenders in the hierrachy starting at
62
             * <code>this</code>.  If no appenders could be found, emit a
63
             * warning.
64
             *
65
             * This method calls all the appenders inherited from the
66
             * hierarchy circumventing any evaluation of whether to log or not
67
             * to log the particular log request.
68
             *
69
             * @param event The event to log.
70
             */
71
            virtual void callAppenders(const InternalLoggingEvent& event);
72
73
            /**
74
             * Close all attached appenders implementing the AppenderAttachable
75
             * interface.
76
             */
77
            virtual void closeNestedAppenders();
78
79
            /**
80
             * Check whether this logger is enabled for a given LogLevel passed
81
             * as parameter.
82
             *
83
             * @return boolean True if this logger is enabled for <code>ll</code>.
84
             */
85
            virtual bool isEnabledFor(LogLevel ll) const;
86
87
            /**
88
             * This generic form is intended to be used by wrappers.
89
             */
90
            virtual void log(LogLevel ll, const log4cplus::tstring& message,
91
                             const char* file=nullptr, int line=-1,
92
                             const char* function=nullptr);
93
94
            virtual void log(spi::InternalLoggingEvent const &);
95
96
            /**
97
             * Starting from this logger, search the logger hierarchy for a
98
             * "set" LogLevel and return it. Otherwise, return the LogLevel of the
99
             * root logger.
100
             *
101
             * The Logger class is designed so that this method executes as
102
             * quickly as possible.
103
             */
104
            virtual LogLevel getChainedLogLevel() const;
105
106
            /**
107
             * Returns the assigned LogLevel, if any, for this Logger.
108
             *
109
             * @return LogLevel - the assigned LogLevel.
110
             */
111
0
            LogLevel getLogLevel() const { return this->ll; }
112
113
            /**
114
             * Set the LogLevel of this Logger.
115
             */
116
2.79M
            void setLogLevel(LogLevel _ll) { this->ll = _ll; }
117
118
            /**
119
             * Return the the {@link Hierarchy} where this <code>Logger</code>
120
             * instance is attached.
121
             */
122
            virtual Hierarchy& getHierarchy() const;
123
124
            /**
125
             * Return the logger name.
126
             */
127
608k
            log4cplus::tstring const & getName() const { return name; }
128
129
            /**
130
             * Get the additivity flag for this Logger instance.
131
             */
132
            bool getAdditivity() const;
133
134
            /**
135
             * Set the additivity flag for this Logger instance.
136
             */
137
            void setAdditivity(bool additive);
138
139
            virtual ~LoggerImpl();
140
141
        protected:
142
          // Ctors
143
            /**
144
             * This constructor created a new <code>Logger</code> instance and
145
             * sets its name.
146
             *
147
             * It is intended to be used by sub-classes only. You should not
148
             * create loggers directly.
149
             *
150
             * @param name The name of the logger.
151
             * @param h Hierarchy
152
             */
153
            LoggerImpl(const log4cplus::tstring& name, Hierarchy& h);
154
155
156
          // Methods
157
            /**
158
             * This method creates a new logging event and logs the event
159
             * without further checks.
160
             */
161
            virtual void forcedLog(LogLevel ll,
162
                                   const log4cplus::tstring& message,
163
                                   const char* file,
164
                                   int line,
165
                                   const char* function);
166
167
            virtual void forcedLog(spi::InternalLoggingEvent const & ev);
168
169
170
          // Data
171
            /** The name of this logger */
172
            log4cplus::tstring name;
173
174
            /**
175
             * The assigned LogLevel of this logger.
176
             */
177
            LogLevel ll;
178
179
            /**
180
             * The parent of this logger. All loggers have at least one
181
             * ancestor which is the root logger.
182
             */
183
            SharedLoggerImplPtr parent;
184
185
            /**
186
             * Additivity is set to true by default, that is children inherit
187
             * the appenders of their ancestors by default. If this variable is
188
             * set to <code>false</code> then the appenders found in the
189
             * ancestors of this logger are not used. However, the children
190
             * of this logger will inherit its appenders, unless the children
191
             * have their additivity flag set to <code>false</code> too. See
192
             * the user manual for more details.
193
             */
194
            bool additive;
195
196
        private:
197
          // Data
198
            /** Loggers need to know what Hierarchy they are in. */
199
            Hierarchy& hierarchy;
200
201
          // Disallow copying of instances of this class
202
            LoggerImpl(const LoggerImpl&) = delete;
203
            LoggerImpl& operator=(const LoggerImpl&) = delete;
204
205
          // Friends
206
            friend class log4cplus::Logger;
207
            friend class log4cplus::DefaultLoggerFactory;
208
            friend class log4cplus::Hierarchy;
209
        };
210
211
        typedef LoggerImpl::SharedLoggerImplPtr SharedLoggerImplPtr;
212
213
    } // end namespace spi
214
} // end namespace log4cplus
215
216
#endif // LOG4CPLUS_SPI_LOGGER_HEADER_