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

loggingLoggingProxy.h

Go to the documentation of this file.
00001 #ifndef logging_logging_proxy_H
00002 #define logging_logging_proxy_H
00003 
00004 /*******************************************************************************
00005  *    ALMA - Atacama Large Millimiter Array
00006  *    (c) European Southern Observatory, 2002
00007  *    Copyright by ESO (in the framework of the ALMA collaboration)
00008  *    and Cosylab 2002, All rights reserved
00009  *
00010  *    This library is free software; you can redistribute it and/or
00011  *    modify it under the terms of the GNU Lesser General Public
00012  *    License as published by the Free Software Foundation; either
00013  *    version 2.1 of the License, or (at your option) any later version.
00014  *
00015  *    This library is distributed in the hope that it will be useful,
00016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  *    Lesser General Public License for more details.
00019  *
00020  *    You should have received a copy of the GNU Lesser General Public
00021  *    License along with this library; if not, write to the Free Software
00022  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00023  *
00024  * "@(#) $Id: loggingLoggingProxy.h,v 1.39 2010/03/15 10:31:03 bjeram Exp $"
00025  *
00026  * who       when        what
00027  * --------  ----------  ----------------------------------------------
00028  * bjeram    2003-03-06  added #include <ace/Log_Record.h> (needed by ACE/TAO x.3)
00029  * bjeram    2002-04-10  added setStdio
00030  * msekoran  2001-12-17  added CL failure detection, logging to syslog, file, ...
00031  * bjeram    2001-09-13  added logXML(...) method
00032  * bjeram    2001-08     added ACS_LOG_TIME macro
00033  * msekoran  2001-07-12  renamed m_data and m_flags variables in LoggingTSSStorage class
00034  * msekoran  2001-06-08  Implementation according new specifications
00035  * almamgr   2000-12-03  Removed static and changed to char* from filename and oldfilename
00036  * almamgr   2000-12-03  created
00037  */
00038 
00039 #ifndef __cplusplus
00040 #error This is a C++ include file and cannot be used from plain C
00041 #endif
00042 
00043 #include <ace/Log_Msg_Callback.h>
00044 
00045 #include <deque>
00046 
00047 #include <orbsvcs/orbsvcs/DsLogAdminC.h>
00048 #include <orbsvcs/CosNamingC.h>
00049 
00050 #include <ace/Synch.h>
00051 #include "logging_idlC.h"
00052 
00053 #include "loggingExport.h"
00054 #include "loggingLoggingTSSStorage.h"
00055 
00056 #define DYNAMIC_LOG_LEVEL 1
00057 #define CDB_REFRESH_LOG_LEVEL 2
00058 #define ENV_LOG_LEVEL 3
00059 #define CDB_LOG_LEVEL 4
00060 #define DEFAULT_LOG_LEVEL 5
00061 #define NOT_DEFINED_LOG_LEVEL 6
00062 
00064 #define ADD_DATA_VALUE_MAX 1024
00065 
00066 #define ADD_DATA_NAME_MAX 256
00067 
00070 #define LM_RUNTIME_CONTEXT 0x00000200
00071 
00074 #define LM_SOURCE_INFO 0x00000100
00075 
00077 #define LM_FULL_INFO (LM_RUNTIME_CONTEXT | LM_SOURCE_INFO)
00078 
00120 class logging_EXPORT LoggingProxy : public ACE_Log_Msg_Callback
00121 {
00122 
00123   public:
00126     void log(ACE_Log_Record &log_record);
00127 
00132     static void LogEntryType(const ACE_TCHAR *szType);
00133 
00137     static void Routine(const ACE_TCHAR *szRoutine);
00138 
00142     static void File(const ACE_TCHAR *fileName);
00143 
00147     static void Line(long lineNumber);
00148 
00153     static void Flags(unsigned int uiFlags);
00154 
00157     static void ThreadName(const ACE_TCHAR *szName);
00158 
00160     static const ACE_TCHAR *ThreadName();
00161 
00164     static void ProcessName(const ACE_TCHAR *szName);
00165 
00167     static const ACE_TCHAR *ProcessName();
00168 
00171     static void ResetAttributes();
00172 
00174     static void AddAttribute(const ACE_TCHAR *szName, const ACE_TCHAR *szValue);
00175 
00178     static void LogId(const ACE_TCHAR *szName);
00179 
00182     static void URI(const ACE_TCHAR *szName);
00183 
00187     static void StackId(const ACE_TCHAR *szId);
00188 
00191     static const ACE_TCHAR *StackId();
00192 
00194     static void PrivateFlags(int privateFlags);
00195 
00197     static const int PrivateFlags();
00198 
00199     static void LogLevelLocalType(int logLevelLocalType);
00200 
00201     static const int LogLevelLocalType();
00202 
00203     static void LogLevelRemoteType(int logLevelRemoteType);
00204 
00205     static const int LogLevelRemoteType();
00206 
00209     static void StackLevel(int nLevel);
00210 
00212     static int StackLevel();
00213 
00216     static void Context(const ACE_TCHAR *szName);
00217 
00219     static const ACE_TCHAR *Context();
00220 
00224     static void SourceObject(const ACE_TCHAR *soName);
00225 
00228     static const ACE_TCHAR * SourceObject();
00229 
00231     static void audience(const ACE_TCHAR *aud);
00232 
00235     static const ACE_TCHAR * audience();
00236 
00238     static void array(const ACE_TCHAR *aud);
00239 
00242     static const ACE_TCHAR * array();
00243 
00245     static void antenna(const ACE_TCHAR *aud);
00246 
00249     static const ACE_TCHAR * antenna();
00250 
00252     static void host(const ACE_TCHAR *aud);
00253 
00256     static const ACE_TCHAR * host();
00257 
00260     static void AddData(const ACE_TCHAR *szName, const ACE_TCHAR *szFormat, ...);
00261 
00262   public:
00263 
00266     LoggingProxy(const unsigned long cacheSize,
00267                  const unsigned long minCachePriority,
00268                  const unsigned long maxCachePriority,
00269                  Logging::AcsLogService_ptr centralizedLogger = Logging::AcsLogService::_nil(),
00270                  CosNaming::NamingContext_ptr namingContext = CosNaming::NamingContext::_nil(),
00271                  const unsigned int autoFlushTimeoutSec = 5);
00272 
00274     ~LoggingProxy();
00275 
00277     void setCentralizedLogger(Logging::AcsLogService_ptr centralizedLogger);
00278 
00280     void setNamingContext(CosNaming::NamingContext_ptr namingContext)
00281         {
00282             m_namingContext = CosNaming::NamingContext::_duplicate(namingContext);
00283         }
00284 
00286     void flush();
00287 
00289     void setStdio(int stdio){ m_envStdioPriority = stdio; }
00290 
00292     //static ACE_TCHAR* m_LogEntryTypeName[];
00293     //static ACSLoggingLog::LogType m_LogBinEntryTypeName[];
00294 
00296     static void init(LoggingProxy *loggingProxy);
00297 
00299     static void done();
00300     static std::string BinToXml(ACSLoggingLog::LogBinaryRecord* record);
00301 
00305     static unsigned long getPriority(ACE_Log_Record &log_record);
00306 
00308     void logXML(const ACE_TCHAR *xml, bool cache=true);
00309 
00311     static bool isInit()
00312         {
00313             return initialized;
00314         }
00315 
00317     static bool isInitThread();
00318 
00320     int getCacheLogCount() const { if(!m_logBin) return m_cache.size(); else return m_bin_cache.size();}
00321 
00322   protected:
00324          char *oldLog;
00325 
00326   private:
00327 
00329     static void formatISO8601inUTC(const ACE_Time_Value &timestamp, ACE_TCHAR str[]);
00330 
00332     void failedToSend();
00333 
00335     void successfullySent();
00336 
00338     bool reconnectToLogger();
00339 
00341     void sendCache();
00342 
00344     void sendCacheInternal();
00345 
00348     bool sendRecord(CORBA::Any &record);
00349     
00352     bool sendRecord(const Logging::XmlLogRecordSeq &reclist);
00353 
00354     void sendXmlLogs(ACE_Log_Record &log_record,  const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00355     void sendBinLogs(ACE_Log_Record &log_record,  const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00356 
00363     unsigned long m_cacheSize;
00364 
00371     unsigned long m_minCachePriority;
00372 
00378     unsigned long m_maxCachePriority;
00379 
00383     unsigned int m_autoFlushTimeoutSec;
00384 
00389     Logging::AcsLogService_var m_logger;
00390     bool m_noLogger;
00391 
00396     CosNaming::NamingContext_var m_namingContext;
00397 
00400     int m_failureCount;
00401 
00403     static int m_failureLimit;
00404 
00407     ACE_Time_Value m_disconnectionTime;
00408 
00410     static int m_minReconnectionTime;
00411 
00415     typedef std::deque<ACE_CString> LogDeque;
00416     LogDeque m_cache;
00417 
00418 
00419     typedef std::deque<ACSLoggingLog::LogBinaryRecord *> LogBinDeque;
00420     //typedef std::deque<ACSLoggingLog::LogBinaryRecord > LogBinDeque;
00421     LogBinDeque m_bin_cache;
00422 
00423    // ACSLoggingLog::LogBinaryRecord * m_binaryRecord;
00424 
00426     bool m_cacheDisabled;
00427 
00431     static char /*ACE_CString*/ m_process[256];
00432 
00436     ACE_Recursive_Thread_Mutex m_mutex;
00437 
00438     bool m_logBin;
00439 
00443     static ACE_TSS<LoggingTSSStorage> * tss;
00444     static int instances;
00445 
00447     ACE_CString m_filename;
00448 
00450     bool m_alreadyInformed;
00451 
00455     int m_envStdioPriority;
00456     int m_envCentralizePriority;
00457 
00462     ACE_CString m_syslog;
00463 
00465     static bool initialized;
00466 
00467     static ACE_CString sourceObject_m;
00468 
00471     static unsigned int setClrCount_m;
00472 
00474   ACE_SYNCH_MUTEX m_doWorkMutex;
00475 
00477   ACE_SYNCH_CONDITION m_doWorkCond;
00478 
00480   volatile bool m_sendingPending;
00481 
00483   virtual int svc();
00484 
00486   static void* worker(void*);
00487 
00489   volatile bool m_threadCreated;
00491   //ACE_Barrier m_threadStart;
00493   ACE_Barrier m_threadShutdown;
00494   volatile bool m_shutdown;
00495 };
00496 
00497 #endif 

Generated on Thu Jul 8 2010 19:47:47 for ACS-9.0 C++ API by  doxygen 1.7.0