logger.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: logger.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOG4CPLUS_LOGGERHEADER_
#define LOG4CPLUS_LOGGERHEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/loglevel.h>
#include <log4cplus/tstring.h>
#include <log4cplus/spi/appenderattachable.h>
#include <log4cplus/spi/loggerfactory.h>
#include <vector>
namespace log4cplus
{
// Forward declarations
class Appender;
class Hierarchy;
class HierarchyLocker;
class DefaultLoggerFactory;
namespace spi
{
class LoggerImpl;
}
typedef std::vector<Logger> LoggerList;
class LOG4CPLUS_EXPORT Logger
: public log4cplus::spi::AppenderAttachable
{
public:
// Static Methods
static bool exists(const log4cplus::tstring& name);
/*
* Returns all the currently defined loggers in the default
* hierarchy.
*
* The root logger is <em>not</em> included in the returned
* list.
*/
static LoggerList getCurrentLoggers();
static Hierarchy& getDefaultHierarchy();
static Logger getInstance(const log4cplus::tstring& name);
static Logger getInstance(const log4cplus::tstring& name,
spi::LoggerFactory& factory);
static Logger getRoot();
static void shutdown();
// Non-Static Methods
void assertion(bool assertionVal, const log4cplus::tstring& msg) const;
void closeNestedAppenders() const;
bool isEnabledFor(LogLevel ll) const;
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;
void log(spi::InternalLoggingEvent const &) const;
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;
void forcedLog(spi::InternalLoggingEvent const &) const;
void callAppenders(const spi::InternalLoggingEvent& event) const;
LogLevel getChainedLogLevel() const;
LogLevel getLogLevel() const;
void setLogLevel(LogLevel ll);
Hierarchy& getHierarchy() const;
log4cplus::tstring const & getName() const;
bool getAdditivity() const;
void setAdditivity(bool additive);
// AppenderAttachable Methods
virtual void addAppender(SharedAppenderPtr newAppender);
virtual SharedAppenderPtrList getAllAppenders();
virtual SharedAppenderPtr getAppender(const log4cplus::tstring& name);
virtual void removeAllAppenders();
virtual void removeAppender(SharedAppenderPtr appender);
virtual void removeAppender(const log4cplus::tstring& name);
Logger () LOG4CPLUS_NOEXCEPT;
Logger(const Logger& rhs) LOG4CPLUS_NOEXCEPT;
Logger& operator=(const Logger& rhs) LOG4CPLUS_NOEXCEPT;
Logger (Logger && rhs) LOG4CPLUS_NOEXCEPT;
Logger & operator = (Logger && rhs) LOG4CPLUS_NOEXCEPT;
virtual ~Logger();
void swap (Logger &) LOG4CPLUS_NOEXCEPT;
Logger getParent() const;
protected:
// Data
spi::LoggerImpl * value = nullptr;
private:
// Ctors
Logger(spi::LoggerImpl * ptr) LOG4CPLUS_NOEXCEPT;
// Friends
friend class log4cplus::spi::LoggerImpl;
friend class log4cplus::Hierarchy;
friend class log4cplus::HierarchyLocker;
friend class log4cplus::DefaultLoggerFactory;
};
class LOG4CPLUS_EXPORT DefaultLoggerFactory : public spi::LoggerFactory {
public:
Logger makeNewLoggerInstance(const log4cplus::tstring& name, Hierarchy& h);
protected:
virtual spi::LoggerImpl * makeNewLoggerImplInstance(
const log4cplus::tstring& name, Hierarchy& h);
};
} // end namespace log4cplus
#endif // LOG4CPLUS_LOGGERHEADER_
appenderattachable.h
log4cplus::Appender
Extend this class for implementing your own strategies for printing log statements.
Definition appender.h:139
log4cplus::DefaultLoggerFactory
This class is used to create the default implementation of the Logger class.
Definition logger.h:312
log4cplus::DefaultLoggerFactory::makeNewLoggerImplInstance
virtual spi::LoggerImpl * makeNewLoggerImplInstance(const log4cplus::tstring &name, Hierarchy &h)
log4cplus::DefaultLoggerFactory::makeNewLoggerInstance
Logger makeNewLoggerInstance(const log4cplus::tstring &name, Hierarchy &h)
Creates a new Logger object.
log4cplus::HierarchyLocker
This is used to lock a Hierarchy.
Definition hierarchylocker.h:47
log4cplus::Hierarchy
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.
Definition hierarchy.h:64
log4cplus::Logger
This is the central class in the log4cplus package.
Definition logger.h:71
log4cplus::Logger::getChainedLogLevel
LogLevel getChainedLogLevel() const
Starting from this logger, search the logger hierarchy for a "set" LogLevel and return it.
log4cplus::Logger::log
void log(spi::InternalLoggingEvent const &) const
log4cplus::Logger::getParent
Logger getParent() const
Used to retrieve the parent of this Logger in the Logger tree.
log4cplus::Logger::callAppenders
void callAppenders(const spi::InternalLoggingEvent &event) const
Call the appenders in the hierrachy starting at this.
log4cplus::Logger::isEnabledFor
bool isEnabledFor(LogLevel ll) const
Check whether this logger is enabled for a given LogLevel passed as parameter.
log4cplus::Logger::swap
void swap(Logger &) LOG4CPLUS_NOEXCEPT
log4cplus::Logger::setAdditivity
void setAdditivity(bool additive)
Set the additivity flag for this Logger instance.
log4cplus::Logger::getLogLevel
LogLevel getLogLevel() const
Returns the assigned LogLevel, if any, for this Logger.
log4cplus::Logger::log
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.
log4cplus::Logger::removeAppender
virtual void removeAppender(const log4cplus::tstring &name)
Remove the appender with the name passed as parameter from the list of appenders.
log4cplus::Logger::getRoot
static Logger getRoot()
Return the root of the default logger hierrachy.
log4cplus::Logger::getDefaultHierarchy
static Hierarchy & getDefaultHierarchy()
Return the default Hierarchy instance.
log4cplus::Logger::removeAllAppenders
virtual void removeAllAppenders()
Remove all previously added appenders.
log4cplus::Logger::exists
static bool exists(const log4cplus::tstring &name)
Returns true if the named logger exists (in the default hierarchy).
log4cplus::Logger::getCurrentLoggers
static LoggerList getCurrentLoggers()
log4cplus::Logger::Hierarchy
friend class log4cplus::Hierarchy
Definition logger.h:302
log4cplus::Logger::Logger
Logger() LOG4CPLUS_NOEXCEPT
log4cplus::Logger::forcedLog
void forcedLog(spi::InternalLoggingEvent const &) const
log4cplus::Logger::getInstance
static Logger getInstance(const log4cplus::tstring &name)
Retrieve a logger with name name.
log4cplus::Logger::getAppender
virtual SharedAppenderPtr getAppender(const log4cplus::tstring &name)
Get an appender by name.
log4cplus::Logger::LoggerImpl
friend class log4cplus::spi::LoggerImpl
Definition logger.h:301
log4cplus::Logger::getAdditivity
bool getAdditivity() const
Get the additivity flag for this Logger instance.
log4cplus::Logger::closeNestedAppenders
void closeNestedAppenders() const
Close all attached appenders implementing the AppenderAttachable interface.
log4cplus::Logger::addAppender
virtual void addAppender(SharedAppenderPtr newAppender)
Add an appender.
log4cplus::Logger::getHierarchy
Hierarchy & getHierarchy() const
Return the the Hierarchy where this Logger instance is attached.
log4cplus::Logger::shutdown
static void shutdown()
Calling this method will safely close and remove all appenders in all the loggers including root cont...
log4cplus::Logger::forcedLog
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::Logger::getName
log4cplus::tstring const & getName() const
Return the logger name.
log4cplus::Logger::HierarchyLocker
friend class log4cplus::HierarchyLocker
Definition logger.h:303
log4cplus::Logger::setLogLevel
void setLogLevel(LogLevel ll)
Set the LogLevel of this Logger.
log4cplus::Logger::removeAppender
virtual void removeAppender(SharedAppenderPtr appender)
Remove the appender passed as parameter from the list of appenders.
log4cplus::Logger::value
spi::LoggerImpl * value
This is a pointer to the implementation class.
Definition logger.h:285
log4cplus::Logger::getInstance
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...
log4cplus::Logger::getAllAppenders
virtual SharedAppenderPtrList getAllAppenders()
Get all previously added appenders as an Enumeration.
log4cplus::Logger::DefaultLoggerFactory
friend class log4cplus::DefaultLoggerFactory
Definition logger.h:304
log4cplus::Logger::assertion
void assertion(bool assertionVal, const log4cplus::tstring &msg) const
If assertionVal parameter is false, then logs msg with FATAL_LOG_LEVEL log level.
log4cplus::spi::AppenderAttachable
This Interface is for attaching Appenders to objects.
Definition appenderattachable.h:47
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
log4cplus::spi::LoggerFactory
Implement this interface to create new instances of Logger or a sub-class of Logger.
Definition loggerfactory.h:48
log4cplus::spi::LoggerImpl
This is the central class in the log4cplus package.
Definition loggerimpl.h:54
config.hxx
LOG4CPLUS_CALLER_FUNCTION
#define LOG4CPLUS_CALLER_FUNCTION()
Definition config.hxx:123
LOG4CPLUS_CALLER_FILE
#define LOG4CPLUS_CALLER_FILE()
Definition config.hxx:121
LOG4CPLUS_NOEXCEPT
#define LOG4CPLUS_NOEXCEPT
Definition config.hxx:101
LOG4CPLUS_CALLER_LINE
#define LOG4CPLUS_CALLER_LINE()
Definition config.hxx:122
loggerfactory.h
loglevel.h
This header defines the LogLevel type.
log4cplus::spi
Definition layout.h:62
log4cplus
Definition appender.h:46
log4cplus::SharedAppenderPtr
helpers::SharedObjectPtr< Appender > SharedAppenderPtr
This is a pointer to an Appender.
Definition appender.h:336
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::SharedAppenderPtrList
std::vector< log4cplus::SharedAppenderPtr > SharedAppenderPtrList
Definition appenderattachable.h:40
log4cplus::LoggerList
std::vector< Logger > LoggerList
This is a list of Loggers.
Definition logger.h:61
log4cplus::LogLevel
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition loglevel.h:48
tstring.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141