log4cplus  2.1.0
loggerimpl.h
Go to the documentation of this file.
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 
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>
37 #include <memory>
38 #include <vector>
39 
40 
41 namespace log4cplus {
42  class DefaultLoggerFactory;
43 
44  namespace spi {
45 
52  : public virtual log4cplus::helpers::SharedObject,
54  {
55  public:
57 
58  // Methods
59 
71  virtual void callAppenders(const InternalLoggingEvent& event);
72 
77  virtual void closeNestedAppenders();
78 
85  virtual bool isEnabledFor(LogLevel ll) const;
86 
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 
104  virtual LogLevel getChainedLogLevel() const;
105 
111  LogLevel getLogLevel() const { return this->ll; }
112 
116  void setLogLevel(LogLevel _ll) { this->ll = _ll; }
117 
122  virtual Hierarchy& getHierarchy() const;
123 
127  log4cplus::tstring const & getName() const { return name; }
128 
132  bool getAdditivity() const;
133 
137  void setAdditivity(bool additive);
138 
139  virtual ~LoggerImpl();
140 
141  protected:
142  // Ctors
154 
155 
156  // Methods
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
173 
178 
184 
194  bool additive;
195 
196  private:
197  // Data
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;
208  friend class log4cplus::Hierarchy;
209  };
210 
212 
213  } // end namespace spi
214 } // end namespace log4cplus
215 
216 #endif // LOG4CPLUS_SPI_LOGGER_HEADER_
This class is used to create the default implementation of the Logger class.
Definition: logger.h:312
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:64
This is the central class in the log4cplus package.
Definition: logger.h:71
This Interface is for attaching Appenders to objects.
The internal representation of logging events.
Definition: loggingevent.h:51
This is the central class in the log4cplus package.
Definition: loggerimpl.h:54
virtual Hierarchy & getHierarchy() const
Return the the Hierarchy where this Logger instance is attached.
virtual void closeNestedAppenders()
Close all attached appenders implementing the AppenderAttachable interface.
LogLevel getLogLevel() const
Returns the assigned LogLevel, if any, for this Logger.
Definition: loggerimpl.h:111
virtual LogLevel getChainedLogLevel() const
Starting from this logger, search the logger hierarchy for a "set" LogLevel and return it.
void setAdditivity(bool additive)
Set the additivity flag for this Logger instance.
bool getAdditivity() const
Get the additivity flag for this Logger instance.
log4cplus::tstring const & getName() const
Return the logger name.
Definition: loggerimpl.h:127
helpers::SharedObjectPtr< LoggerImpl > SharedLoggerImplPtr
Definition: loggerimpl.h:56
LoggerImpl(const log4cplus::tstring &name, Hierarchy &h)
This constructor created a new Logger instance and sets its name.
virtual void forcedLog(spi::InternalLoggingEvent const &ev)
LogLevel ll
The assigned LogLevel of this logger.
Definition: loggerimpl.h:177
SharedLoggerImplPtr parent
The parent of this logger.
Definition: loggerimpl.h:183
virtual bool isEnabledFor(LogLevel ll) const
Check whether this logger is enabled for a given LogLevel passed as parameter.
virtual void callAppenders(const InternalLoggingEvent &event)
Call the appenders in the hierrachy starting at this.
virtual void log(LogLevel ll, const log4cplus::tstring &message, const char *file=nullptr, int line=-1, const char *function=nullptr)
This generic form is intended to be used by wrappers.
bool additive
Additivity is set to true by default, that is children inherit the appenders of their ancestors by de...
Definition: loggerimpl.h:194
virtual void log(spi::InternalLoggingEvent const &)
void setLogLevel(LogLevel _ll)
Set the LogLevel of this Logger.
Definition: loggerimpl.h:116
log4cplus::tstring name
The name of this logger.
Definition: loggerimpl.h:172
virtual void forcedLog(LogLevel ll, const log4cplus::tstring &message, const char *file, int line, const char *function)
This method creates a new logging event and logs the event without further checks.
LoggerImpl::SharedLoggerImplPtr SharedLoggerImplPtr
Definition: loggerimpl.h:211
std::basic_string< tchar > tstring
Definition: tstring.h:39
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
#define LOG4CPLUS_EXPORT
Definition: win32.h:141