• 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.41 2010/09/05 20:42:28 javarias 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/orbsvcs/CosNamingC.h>
00049 
00050 #include <ace/Synch.h>
00051 #include "logging_idlC.h"
00052 
00053 #include "loggingExport.h"
00054 #include "loggingLoggingTSSStorage.h"
00055 #include "loggingLogThrottle.h"
00056 
00057 #define DYNAMIC_LOG_LEVEL 1
00058 #define CDB_REFRESH_LOG_LEVEL 2
00059 #define ENV_LOG_LEVEL 3
00060 #define CDB_LOG_LEVEL 4
00061 #define DEFAULT_LOG_LEVEL 5
00062 #define NOT_DEFINED_LOG_LEVEL 6
00063 
00065 #define ADD_DATA_VALUE_MAX 1024
00066 
00067 #define ADD_DATA_NAME_MAX 256
00068 
00071 #define LM_RUNTIME_CONTEXT 0x00000200
00072 
00075 #define LM_SOURCE_INFO 0x00000100
00076 
00078 #define LM_FULL_INFO (LM_RUNTIME_CONTEXT | LM_SOURCE_INFO)
00079 
00121 class logging_EXPORT LoggingProxy : public ACE_Log_Msg_Callback
00122 {
00123 
00124   public:
00127     void log(ACE_Log_Record &log_record);
00128 
00133     static void LogEntryType(const ACE_TCHAR *szType);
00134 
00138     static void Routine(const ACE_TCHAR *szRoutine);
00139 
00143     static void File(const ACE_TCHAR *fileName);
00144 
00148     static void Line(long lineNumber);
00149 
00154     static void Flags(unsigned int uiFlags);
00155 
00158     static void ThreadName(const ACE_TCHAR *szName);
00159 
00161     static const ACE_TCHAR *ThreadName();
00162 
00165     static void ProcessName(const ACE_TCHAR *szName);
00166 
00168     static const ACE_TCHAR *ProcessName();
00169 
00172     static void ResetAttributes();
00173 
00175     static void AddAttribute(const ACE_TCHAR *szName, const ACE_TCHAR *szValue);
00176 
00179     static void LogId(const ACE_TCHAR *szName);
00180 
00183     static void URI(const ACE_TCHAR *szName);
00184 
00188     static void StackId(const ACE_TCHAR *szId);
00189 
00192     static const ACE_TCHAR *StackId();
00193 
00195     static void PrivateFlags(int privateFlags);
00196 
00198     static const int PrivateFlags();
00199 
00200     static void LogLevelLocalType(int logLevelLocalType);
00201 
00202     static const int LogLevelLocalType();
00203 
00204     static void LogLevelRemoteType(int logLevelRemoteType);
00205 
00206     static const int LogLevelRemoteType();
00207 
00210     static void StackLevel(int nLevel);
00211 
00213     static int StackLevel();
00214 
00217     static void Context(const ACE_TCHAR *szName);
00218 
00220     static const ACE_TCHAR *Context();
00221 
00225     static void SourceObject(const ACE_TCHAR *soName);
00226 
00229     static const ACE_TCHAR * SourceObject();
00230 
00232     static void audience(const ACE_TCHAR *aud);
00233 
00236     static const ACE_TCHAR * audience();
00237 
00239     static void array(const ACE_TCHAR *aud);
00240 
00243     static const ACE_TCHAR * array();
00244 
00246     static void antenna(const ACE_TCHAR *aud);
00247 
00250     static const ACE_TCHAR * antenna();
00251 
00253     static void host(const ACE_TCHAR *aud);
00254 
00257     static const ACE_TCHAR * host();
00258 
00261     static void AddData(const ACE_TCHAR *szName, const ACE_TCHAR *szFormat, ...);
00262 
00263     static ACE_TSS<LoggingTSSStorage> *getTSS();
00264 
00265   public:
00266 
00269     LoggingProxy(const unsigned long cacheSize,
00270                  const unsigned long minCachePriority,
00271                  const unsigned long maxCachePriority,
00272                  Logging::AcsLogService_ptr centralizedLogger = Logging::AcsLogService::_nil(),
00273                  CosNaming::NamingContext_ptr namingContext = CosNaming::NamingContext::_nil(),
00274                  const unsigned int autoFlushTimeoutSec = 5,
00275                  const int maxLogsPerSecond = -1);
00276 
00278     ~LoggingProxy();
00279 
00281     void setCentralizedLogger(Logging::AcsLogService_ptr centralizedLogger);
00282 
00284     void setNamingContext(CosNaming::NamingContext_ptr namingContext)
00285         {
00286             m_namingContext = CosNaming::NamingContext::_duplicate(namingContext);
00287         }
00288 
00290     void flush();
00291 
00293     void setStdio(int stdio){ m_envStdioPriority = stdio; }
00294 
00296     //static ACE_TCHAR* m_LogEntryTypeName[];
00297     //static ACSLoggingLog::LogType m_LogBinEntryTypeName[];
00298 
00300     static void init(LoggingProxy *loggingProxy);
00301 
00303     static void done();
00304     static std::string BinToXml(ACSLoggingLog::LogBinaryRecord* record);
00305 
00309     static unsigned long getPriority(ACE_Log_Record &log_record);
00310 
00312     void logXML(const ACE_TCHAR *xml, bool cache=true);
00313 
00315     static bool isInit()
00316         {
00317             return initialized;
00318         }
00319 
00321     static bool isInitThread();
00322 
00324     int getCacheLogCount() const { if(!m_logBin) return m_cache.size(); else return m_bin_cache.size();}
00325 
00326   protected:
00328          char *oldLog;
00329 
00330   private:
00332     static void formatISO8601inUTC(const ACE_Time_Value &timestamp, ACE_TCHAR str[]);
00333 
00335     void failedToSend();
00336 
00338     void successfullySent();
00339 
00341     bool reconnectToLogger();
00342 
00344     void sendCache();
00345 
00347     void sendCacheInternal();
00348 
00351     bool sendRecord(CORBA::Any &record);
00352     
00355     bool sendRecord(const Logging::XmlLogRecordSeq &reclist);
00356 
00357     void sendXmlLogs(ACE_Log_Record &log_record,  const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00358     void sendBinLogs(ACE_Log_Record &log_record,  const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00359 
00366     unsigned long m_cacheSize;
00367 
00374     unsigned long m_minCachePriority;
00375 
00381     unsigned long m_maxCachePriority;
00382 
00386     unsigned int m_autoFlushTimeoutSec;
00387 
00392     int m_maxLogsPerSecond;
00393     logging::LogThrottle *logThrottle;
00398     Logging::AcsLogService_var m_logger;
00399     bool m_noLogger;
00400 
00405     CosNaming::NamingContext_var m_namingContext;
00406 
00409     int m_failureCount;
00410 
00412     static int m_failureLimit;
00413 
00416     ACE_Time_Value m_disconnectionTime;
00417 
00419     static int m_minReconnectionTime;
00420 
00424     typedef std::deque<ACE_CString> LogDeque;
00425     LogDeque m_cache;
00426 
00427 
00428     typedef std::deque<ACSLoggingLog::LogBinaryRecord *> LogBinDeque;
00429     //typedef std::deque<ACSLoggingLog::LogBinaryRecord > LogBinDeque;
00430     LogBinDeque m_bin_cache;
00431 
00432    // ACSLoggingLog::LogBinaryRecord * m_binaryRecord;
00433 
00435     bool m_cacheDisabled;
00436 
00440     static char /*ACE_CString*/ m_process[256];
00441 
00445     ACE_Recursive_Thread_Mutex m_mutex;
00446 
00447     bool m_logBin;
00448 
00452     static ACE_TSS<LoggingTSSStorage> * tss;
00453     static int instances;
00454 
00456     ACE_CString m_filename;
00457 
00459     bool m_alreadyInformed;
00460 
00464     int m_envStdioPriority;
00465     int m_envCentralizePriority;
00466 
00471     ACE_CString m_syslog;
00472 
00474     static bool initialized;
00475 
00476     static ACE_CString sourceObject_m;
00477 
00480     static unsigned int setClrCount_m;
00481 
00483   ACE_SYNCH_MUTEX m_doWorkMutex;
00484 
00486   ACE_SYNCH_CONDITION m_doWorkCond;
00487 
00489   volatile bool m_sendingPending;
00490 
00492   virtual int svc();
00493 
00495   static void* worker(void*);
00496 
00498   volatile bool m_threadCreated;
00500   //ACE_Barrier m_threadStart;
00502   ACE_Barrier m_threadShutdown;
00503   volatile bool m_shutdown;
00504 };
00505 
00506 #endif 

Generated on Thu Jan 12 2012 23:13:51 for ACS-10.0 C++ API by  doxygen 1.7.0