log4cplus 2.0.8
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
42namespace 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 */
90
95
108
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
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
197
209 void callAppenders(const spi::InternalLoggingEvent& event) const;
210
220
227
232
238
243
247 bool getAdditivity() const;
248
252 void setAdditivity(bool additive);
253
254 // AppenderAttachable Methods
255 virtual void addAppender(SharedAppenderPtr newAppender);
256
258
260
261 virtual void removeAllAppenders();
262
263 virtual void removeAppender(SharedAppenderPtr appender);
264
265 virtual void removeAppender(const log4cplus::tstring& name);
266
269 Logger& operator=(const Logger& rhs) LOG4CPLUS_NOEXCEPT;
271 Logger & operator = (Logger && rhs) LOG4CPLUS_NOEXCEPT;
272 virtual ~Logger();
273
275
280 Logger getParent() const;
281
282 protected:
283 // Data
285 spi::LoggerImpl * value = nullptr;
286
287 private:
288 // Ctors
298 Logger(spi::LoggerImpl * ptr) LOG4CPLUS_NOEXCEPT;
299
300 // Friends
301 friend class log4cplus::spi::LoggerImpl;
302 friend class log4cplus::Hierarchy;
305 };
306
307
312 class LOG4CPLUS_EXPORT DefaultLoggerFactory : public spi::LoggerFactory {
313 public:
315
316 protected:
318 const log4cplus::tstring& name, Hierarchy& h);
319 };
320
321
322} // end namespace log4cplus
323
324
325#endif // LOG4CPLUS_LOGGERHEADER_
This class is used to create the default implementation of the Logger class.
Definition logger.h:312
virtual spi::LoggerImpl * makeNewLoggerImplInstance(const log4cplus::tstring &name, Hierarchy &h)
Logger makeNewLoggerInstance(const log4cplus::tstring &name, Hierarchy &h)
Creates a new Logger object.
This is used to lock a Hierarchy.
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
LogLevel getChainedLogLevel() const
Starting from this logger, search the logger hierarchy for a "set" LogLevel and return it.
void log(spi::InternalLoggingEvent const &) const
void callAppenders(const spi::InternalLoggingEvent &event) const
Call the appenders in the hierrachy starting at this.
bool isEnabledFor(LogLevel ll) const
Check whether this logger is enabled for a given LogLevel passed as parameter.
void setAdditivity(bool additive)
Set the additivity flag for this Logger instance.
LogLevel getLogLevel() const
Returns the assigned LogLevel, if any, for this Logger.
void log(LogLevel ll, const log4cplus::tstring &message, const char *file=LOG4CPLUS_CALLER_FILE(), int line=LOG4CPLUS_CALLER_LINE(), const char *function=LOG4CPLUS_CALLER_FUNCTION()) const
This generic form is intended to be used by wrappers.
virtual void removeAppender(const log4cplus::tstring &name)
Remove the appender with the name passed as parameter from the list of appenders.
static Logger getRoot()
Return the root of the default logger hierrachy.
static Hierarchy & getDefaultHierarchy()
Return the default Hierarchy instance.
virtual void removeAllAppenders()
Remove all previously added appenders.
static bool exists(const log4cplus::tstring &name)
Returns true if the named logger exists (in the default hierarchy).
static LoggerList getCurrentLoggers()
Logger() LOG4CPLUS_NOEXCEPT
void forcedLog(spi::InternalLoggingEvent const &) const
static Logger getInstance(const log4cplus::tstring &name)
Retrieve a logger with name name.
virtual SharedAppenderPtr getAppender(const log4cplus::tstring &name)
Get an appender by name.
bool getAdditivity() const
Get the additivity flag for this Logger instance.
void closeNestedAppenders() const
Close all attached appenders implementing the AppenderAttachable interface.
virtual void addAppender(SharedAppenderPtr newAppender)
Add an appender.
Hierarchy & getHierarchy() const
Return the the Hierarchy where this Logger instance is attached.
static void shutdown()
Calling this method will safely close and remove all appenders in all the loggers including root cont...
void forcedLog(LogLevel ll, const log4cplus::tstring &message, const char *file=LOG4CPLUS_CALLER_FILE(), int line=LOG4CPLUS_CALLER_LINE(), const char *function=LOG4CPLUS_CALLER_FUNCTION()) const
This method creates a new logging event and logs the event without further checks.
log4cplus::tstring const & getName() const
Return the logger name.
void setLogLevel(LogLevel ll)
Set the LogLevel of this Logger.
virtual void removeAppender(SharedAppenderPtr appender)
Remove the appender passed as parameter from the list of appenders.
static Logger getInstance(const log4cplus::tstring &name, spi::LoggerFactory &factory)
Like getInstance() except that the type of logger instantiated depends on the type returned by the sp...
virtual SharedAppenderPtrList getAllAppenders()
Get all previously added appenders as an Enumeration.
void assertion(bool assertionVal, const log4cplus::tstring &msg) const
If assertionVal parameter is false, then logs msg with FATAL_LOG_LEVEL log level.
This Interface is for attaching Appenders to objects.
The internal representation of logging events.
Implement this interface to create new instances of Logger or a sub-class of Logger.
This is the central class in the log4cplus package.
Definition loggerimpl.h:54
#define LOG4CPLUS_CALLER_FUNCTION()
Definition config.hxx:123
#define LOG4CPLUS_CALLER_FILE()
Definition config.hxx:121
#define LOG4CPLUS_NOEXCEPT
Definition config.hxx:101
#define LOG4CPLUS_CALLER_LINE()
Definition config.hxx:122
This header defines the LogLevel type.
std::basic_string< tchar > tstring
Definition tstring.h:39
std::vector< log4cplus::SharedAppenderPtr > SharedAppenderPtrList
std::vector< Logger > LoggerList
This is a list of Loggers.
Definition logger.h:61
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