• Classes
  • Modules
  • Namespaces
  • Files
  • Related Pages
  • File List
  • File Members

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.27 2012/02/29 12:50:09 tstaig 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 <ace/Singleton.h>
00043 #include <ace/Thread_Manager.h>   // it is here just that we can print ID of the thread !!!
00044 
00045 namespace Logging 
00046 {
00047 
00048     //------------------------------------------------------------------------------
00055     class loggingBase_EXPORT Logger : public virtual BaseLog
00056     {
00057       public:
00058         //----------------------------------------------------
00060 #ifndef MAKE_VXWORKS
00061         typedef Loki::SmartPtr<Logger, 
00062 #ifdef __CYGWIN__
00063                                Logging::RefCounted,
00064 #else
00065                                Loki::RefCountedMTAdj<Loki::ObjectLevelLockable>::RefCountedMT,
00066 #endif
00067                                Loki::AllowConversion,
00068                                Loki::NoCheck,
00069                                Loki::DefaultSPStorage> LoggerSmartPtr;
00070 #else
00071         typedef Loki::SmartPtr<Logger, 
00072                                RefCountedMT,
00073                                Loki::AllowConversion,
00074                                Loki::NoCheck,
00075                                Loki::DefaultSPStorage> LoggerSmartPtr;
00076 #endif
00077 
00078         // Loggers list
00079         typedef std::list<Logger*> LoggerList;
00080         
00081         // Implementation of external function that configures logger 
00082         typedef void (*ConfigureLoggerFunction)(const std::string& loggerName);
00083         
00090         virtual LoggerSmartPtr
00091         getLogger(const std::string &loggerName) = 0;
00092 
00093     int getLocalLevel();
00094     int getRemoteLevel();
00095     int
00096     getLocalLevel(const std::string &loggerName);
00097     int
00098     getRemoteLevel(const std::string &loggerName);
00103         static LoggerSmartPtr getAnonymousLogger();
00104 
00110         static void     setAnonymousLogger(LoggerSmartPtr anonyLogger);
00111         
00117         static LoggerSmartPtr getStaticLogger();
00118 
00124         static void     setStaticLogger(LoggerSmartPtr anonyLogger);
00125         
00131         static LoggerSmartPtr getGlobalLogger();
00132         
00138         static void setGlobalLogger(LoggerSmartPtr globalLogger);
00139         
00145         virtual std::string     getName() const;
00146         
00150         virtual ~Logger();
00151         
00160         virtual void
00161         addHandler(Handler::HandlerSmartPtr newHandler_p);
00162         
00169         virtual bool 
00170         removeHandler(const std::string &handlerName);
00171         
00173         virtual void
00174         log(const LogRecord &lr);
00175 
00179         virtual void
00180         log(Priority priority,
00181             const std::string &message,
00182             const std::string &file,
00183             unsigned long line,
00184             const std::string &method)
00185             {
00186                 BaseLog::log(priority, message, file, line, method);
00187             }
00188 
00197         virtual void
00198         log(Priority priority,
00199             const std::string &message)
00200             {
00201                 log(priority,
00202                     message,
00203                     FIELD_UNAVAILABLE,
00204                     0UL,
00205                     FIELD_UNAVAILABLE);
00206             }
00207         
00213         virtual void 
00214         setName(const std::string &newName);
00215 
00221         virtual void
00222         setLevels(Priority remotePriority,Priority localPriority, int type);
00223         
00230         virtual void
00231         setLevels(const std::string &loggerName, Priority remotePriority,Priority localPriority, int type);
00232     
00233     void setLevelsLoggerHandlers(Priority remotePriority,Priority localPriority, int type);
00239         virtual bool
00240         exists(const std::string &loggerName);
00241 
00246         virtual std::list<std::string>
00247         getLoggerNames();
00248 
00252         static void
00253         setConfigureLoggerFunction(ConfigureLoggerFunction configureLoggerFunction) {configureLoggerFunction_m=configureLoggerFunction;}
00254         
00258         static void
00259         configureLogger(const std::string& loggerName)
00260         {
00261                 if (configureLoggerFunction_m)
00262                         (*configureLoggerFunction_m)(loggerName);
00263         }
00264         
00265       protected:
00266         //----------------------------------------------------
00273         Logger(const std::string &loggerName);
00274 
00282         virtual void
00283         acquireHandlerMutex() {}
00284 
00292         virtual void 
00293         releaseHandlerMutex() {}
00294         
00295       private:
00296         //----------------------------------------------------
00298         std::string loggerName_m;
00299         
00304         std::list<Handler::HandlerSmartPtr> handlers_m;
00305 
00306         class Logger_ptr{
00307                 public:
00308                         Logger_ptr(){globalLogger_m=(Logger *)0;anonymousLogger_m=(Logger *)0;staticLogger_m=(Logger *)0;}
00309                         ~Logger_ptr(){globalLogger_m=(Logger *)0;anonymousLogger_m=(Logger *)0;staticLogger_m=(Logger *)0;}
00314                         LoggerSmartPtr globalLogger_m;
00319                         LoggerSmartPtr anonymousLogger_m;
00320                         
00324                         LoggerSmartPtr staticLogger_m;
00325                         
00329                         LoggerList loggers_m;
00330         };
00331 
00336         static ACE_Thread_Mutex loggersMutex_m;
00337 
00341         static ConfigureLoggerFunction configureLoggerFunction_m;
00342 
00343     };
00344     //------------------------------------------------------------------------------
00345 };
00346 
00347 #endif 

Generated on Mon May 4 2015 08:27:43 for ACS-2015.4 C++ API by  doxygen 1.7.0