log4cplus  2.0.0
logger.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: logger.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 
25 #ifndef LOG4CPLUS_LOGGERHEADER_
26 #define LOG4CPLUS_LOGGERHEADER_
27 
28 #include <log4cplus/config.hxx>
29 
30 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
31 #pragma once
32 #endif
33 
34 #include <log4cplus/loglevel.h>
35 #include <log4cplus/tstring.h>
38 
39 #include <vector>
40 
41 
42 namespace log4cplus
43 {
44  // Forward declarations
45 
46  class Appender;
47  class Hierarchy;
48  class HierarchyLocker;
49  class DefaultLoggerFactory;
50 
51  namespace spi
52  {
53 
54  class LoggerImpl;
55 
56  }
57 
58 
61  typedef std::vector<Logger> LoggerList;
62 
63 
71  {
72  public:
73  // Static Methods
80  static bool exists(const log4cplus::tstring& name);
81 
82  /*
83  * Returns all the currently defined loggers in the default
84  * hierarchy.
85  *
86  * The root logger is <em>not</em> included in the returned
87  * list.
88  */
89  static LoggerList getCurrentLoggers();
90 
95 
107  static Logger getInstance(const log4cplus::tstring& name);
108 
121  static Logger getInstance(const log4cplus::tstring& name,
122  spi::LoggerFactory& factory);
123 
134  static Logger getRoot();
135 
150  static void shutdown();
151 
152  // Non-Static Methods
161  void assertion(bool assertionVal, const log4cplus::tstring& msg) const;
162 
167  void closeNestedAppenders() const;
168 
175  bool isEnabledFor(LogLevel ll) const;
176 
180  void log(LogLevel ll, const log4cplus::tstring& message,
181  const char* file = LOG4CPLUS_CALLER_FILE (),
182  int line = LOG4CPLUS_CALLER_LINE (),
183  const char* function = LOG4CPLUS_CALLER_FUNCTION ()) const;
184 
185  void log(spi::InternalLoggingEvent const &) const;
186 
191  void forcedLog(LogLevel ll, const log4cplus::tstring& message,
192  const char* file = LOG4CPLUS_CALLER_FILE (),
193  int line = LOG4CPLUS_CALLER_LINE (),
194  const char* function = LOG4CPLUS_CALLER_FUNCTION ()) const;
195 
196  void forcedLog(spi::InternalLoggingEvent const &) const;
197 
209  void callAppenders(const spi::InternalLoggingEvent& event) const;
210 
219  LogLevel getChainedLogLevel() const;
220 
226  LogLevel getLogLevel() const;
227 
231  void setLogLevel(LogLevel ll);
232 
237  Hierarchy& getHierarchy() const;
238 
242  log4cplus::tstring const & getName() const;
243 
247  bool getAdditivity() const;
248 
252  void setAdditivity(bool additive);
253 
254  // AppenderAttachable Methods
255  virtual void addAppender(SharedAppenderPtr newAppender);
256 
257  virtual SharedAppenderPtrList getAllAppenders();
258 
259  virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name);
260 
261  virtual void removeAllAppenders();
262 
263  virtual void removeAppender(SharedAppenderPtr appender);
264 
265  virtual void removeAppender(const log4cplus::tstring& name);
266 
268  Logger(const Logger& rhs) LOG4CPLUS_NOEXCEPT;
269  Logger& operator=(const Logger& rhs) LOG4CPLUS_NOEXCEPT;
271  Logger & operator = (Logger && rhs) LOG4CPLUS_NOEXCEPT;
272  virtual ~Logger();
273 
274  void swap (Logger &) LOG4CPLUS_NOEXCEPT;
275 
280  Logger getParent() const;
281 
282  protected:
283  // Data
285  spi::LoggerImpl * value = nullptr;
286 
287  private:
288  // Ctors
299 
300  // Friends
302  friend class log4cplus::Hierarchy;
305  };
306 
307 
313  public:
314  Logger makeNewLoggerInstance(const log4cplus::tstring& name, Hierarchy& h);
315  };
316 
317 
318 } // end namespace log4cplus
319 
320 
321 #endif // LOG4CPLUS_LOGGERHEADER_
The internal representation of logging events.
Definition: loggingevent.h:51
#define LOG4CPLUS_CALLER_FILE()
Definition: config.hxx:120
This is the central class in the log4cplus package.
Definition: loggerimpl.h:51
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
#define LOG4CPLUS_PRIVATE
Definition: config.hxx:53
This is the central class in the log4cplus package.
Definition: logger.h:69
This is used to lock a Hierarchy.
LOG4CPLUS_EXPORT Hierarchy & getDefaultHierarchy()
#define LOG4CPLUS_NOEXCEPT
Definition: config.hxx:101
std::vector< log4cplus::SharedAppenderPtr > SharedAppenderPtrList
std::basic_string< tchar > tstring
Definition: tstring.h:39
This class is used to create the default implementation of the Logger class.
Definition: logger.h:312
#define LOG4CPLUS_CALLER_FUNCTION()
Definition: config.hxx:122
This header defines the LogLevel type.
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition: hierarchy.h:63
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
#define LOG4CPLUS_CALLER_LINE()
Definition: config.hxx:121
Implement this interface to create new instances of Logger or a sub-class of Logger.
Definition: loggerfactory.h:46
std::vector< Logger > LoggerList
This is a list of Loggers.
Definition: logger.h:61
This Interface is for attaching Appenders to objects.