hierarchy.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: hierarchy.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_HIERARCHY_HEADER_
#define LOG4CPLUS_HIERARCHY_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/logger.h>
#include <log4cplus/thread/syncprims.h>
#include <map>
#include <memory>
#include <vector>
namespace log4cplus {
// Forward Declarations
class HierarchyLocker;
class LOG4CPLUS_EXPORT Hierarchy
{
public:
// DISABLE_OFF should be set to a value lower than all possible
// priorities.
static const LogLevel DISABLE_OFF;
static const LogLevel DISABLE_OVERRIDE;
// Ctors
Hierarchy();
// Dtor
virtual ~Hierarchy();
// Methods
virtual void clear();
virtual bool exists(const log4cplus::tstring& name);
virtual void disable(const log4cplus::tstring& loglevelStr);
virtual void disable(LogLevel ll);
virtual void disableAll();
virtual void disableDebug();
virtual void disableInfo();
virtual void enableAll();
virtual Logger getInstance(const log4cplus::tstring& name);
virtual Logger getInstance(const log4cplus::tstring& name, spi::LoggerFactory& factory);
virtual LoggerList getCurrentLoggers();
virtual bool isDisabled(LogLevel level);
virtual Logger getRoot() const;
virtual void resetConfiguration();
virtual void setLoggerFactory(std::unique_ptr<spi::LoggerFactory> factory);
virtual spi::LoggerFactory* getLoggerFactory();
virtual void shutdown();
private:
// Types
typedef std::vector<Logger> ProvisionNode;
typedef std::map<log4cplus::tstring, ProvisionNode> ProvisionNodeMap;
typedef std::map<log4cplus::tstring, Logger> LoggerMap;
// Methods
LOG4CPLUS_PRIVATE
Logger getInstanceImpl(const log4cplus::tstring& name,
spi::LoggerFactory& factory);
LOG4CPLUS_PRIVATE
void initializeLoggerList(LoggerList& list) const;
LOG4CPLUS_PRIVATE void updateParents(Logger const & logger);
LOG4CPLUS_PRIVATE void updateChildren(ProvisionNode& pn,
Logger const & logger);
// Data
thread::Mutex hashtable_mutex;
std::unique_ptr<spi::LoggerFactory> defaultFactory;
ProvisionNodeMap provisionNodes;
LoggerMap loggerPtrs;
Logger root;
int disableValue;
bool emittedNoAppenderWarning;
// Disallow copying of instances of this class
Hierarchy(const Hierarchy&);
Hierarchy& operator=(const Hierarchy&);
// Friends
friend class log4cplus::spi::LoggerImpl;
friend class log4cplus::HierarchyLocker;
};
LOG4CPLUS_EXPORT Hierarchy & getDefaultHierarchy ();
} // end namespace log4cplus
#endif // LOG4CPLUS_HIERARCHY_HEADER_
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::Hierarchy::getCurrentLoggers
virtual LoggerList getCurrentLoggers()
Returns all the currently defined loggers in this hierarchy.
log4cplus::Hierarchy::clear
virtual void clear()
This call will clear all logger definitions from the internal hashtable.
log4cplus::Hierarchy::getLoggerFactory
virtual spi::LoggerFactory * getLoggerFactory()
Returns the default LoggerFactory instance.
log4cplus::Hierarchy::getInstance
virtual Logger getInstance(const log4cplus::tstring &name, spi::LoggerFactory &factory)
Return a new logger instance named as the first parameter using factory.
log4cplus::Hierarchy::setLoggerFactory
virtual void setLoggerFactory(std::unique_ptr< spi::LoggerFactory > factory)
Set the default LoggerFactory instance.
log4cplus::Hierarchy::disableDebug
virtual void disableDebug()
Disable all Debug logging requests regardless of logger.
log4cplus::Hierarchy::disableInfo
virtual void disableInfo()
Disable all Info logging requests regardless of logger.
log4cplus::Hierarchy::shutdown
virtual void shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all loggers including the roo...
log4cplus::Hierarchy::disable
virtual void disable(LogLevel ll)
Disable all logging requests of LogLevel equal to or below the ll parameter p, for all loggers in thi...
log4cplus::Hierarchy::getRoot
virtual Logger getRoot() const
Get the root of this hierarchy.
log4cplus::Hierarchy::resetConfiguration
virtual void resetConfiguration()
Reset all values contained in this hierarchy instance to their default.
log4cplus::Hierarchy::DISABLE_OFF
static const LogLevel DISABLE_OFF
Definition hierarchy.h:68
log4cplus::Hierarchy::enableAll
virtual void enableAll()
Undoes the effect of calling any of disable, disableAll, disableDebug and disableInfo methods.
log4cplus::Hierarchy::isDisabled
virtual bool isDisabled(LogLevel level)
Is the LogLevel specified by level enabled?
log4cplus::Hierarchy::disableAll
virtual void disableAll()
Disable all logging requests regardless of logger and LogLevel.
log4cplus::Hierarchy::disable
virtual void disable(const log4cplus::tstring &loglevelStr)
Similar to disable(LogLevel) except that the LogLevel argument is given as a log4cplus::tstring.
log4cplus::Hierarchy::Hierarchy
Hierarchy()
Create a new Logger hierarchy.
log4cplus::Hierarchy::getInstance
virtual Logger getInstance(const log4cplus::tstring &name)
Return a new logger instance named as the first parameter using the default factory.
log4cplus::Hierarchy::~Hierarchy
virtual ~Hierarchy()
log4cplus::Hierarchy::DISABLE_OVERRIDE
static const LogLevel DISABLE_OVERRIDE
Definition hierarchy.h:69
log4cplus::Hierarchy::exists
virtual bool exists(const log4cplus::tstring &name)
Returns true if the named logger exists (in the default hierarchy).
log4cplus::Logger
This is the central class in the log4cplus package.
Definition logger.h:71
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
log4cplus::thread::Mutex
Definition syncprims.h:83
config.hxx
LOG4CPLUS_PRIVATE
#define LOG4CPLUS_PRIVATE
Definition config.hxx:53
logger.h
This header defines the Logger class and the logging macros.
log4cplus
Definition appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::getDefaultHierarchy
LOG4CPLUS_EXPORT Hierarchy & getDefaultHierarchy()
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
syncprims.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141