Go to the documentation of this file.00001 #ifndef logging_logging_proxy_H
00002 #define logging_logging_proxy_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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 #include "loggingThrottleAlarmInterface.h"
00057 #include <loggingCacheLogger.h>
00058
00059 #define DYNAMIC_LOG_LEVEL 1
00060 #define CDB_REFRESH_LOG_LEVEL 2
00061 #define ENV_LOG_LEVEL 3
00062 #define CDB_LOG_LEVEL 4
00063 #define DEFAULT_LOG_LEVEL 5
00064 #define NOT_DEFINED_LOG_LEVEL 6
00065
00067 #define ADD_DATA_VALUE_MAX 1024
00068
00069 #define ADD_DATA_NAME_MAX 256
00070
00073 #define LM_RUNTIME_CONTEXT 0x00000200
00074
00077 #define LM_SOURCE_INFO 0x00000100
00078
00080 #define LM_FULL_INFO (LM_RUNTIME_CONTEXT | LM_SOURCE_INFO)
00081
00123 class logging_EXPORT LoggingProxy : public ACE_Log_Msg_Callback
00124 {
00125
00126 public:
00129 void log(ACE_Log_Record &log_record);
00130
00135 static void LogEntryType(const ACE_TCHAR *szType);
00136
00140 static void Routine(const ACE_TCHAR *szRoutine);
00141
00145 static void File(const ACE_TCHAR *fileName);
00146
00150 static void Line(long lineNumber);
00151
00156 static void Flags(unsigned int uiFlags);
00157
00160 static void ThreadName(const ACE_TCHAR *szName);
00161
00163 static const ACE_TCHAR *ThreadName();
00164
00167 static void ProcessName(const ACE_TCHAR *szName);
00168
00170 static const ACE_TCHAR *ProcessName();
00171
00174 static void ResetAttributes();
00175
00177 static void AddAttribute(const ACE_TCHAR *szName, const ACE_TCHAR *szValue);
00178
00181 static void LogId(const ACE_TCHAR *szName);
00182
00185 static void URI(const ACE_TCHAR *szName);
00186
00190 static void StackId(const ACE_TCHAR *szId);
00191
00194 static const ACE_TCHAR *StackId();
00195
00197 static void PrivateFlags(int privateFlags);
00198
00200 static const int PrivateFlags();
00201
00202 static void LogLevelLocalType(int logLevelLocalType);
00203
00204 static const int LogLevelLocalType();
00205
00206 static void LogLevelRemoteType(int logLevelRemoteType);
00207
00208 static const int LogLevelRemoteType();
00209
00212 static void StackLevel(int nLevel);
00213
00215 static int StackLevel();
00216
00219 static void Context(const ACE_TCHAR *szName);
00220
00222 static const ACE_TCHAR *Context();
00223
00227 static void SourceObject(const ACE_TCHAR *soName);
00228
00231 static const ACE_TCHAR * SourceObject();
00232
00234 static void audience(const ACE_TCHAR *aud);
00235
00238 static const ACE_TCHAR * audience();
00239
00241 static void array(const ACE_TCHAR *aud);
00242
00245 static const ACE_TCHAR * array();
00246
00248 static void antenna(const ACE_TCHAR *aud);
00249
00252 static const ACE_TCHAR * antenna();
00253
00255 static void host(const ACE_TCHAR *aud);
00256
00259 static const ACE_TCHAR * host();
00260
00263 static void AddData(const ACE_TCHAR *szName, const ACE_TCHAR *szFormat, ...);
00264
00265 static ACE_TSS<LoggingTSSStorage> *getTSS();
00266
00267 public:
00268
00271 LoggingProxy(const unsigned long cacheSize,
00272 const unsigned long minCachePriority,
00273 const unsigned long maxCachePriority,
00274 Logging::AcsLogService_ptr centralizedLogger = Logging::AcsLogService::_nil(),
00275 CosNaming::NamingContext_ptr namingContext = CosNaming::NamingContext::_nil(),
00276 const unsigned int autoFlushTimeoutSec = 5,
00277 const int maxLogsPerSecond = -1);
00278
00280 ~LoggingProxy();
00281
00283 void setCentralizedLogger(Logging::AcsLogService_ptr centralizedLogger);
00284
00286 void setNamingContext(CosNaming::NamingContext_ptr namingContext)
00287 {
00288 m_namingContext = CosNaming::NamingContext::_duplicate(namingContext);
00289 }
00290
00292 void flush();
00293
00295 void setStdio(int stdio){ m_envStdioPriority = stdio; }
00296
00298
00299
00300
00302 static void init(LoggingProxy *loggingProxy);
00303
00305 static void done();
00306 static std::string BinToXml(ACSLoggingLog::LogBinaryRecord* record);
00307
00311 static unsigned long getPriority(ACE_Log_Record &log_record);
00312
00314 void logXML(const ACE_TCHAR *xml, bool cache=true);
00315
00317 static bool isInit()
00318 {
00319 return initialized;
00320 }
00321
00326 void setAlarmSender(LogThrottleAlarm* alarmSender);
00327
00329 static bool isInitThread();
00330
00332 int getCacheLogCount() const { if(!m_logBin) return m_cache.size(); else return m_bin_cache.size();}
00333
00334 protected:
00336 char *oldLog;
00337
00338 private:
00340 static void formatISO8601inUTC(const ACE_Time_Value ×tamp, ACE_TCHAR str[]);
00341
00343 void failedToSend();
00344
00346 void successfullySent();
00347
00349 bool reconnectToLogger();
00350
00352 void sendCache();
00353
00355 void sendCacheInternal();
00356
00359 bool sendRecord(CORBA::Any &record);
00360
00363 bool sendRecord(const Logging::XmlLogRecordSeq &reclist);
00364
00365 void sendXmlLogs(ACE_Log_Record &log_record, const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00366 void sendBinLogs(ACE_Log_Record &log_record, const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00367
00377 ACE_CString getTempFileNameAndCreateMissingDirs(const ACE_TCHAR * timestamp);
00378
00380 int makeDirectory(const ACE_TCHAR * dirname, const ACE_TCHAR * timestamp);
00381
00383 int createMissingDirectories(const ACE_TCHAR * dirname, const ACE_TCHAR * timestamp);
00384
00386 int logNonCentralizedLoggerCache(CacheLogger * logger, const ACE_CString & key, const ACE_TCHAR * timestamp);
00387
00389 ACE_CString getParentFolder(const ACE_TCHAR * filename);
00396 unsigned long m_cacheSize;
00397
00404 unsigned long m_minCachePriority;
00405
00411 unsigned long m_maxCachePriority;
00412
00416 unsigned int m_autoFlushTimeoutSec;
00417
00422 int m_maxLogsPerSecond;
00423 logging::LogThrottle *logThrottle;
00424
00430 LogThrottleAlarm* logThrottleAlarm_p;
00431
00436 Logging::AcsLogService_var m_logger;
00437 bool m_noLogger;
00438
00443 CosNaming::NamingContext_var m_namingContext;
00444
00447 int m_failureCount;
00448
00450 static int m_failureLimit;
00451
00454 ACE_Time_Value m_disconnectionTime;
00455
00457 static int m_minReconnectionTime;
00458
00462 typedef std::deque<ACE_CString> LogDeque;
00463 LogDeque m_cache;
00464
00465
00466 typedef std::deque<ACSLoggingLog::LogBinaryRecord *> LogBinDeque;
00467
00468 LogBinDeque m_bin_cache;
00469
00470
00471
00473 bool m_cacheDisabled;
00474
00478 static char m_process[256];
00479
00483 ACE_Recursive_Thread_Mutex m_mutex;
00484
00485 bool m_logBin;
00486
00490 static ACE_TSS<LoggingTSSStorage> * tss;
00491 static int instances;
00492
00494 ACE_CString m_filename;
00495
00497 bool m_alreadyInformed;
00498
00502 int m_envStdioPriority;
00503 int m_envCentralizePriority;
00504
00509 ACE_CString m_syslog;
00510
00512 static bool initialized;
00513
00514 static ACE_CString sourceObject_m;
00515
00518 static unsigned int setClrCount_m;
00519
00521 ACE_SYNCH_MUTEX m_doWorkMutex;
00522
00524 ACE_SYNCH_CONDITION m_doWorkCond;
00525
00527 volatile bool m_sendingPending;
00528
00530 virtual int svc();
00531
00533 static void* worker(void*);
00534
00536 volatile bool m_threadCreated;
00538
00540 ACE_Barrier m_threadShutdown;
00541 volatile bool m_shutdown;
00542 };
00543
00544 #endif