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 256
00065
00068 #define LM_RUNTIME_CONTEXT 0x00000200
00069
00072 #define LM_SOURCE_INFO 0x00000100
00073
00075 #define LM_FULL_INFO (LM_RUNTIME_CONTEXT | LM_SOURCE_INFO)
00076
00118 class logging_EXPORT LoggingProxy : public ACE_Log_Msg_Callback
00119 {
00120
00121 public:
00124 void log(ACE_Log_Record &log_record);
00125
00130 static void LogEntryType(const ACE_TCHAR *szType);
00131
00135 static void Routine(const ACE_TCHAR *szRoutine);
00136
00140 static void File(const ACE_TCHAR *fileName);
00141
00145 static void Line(long lineNumber);
00146
00151 static void Flags(unsigned int uiFlags);
00152
00155 static void ThreadName(const ACE_TCHAR *szName);
00156
00158 static const ACE_TCHAR *ThreadName();
00159
00162 static void ProcessName(const ACE_TCHAR *szName);
00163
00165 static const ACE_TCHAR *ProcessName();
00166
00169 static void ResetAttributes();
00170
00172 static void AddAttribute(const ACE_TCHAR *szName, const ACE_TCHAR *szValue);
00173
00176 static void LogId(const ACE_TCHAR *szName);
00177
00180 static void URI(const ACE_TCHAR *szName);
00181
00185 static void StackId(const ACE_TCHAR *szId);
00186
00189 static const ACE_TCHAR *StackId();
00190
00192 static void PrivateFlags(int privateFlags);
00193
00195 static const int PrivateFlags();
00196
00197 static void LogLevelLocalType(int logLevelLocalType);
00198
00199 static const int LogLevelLocalType();
00200
00201 static void LogLevelRemoteType(int logLevelRemoteType);
00202
00203 static const int LogLevelRemoteType();
00204
00207 static void StackLevel(int nLevel);
00208
00210 static int StackLevel();
00211
00214 static void Context(const ACE_TCHAR *szName);
00215
00217 static const ACE_TCHAR *Context();
00218
00222 static void SourceObject(const ACE_TCHAR *soName);
00223
00226 static const ACE_TCHAR * SourceObject();
00227
00229 static void audience(const ACE_TCHAR *aud);
00230
00233 static const ACE_TCHAR * audience();
00234
00236 static void array(const ACE_TCHAR *aud);
00237
00240 static const ACE_TCHAR * array();
00241
00243 static void antenna(const ACE_TCHAR *aud);
00244
00247 static const ACE_TCHAR * antenna();
00248
00250 static void host(const ACE_TCHAR *aud);
00251
00254 static const ACE_TCHAR * host();
00255
00258 static void AddData(const ACE_TCHAR *szName, const ACE_TCHAR *szFormat, ...);
00259
00260 public:
00261
00264 LoggingProxy(const unsigned long cacheSize,
00265 const unsigned long minCachePriority,
00266 const unsigned long maxCachePriority,
00267 Logging::AcsLogService_ptr centralizedLogger = Logging::AcsLogService::_nil(),
00268 CosNaming::NamingContext_ptr namingContext = CosNaming::NamingContext::_nil(),
00269 const unsigned int autoFlushTimeoutSec = 5);
00270
00272 ~LoggingProxy();
00273
00275 void setCentralizedLogger(Logging::AcsLogService_ptr centralizedLogger);
00276
00278 void setNamingContext(CosNaming::NamingContext_ptr namingContext)
00279 {
00280 m_namingContext = CosNaming::NamingContext::_duplicate(namingContext);
00281 }
00282
00284 void flush();
00285
00287 void setStdio(int stdio){ m_envStdioPriority = stdio; }
00288
00290
00291
00292
00294 static void init(LoggingProxy *loggingProxy);
00295
00297 static void done();
00298 static std::string BinToXml(ACSLoggingLog::LogBinaryRecord* record);
00299
00303 static unsigned long getPriority(ACE_Log_Record &log_record);
00304
00306 void logXML(const ACE_TCHAR *xml, bool cache=true);
00307
00309 static bool isInit()
00310 {
00311 return initialized;
00312 }
00313
00315 static bool isInitThread();
00316
00318 int getCacheLogCount() const { if(!m_logBin) return m_cache.size(); else return m_bin_cache.size();}
00319
00320 protected:
00322 char *oldLog;
00323
00324 private:
00325
00327 static void formatISO8601inUTC(const ACE_Time_Value ×tamp, ACE_TCHAR str[]);
00328
00330 void failedToSend();
00331
00333 void successfullySent();
00334
00336 bool reconnectToLogger();
00337
00339 void sendCache();
00340
00342 void sendCacheInternal();
00343
00346 bool sendRecord(CORBA::Any &record);
00347
00350 bool sendRecord(const Logging::XmlLogRecordSeq &reclist);
00351
00352 void sendXmlLogs(ACE_Log_Record &log_record, const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00353 void sendBinLogs(ACE_Log_Record &log_record, const ACE_TCHAR * timestamp, const ACE_TCHAR * entryType);
00354
00361 unsigned long m_cacheSize;
00362
00369 unsigned long m_minCachePriority;
00370
00376 unsigned long m_maxCachePriority;
00377
00381 unsigned int m_autoFlushTimeoutSec;
00382
00387 Logging::AcsLogService_var m_logger;
00388 bool m_noLogger;
00389
00394 CosNaming::NamingContext_var m_namingContext;
00395
00398 int m_failureCount;
00399
00401 static int m_failureLimit;
00402
00405 ACE_Time_Value m_disconnectionTime;
00406
00408 static int m_minReconnectionTime;
00409
00413 typedef std::deque<ACE_CString> LogDeque;
00414 LogDeque m_cache;
00415
00416
00417 typedef std::deque<ACSLoggingLog::LogBinaryRecord *> LogBinDeque;
00418
00419 LogBinDeque m_bin_cache;
00420
00421
00422
00424 bool m_cacheDisabled;
00425
00429 static char m_process[256];
00430
00434 ACE_Recursive_Thread_Mutex m_mutex;
00435
00436 bool m_logBin;
00437
00441 static ACE_TSS<LoggingTSSStorage> * tss;
00442 static int instances;
00443
00445 ACE_CString m_filename;
00446
00448 bool m_alreadyInformed;
00449
00453 int m_envStdioPriority;
00454 int m_envCentralizePriority;
00455
00460 ACE_CString m_syslog;
00461
00463 static bool initialized;
00464
00465 static ACE_CString sourceObject_m;
00466
00469 static unsigned int setClrCount_m;
00470
00472 ACE_SYNCH_MUTEX m_doWorkMutex;
00473
00475 ACE_SYNCH_CONDITION m_doWorkCond;
00476
00478 volatile bool m_sendingPending;
00479
00481 virtual int svc();
00482
00484 static void* worker(void*);
00485
00487 volatile bool m_threadCreated;
00489
00491 ACE_Barrier m_threadShutdown;
00492 volatile bool m_shutdown;
00493 };
00494
00495 #endif