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/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
00293
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 ×tamp, 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
00421 LogBinDeque m_bin_cache;
00422
00423
00424
00426 bool m_cacheDisabled;
00427
00431 static char 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
00493 ACE_Barrier m_threadShutdown;
00494 volatile bool m_shutdown;
00495 };
00496
00497 #endif