log4cpp 1.1
|
00001 /* 00002 * Appender.hh 00003 * 00004 * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved. 00005 * Copyright 2000, Bastiaan Bakker. All rights reserved. 00006 * 00007 * See the COPYING file for the terms of usage and distribution. 00008 */ 00009 00010 #ifndef _LOG4CPP_APPENDER_HH 00011 #define _LOG4CPP_APPENDER_HH 00012 00013 #include <log4cpp/Portability.hh> 00014 #include <string> 00015 #include <map> 00016 #include <set> 00017 #include <vector> 00018 #include <stdarg.h> 00019 #include <sys/types.h> 00020 #include <sys/stat.h> 00021 #include <fcntl.h> 00022 #include <log4cpp/Priority.hh> 00023 #include <log4cpp/Layout.hh> 00024 #include <log4cpp/LoggingEvent.hh> 00025 #include <log4cpp/threading/Threading.hh> 00026 00027 namespace log4cpp { 00028 class LOG4CPP_EXPORT Filter; 00029 00034 class LOG4CPP_EXPORT Appender { 00035 friend class Category; 00036 public: 00037 00044 static Appender* getAppender(const std::string& name); 00045 00050 static bool reopenAll(); 00051 00056 static void closeAll(); 00057 00058 protected: 00064 Appender(const std::string& name); 00065 00066 public: 00070 virtual ~Appender(); 00071 00076 virtual void doAppend(const LoggingEvent& event) = 0; 00077 00083 virtual bool reopen() = 0; 00084 00089 virtual void close() = 0; 00090 00096 virtual bool requiresLayout() const = 0; 00097 00102 virtual void setLayout(Layout* layout) = 0; 00103 00108 inline const std::string& getName() const { return _name; }; 00109 00116 virtual void setThreshold(Priority::Value priority) = 0; 00117 00122 virtual Priority::Value getThreshold() = 0; 00123 00127 virtual void setFilter(Filter* filter) = 0; 00128 00133 virtual Filter* getFilter() = 0; 00134 00135 private: 00136 typedef std::map<std::string, Appender*> AppenderMap; 00137 00138 static AppenderMap& _getAllAppenders(); 00139 static void _deleteAllAppenders(); 00140 static void _deleteAllAppendersWOLock(std::vector<Appender*> &appenders); 00141 static void _addAppender(Appender* appender); 00142 static void _removeAppender(Appender* appender); 00143 00144 const std::string _name; 00145 00146 public: 00147 class AppenderMapStorage { 00148 public: 00149 Appender::AppenderMap* _allAppenders; // single shared instance, nifty-counter defensed 00150 threading::Mutex _appenderMapMutex; // mutex protecting map from multiple thread access 00151 00152 AppenderMapStorage(); 00153 ~AppenderMapStorage(); 00154 }; 00155 class AppenderMapStorageInitializer { 00156 public: 00157 AppenderMapStorageInitializer(); 00158 ~AppenderMapStorageInitializer(); 00159 }; 00160 private: 00161 static AppenderMapStorage &_appenderMapStorageInstance; 00162 }; 00163 00164 static Appender::AppenderMapStorageInitializer appenderMapStorageInitializer; // static initializer for every translation unit 00165 typedef std::set<Appender *> AppenderSet; 00166 00167 } 00168 00169 #endif // _LOG4CPP_APPENDER_HH