Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

loggingLogger.h

Go to the documentation of this file.
00001 #ifndef logging_logger_H 00002 #define logging_logger_H 00003 /******************************************************************************* 00004 * ALMA - Atacama Large Millimiter Array 00005 * (c) Associated Universities Inc., 2005 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * "@(#) $Id: loggingLogger.h,v 1.25 2008/01/23 09:45:08 bjeram Exp $" 00022 * 00023 * who when what 00024 * -------- -------- ---------------------------------------------- 00025 * dfugate 2005-03-09 created 00026 */ 00027 00032 #ifndef __cplusplus 00033 #error This is a C++ include file and cannot be used from plain C 00034 #endif 00035 00036 #include <string> 00037 #include <lokiSmartPtr.h> 00038 #include <list> 00039 #include "loggingBaseLog.h" 00040 #include "loggingHandler.h" 00041 #include <ace/Thread_Mutex.h> 00042 #include <Singleton.h> 00043 #include <Thread_Manager.h> // it is here just that we can print ID of the thread !!! 00044 00045 namespace Logging 00046 { 00047 00048 //------------------------------------------------------------------------------ 00055 class Logger : public virtual BaseLog 00056 { 00057 public: 00058 //---------------------------------------------------- 00060 #ifndef MAKE_VXWORKS 00061 typedef Loki::SmartPtr<Logger, 00062 Loki::RefCountedMTAdj<Loki::ObjectLevelLockable>::RefCountedMT, 00063 Loki::AllowConversion, 00064 Loki::NoCheck, 00065 Loki::DefaultSPStorage> LoggerSmartPtr; 00066 #else 00067 typedef Loki::SmartPtr<Logger, 00068 RefCountedMT, 00069 Loki::AllowConversion, 00070 Loki::NoCheck, 00071 Loki::DefaultSPStorage> LoggerSmartPtr; 00072 #endif 00073 00074 // Loggers list 00075 typedef std::list<Logger*> LoggerList; 00076 00077 // Implementation of external function that configures logger 00078 typedef void (*ConfigureLoggerFunction)(const std::string& loggerName); 00079 00086 virtual LoggerSmartPtr 00087 getLogger(const std::string &loggerName) = 0; 00088 00089 int getLocalLevel(); 00090 int getRemoteLevel(); 00091 int 00092 getLocalLevel(const std::string &loggerName); 00093 int 00094 getRemoteLevel(const std::string &loggerName); 00099 static LoggerSmartPtr getAnonymousLogger(); 00100 00106 static void setAnonymousLogger(LoggerSmartPtr anonyLogger); 00107 00113 static LoggerSmartPtr getStaticLogger(); 00114 00120 static void setStaticLogger(LoggerSmartPtr anonyLogger); 00121 00127 static LoggerSmartPtr getGlobalLogger(); 00128 00134 static void setGlobalLogger(LoggerSmartPtr globalLogger); 00135 00141 virtual std::string getName() const; 00142 00146 virtual ~Logger(); 00147 00156 virtual void 00157 addHandler(Handler::HandlerSmartPtr newHandler_p); 00158 00165 virtual bool 00166 removeHandler(const std::string &handlerName); 00167 00169 virtual void 00170 log(const LogRecord &lr); 00171 00175 virtual void 00176 log(Priority priority, 00177 const std::string &message, 00178 const std::string &file, 00179 unsigned long line, 00180 const std::string &method) 00181 { 00182 BaseLog::log(priority, message, file, line, method); 00183 } 00184 00193 virtual void 00194 log(Priority priority, 00195 const std::string &message) 00196 { 00197 log(priority, 00198 message, 00199 FIELD_UNAVAILABLE, 00200 0UL, 00201 FIELD_UNAVAILABLE); 00202 } 00203 00209 virtual void 00210 setName(const std::string &newName); 00211 00217 virtual void 00218 setLevels(Priority remotePriority,Priority localPriority, int type); 00219 00226 virtual void 00227 setLevels(const std::string &loggerName, Priority remotePriority,Priority localPriority, int type); 00228 00229 void setLevelsLoggerHandlers(Priority remotePriority,Priority localPriority, int type); 00235 virtual bool 00236 exists(const std::string &loggerName); 00237 00242 virtual std::list<std::string> 00243 getLoggerNames(); 00244 00248 static void 00249 setConfigureLoggerFunction(ConfigureLoggerFunction configureLoggerFunction) {configureLoggerFunction_m=configureLoggerFunction;} 00250 00254 static void 00255 configureLogger(const std::string& loggerName) 00256 { 00257 if (configureLoggerFunction_m) 00258 (*configureLoggerFunction_m)(loggerName); 00259 } 00260 00261 protected: 00262 //---------------------------------------------------- 00269 Logger(const std::string &loggerName); 00270 00278 virtual void 00279 acquireHandlerMutex() {} 00280 00288 virtual void 00289 releaseHandlerMutex() {} 00290 00291 private: 00292 //---------------------------------------------------- 00294 std::string loggerName_m; 00295 00300 std::list<Handler::HandlerSmartPtr> handlers_m; 00301 00302 class Logger_ptr{ 00303 public: 00304 Logger_ptr(){globalLogger_m=(Logger *)0;anonymousLogger_m=(Logger *)0;staticLogger_m=(Logger *)0;} 00305 ~Logger_ptr(){globalLogger_m=(Logger *)0;anonymousLogger_m=(Logger *)0;staticLogger_m=(Logger *)0;} 00310 LoggerSmartPtr globalLogger_m; 00315 LoggerSmartPtr anonymousLogger_m; 00316 00320 LoggerSmartPtr staticLogger_m; 00321 00325 LoggerList loggers_m; 00326 }; 00327 00332 static ACE_Thread_Mutex loggersMutex_m; 00333 00337 static ConfigureLoggerFunction configureLoggerFunction_m; 00338 00339 }; 00340 //------------------------------------------------------------------------------ 00341 }; 00342 00343 #endif

Generated on Thu Apr 30 02:30:51 2009 for ACS C++ API by doxygen 1.3.8