diff options
-rw-r--r-- | project2/basics/loggers/consoleLog.cpp | 6 | ||||
-rw-r--r-- | project2/basics/loggers/syslogLog.cpp | 6 | ||||
-rw-r--r-- | project2/common/logger.cpp | 13 | ||||
-rw-r--r-- | project2/common/logger.h | 49 | ||||
-rw-r--r-- | project2/common/loggerFactory.cpp | 14 | ||||
-rw-r--r-- | project2/common/loggerFactory.h | 38 | ||||
-rw-r--r-- | project2/common/loggerFactory.impl.h | 43 | ||||
-rw-r--r-- | project2/files/fileLog.cpp | 6 | ||||
-rw-r--r-- | project2/ut/butf_logger.cpp | 6 |
9 files changed, 111 insertions, 70 deletions
diff --git a/project2/basics/loggers/consoleLog.cpp b/project2/basics/loggers/consoleLog.cpp index de45245..a88e6b2 100644 --- a/project2/basics/loggers/consoleLog.cpp +++ b/project2/basics/loggers/consoleLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include <loggerFactory.impl.h> +#include <options.h> /// Logger that writes to the console class ConsoleLogDriver : public LogDriverBase { @@ -25,5 +25,5 @@ END_OPTIONS(ConsoleLogDriver); int ConsoleLogDriver::level; -DECLARE_LOGGER_LOADER("console", ConsoleLogDriver); +DECLARE_LOGGER("console", ConsoleLogDriver); diff --git a/project2/basics/loggers/syslogLog.cpp b/project2/basics/loggers/syslogLog.cpp index 8e58326..cb026c6 100644 --- a/project2/basics/loggers/syslogLog.cpp +++ b/project2/basics/loggers/syslogLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include <loggerFactory.impl.h> +#include <options.h> /// Logger that writes to syslog class SyslogLogDriver : public LogDriverBase { @@ -35,5 +35,5 @@ END_OPTIONS(SyslogLogDriver); int SyslogLogDriver::level; std::string SyslogLogDriver::ident; -DECLARE_LOGGER_LOADER("syslog", SyslogLogDriver); +DECLARE_LOGGER("syslog", SyslogLogDriver); diff --git a/project2/common/logger.cpp b/project2/common/logger.cpp index 64df516..f21bd40 100644 --- a/project2/common/logger.cpp +++ b/project2/common/logger.cpp @@ -2,7 +2,7 @@ #define SYSLOG_NAMES 1 // Enables the definition of names in syslog.h #include "logger.h" -#include <factory.impl.h> +#include "loggerFactory.h" Log Logger::log; @@ -94,14 +94,3 @@ Logger::operator->() const return &log; } -LogDriverBase::LogDriverBase() -{ -} - -LogDriverBase::~LogDriverBase() -{ -} - -template class AdHoc::Factory<LogDriverBase>; -INSTANTIATEPLUGINOF(LogDriverFactory) - diff --git a/project2/common/logger.h b/project2/common/logger.h index 9b7d868..8d8b6de 100644 --- a/project2/common/logger.h +++ b/project2/common/logger.h @@ -3,29 +3,15 @@ #include <map> #include <stdarg.h> -#include <stdlib.h> #include <syslog.h> // Pulled in for easy client lookups of LOG_* priorties #include <boost/intrusive_ptr.hpp> -#include <boost/format.hpp> +#include <boost/format/format_fwd.hpp> #include "intrusivePtrBase.h" -#include <factory.h> #include <buffer.h> #include "lifeCycle.h" -/// Base class for classes providing a logging facility -class LogDriverBase : public virtual IntrusivePtrBase { - public: - LogDriverBase(); - virtual ~LogDriverBase(); - - virtual void message(int priority, const char * msg) const = 0; -}; - -class LogDriverFactory : public AdHoc::Factory<LogDriverBase> { - public: - virtual int loggerLevel() const = 0; -}; - +class LogDriverBase; +class LogDriverFactory; class Log { public: typedef boost::intrusive_ptr<LogDriverBase> LogDriverBasePtr; @@ -68,34 +54,5 @@ class Logger { static Log log; }; -template<typename LoggerType> -class LogDriverFactoryImpl : public LogDriverFactory, public LifeCycle { - public: - LogDriverFactoryImpl() : - level(LoggerType::level) - { - } - virtual void onConfigLoad() override { - Logger()->setLoggerAt(this, level); - if (level == -1) { - instance.reset(); - } - } - inline LoggerType * create() const { - if (!instance) { - instance = new LoggerType(); - } - return instance.get(); - } - int loggerLevel() const { - return level; - } - const int & level; - private: - mutable boost::intrusive_ptr<LoggerType> instance; -}; -#define DECLARE_LOGGER_LOADER(N, T) \ - NAMEDPLUGIN(N, LogDriverFactoryImpl<T>, LogDriverFactory) - #endif diff --git a/project2/common/loggerFactory.cpp b/project2/common/loggerFactory.cpp new file mode 100644 index 0000000..b1d75d1 --- /dev/null +++ b/project2/common/loggerFactory.cpp @@ -0,0 +1,14 @@ +#include "loggerFactory.h" +#include <factory.impl.h> + +LogDriverBase::LogDriverBase() +{ +} + +LogDriverBase::~LogDriverBase() +{ +} + +template class AdHoc::Factory<LogDriverBase>; +INSTANTIATEPLUGINOF(LogDriverFactory) + diff --git a/project2/common/loggerFactory.h b/project2/common/loggerFactory.h new file mode 100644 index 0000000..056f5e3 --- /dev/null +++ b/project2/common/loggerFactory.h @@ -0,0 +1,38 @@ +#ifndef LOGGERFACTORY_H +#define LOGGERFACTORY_H + +#include <factory.h> +#include "lifeCycle.h" +#include "intrusivePtrBase.h" +#include "logger.h" + +/// Base class for classes providing a logging facility +class LogDriverBase : public virtual IntrusivePtrBase { + public: + LogDriverBase(); + virtual ~LogDriverBase(); + + virtual void message(int priority, const char * msg) const = 0; +}; + +class LogDriverFactory : public AdHoc::Factory<LogDriverBase> { + public: + virtual int loggerLevel() const = 0; +}; + +template<typename LoggerType> +class LogDriverFactoryImpl : public LogDriverFactory, public LifeCycle { + public: + LogDriverFactoryImpl(); + + virtual void onConfigLoad() override; + inline LoggerType * create() const override; + int loggerLevel() const override; + + const int & level; + private: + mutable boost::intrusive_ptr<LoggerType> instance; +}; + +#endif + diff --git a/project2/common/loggerFactory.impl.h b/project2/common/loggerFactory.impl.h new file mode 100644 index 0000000..61711fd --- /dev/null +++ b/project2/common/loggerFactory.impl.h @@ -0,0 +1,43 @@ +#ifndef LOGGERFACTORY_IMPL_H +#define LOGGERFACTORY_IMPL_H + +#include "loggerFactory.h" + +template<typename T> +LogDriverFactoryImpl<T>::LogDriverFactoryImpl() : + level(T::level) +{ +} + +template<typename T> +void +LogDriverFactoryImpl<T>::onConfigLoad() +{ + Logger()->setLoggerAt(this, level); + if (level == -1) { + instance.reset(); + } +} + +template<typename T> +T * +LogDriverFactoryImpl<T>::create() const +{ + if (!instance) { + instance = new T(); + } + return instance.get(); +} + +template<typename T> +int +LogDriverFactoryImpl<T>::loggerLevel() const +{ + return level; +} + +#define DECLARE_LOGGER(N, T) \ + NAMEDPLUGIN(N, LogDriverFactoryImpl<T>, LogDriverFactory) + +#endif + diff --git a/project2/files/fileLog.cpp b/project2/files/fileLog.cpp index 078e00b..8a56f6d 100644 --- a/project2/files/fileLog.cpp +++ b/project2/files/fileLog.cpp @@ -1,5 +1,5 @@ -#include "logger.h" -#include "options.h" +#include <loggerFactory.impl.h> +#include <options.h> /// Logger that writes to a file class FileLogDriver : public LogDriverBase { @@ -47,5 +47,5 @@ int FileLogDriver::level; std::string FileLogDriver::path; std::string FileLogDriver::openmode; -DECLARE_LOGGER_LOADER("file", FileLogDriver); +DECLARE_LOGGER("file", FileLogDriver); diff --git a/project2/ut/butf_logger.cpp b/project2/ut/butf_logger.cpp index c5f45b4..42afd41 100644 --- a/project2/ut/butf_logger.cpp +++ b/project2/ut/butf_logger.cpp @@ -1,6 +1,6 @@ #include <boost/test/unit_test_log.hpp> -#include "logger.h" -#include "options.h" +#include <loggerFactory.impl.h> +#include <options.h> /// Logger that writes Boost Unit Test Framework messages class BoostUTFLogDriver : public LogDriverBase { @@ -17,5 +17,5 @@ class BoostUTFLogDriver : public LogDriverBase { int BoostUTFLogDriver::level = LOG_DEBUG; -DECLARE_LOGGER_LOADER("boostutf", BoostUTFLogDriver); +DECLARE_LOGGER("boostutf", BoostUTFLogDriver); |