#include <loggingLoggingProxy.h>
Public Member Functions | |
void | log (ACE_Log_Record &log_record) |
LoggingProxy (const unsigned long cacheSize, const unsigned long minCachePriority, const unsigned long maxCachePriority, Logging::AcsLogService_ptr centralizedLogger=Logging::AcsLogService::_nil(), CosNaming::NamingContext_ptr namingContext=CosNaming::NamingContext::_nil(), const unsigned int autoFlushTimeoutSec=5, const int maxLogsPerSecond=-1) | |
~LoggingProxy () | |
Destructor. | |
void | setCentralizedLogger (Logging::AcsLogService_ptr centralizedLogger) |
Set Centralized Logger. | |
void | setNamingContext (CosNaming::NamingContext_ptr namingContext) |
Set Naming Context. | |
void | flush () |
Forces logger to flush cache. Thread safe! | |
void | setStdio (int stdio) |
Sets ACS_LOG_STDOUT runtime. | |
void | logXML (const ACE_TCHAR *xml, bool cache=true) |
Checks xml if it is XML and "DTD" string and send it to centralized logger. Thread safe! | |
int | getCacheLogCount () const |
For testing only (not tread-safe). | |
Static Public Member Functions | |
static void | LogEntryType (const ACE_TCHAR *szType) |
static void | Routine (const ACE_TCHAR *szRoutine) |
static void | File (const ACE_TCHAR *fileName) |
static void | Line (long lineNumber) |
static void | Flags (unsigned int uiFlags) |
static void | ThreadName (const ACE_TCHAR *szName) |
static const ACE_TCHAR * | ThreadName () |
Returns the name of the thread. | |
static void | ProcessName (const ACE_TCHAR *szName) |
static const ACE_TCHAR * | ProcessName () |
Returns the name of the process. | |
static void | ResetAttributes () |
static void | AddAttribute (const ACE_TCHAR *szName, const ACE_TCHAR *szValue) |
Add an attribute to the list of next log entries� attributes. | |
static void | LogId (const ACE_TCHAR *szName) |
static void | URI (const ACE_TCHAR *szName) |
static void | StackId (const ACE_TCHAR *szId) |
static const ACE_TCHAR * | StackId () |
static void | PrivateFlags (int privateFlags) |
Private flags (to be used only internally). | |
static const int | PrivateFlags () |
Private flags (to be used only internally). | |
static void | LogLevelLocalType (int logLevelLocalType) |
static const int | LogLevelLocalType () |
static void | LogLevelRemoteType (int logLevelRemoteType) |
static const int | LogLevelRemoteType () |
static void | StackLevel (int nLevel) |
static int | StackLevel () |
Retrieve the stack level in the current logical thread. | |
static void | Context (const ACE_TCHAR *szName) |
static const ACE_TCHAR * | Context () |
Retrieve the context in which the code is operating. | |
static void | SourceObject (const ACE_TCHAR *soName) |
static const ACE_TCHAR * | SourceObject () |
static void | audience (const ACE_TCHAR *aud) |
Set the audience intended for the log message. | |
static const ACE_TCHAR * | audience () |
static void | array (const ACE_TCHAR *aud) |
Set the array where the log message was generated. | |
static const ACE_TCHAR * | array () |
static void | antenna (const ACE_TCHAR *aud) |
Set the antenna where the log message was generated. | |
static const ACE_TCHAR * | antenna () |
static void | host (const ACE_TCHAR *aud) |
Set the host where the log message was generated. | |
static const ACE_TCHAR * | host () |
static void | AddData (const ACE_TCHAR *szName, const ACE_TCHAR *szFormat,...) |
static ACE_TSS < LoggingTSSStorage > * | getTSS () |
static void | init (LoggingProxy *loggingProxy) |
ACE log type int-to-string mapping. | |
static void | done () |
returns ACE_LOG_MSG to default state | |
static std::string | BinToXml (ACSLoggingLog::LogBinaryRecord *record) |
static unsigned long | getPriority (ACE_Log_Record &log_record) |
static bool | isInit () |
Returns true if loggin is initialized otherwise false. | |
static bool | isInitThread () |
Returns true if logging is initialized in this thread. | |
Protected Attributes | |
char * | oldLog |
Private Types | |
typedef std::deque< ACE_CString > | LogDeque |
typedef std::deque < ACSLoggingLog::LogBinaryRecord * > | LogBinDeque |
Private Member Functions | |
void | failedToSend () |
Method to be called when CORBA invocation to the centralized logger failed. | |
void | successfullySent () |
Method to be called when CORBA invocation to the centralized logger was successful. | |
bool | reconnectToLogger () |
Tries to reconnect to the centralized logger (after some amount of time) and return <true> if successful. | |
void | sendCache () |
Send local cache file to the centralized logger (Telecom log service). | |
void | sendCacheInternal () |
Send local cache file to the centralized logger (Telecom log service). | |
bool | sendRecord (CORBA::Any &record) |
bool | sendRecord (const Logging::XmlLogRecordSeq &reclist) |
void | sendXmlLogs (ACE_Log_Record &log_record, const ACE_TCHAR *timestamp, const ACE_TCHAR *entryType) |
void | sendBinLogs (ACE_Log_Record &log_record, const ACE_TCHAR *timestamp, const ACE_TCHAR *entryType) |
virtual int | svc () |
Thread entry point (thread worker). | |
Static Private Member Functions | |
static void | formatISO8601inUTC (const ACE_Time_Value ×tamp, ACE_TCHAR str[]) |
Get time in ISO8601 format in UTC (eg. 2000-12-31T08:12:21.322) - 24 chars (incl. ). | |
static void * | worker (void *) |
Static thread worker (calls svc). | |
Private Attributes | |
unsigned long | m_cacheSize |
unsigned long | m_minCachePriority |
unsigned long | m_maxCachePriority |
unsigned int | m_autoFlushTimeoutSec |
int | m_maxLogsPerSecond |
logging::LogThrottle * | logThrottle |
Logging::AcsLogService_var | m_logger |
bool | m_noLogger |
CosNaming::NamingContext_var | m_namingContext |
int | m_failureCount |
ACE_Time_Value | m_disconnectionTime |
LogDeque | m_cache |
LogBinDeque | m_bin_cache |
bool | m_cacheDisabled |
Cache state. | |
ACE_Recursive_Thread_Mutex | m_mutex |
bool | m_logBin |
ACE_CString | m_filename |
Local output file, if Centralized Logger is unavailable (set by ACE_LOG_FILE env. var). | |
bool | m_alreadyInformed |
Switch to inform client only once about logging to the file. | |
int | m_envStdioPriority |
int | m_envCentralizePriority |
ACE_CString | m_syslog |
ACE_SYNCH_MUTEX | m_doWorkMutex |
The mutual exclusion mechanism which is required to use the <m_workWorkCond>. | |
ACE_SYNCH_CONDITION | m_doWorkCond |
Work condition. | |
volatile bool | m_sendingPending |
Sending pending... | |
volatile bool | m_threadCreated |
Thread creation flag. | |
ACE_Barrier | m_threadShutdown |
Thread start barrier. | |
volatile bool | m_shutdown |
Static Private Attributes | |
static int | m_failureLimit |
Failure count limit. | |
static int | m_minReconnectionTime |
Reconnection retry (minimum time in sec). | |
static char | m_process [256] |
static ACE_TSS < LoggingTSSStorage > * | tss |
static int | instances |
static bool | initialized |
Initialization flag. | |
static ACE_CString | sourceObject_m |
static unsigned int | setClrCount_m |
The Log Message Callback. All ACE logging requests (ACE_DEBUG, ACE_ERROR, or ACS_LOG calls) are to be redirected through this LoggingProxy. One of the first things what an ACS application should do is to initialize LoggingProxy. An example of initialization:
// initialize ACE logger instance ACE_TCHAR hostname[33]; ACE_OS::hostname (hostname, sizeof(hostname)); ACE_Log_Msg::instance()->local_host(hostname);
LoggingProxy * logger = new LoggingProxy(cacheSize, minCachePriority, maxCachePriority, telecomLogger.in(), namingContext.in()); if (logger) { LoggingProxy::init(logger); LoggingProxy::ProcessName(argv[0]); LoggingProxy::ThreadName("main"); }
WARNING: When LoggingProxy is configured to log to the centralized logger, this means remote logging using CORBA, user of the LoggingProxy is obligated to disable remote logging before shutting down CORBA, i.e. calling CORBA::ORB::shutdown() or CORBA::ORB::destroy() metods. This is simply done by setting centralized logger refernce to nil. An example: if (logger) { logger->flush(); logger->setCentralizedLogger(Logging::AcsLogService::_nil()); }
LoggingProxy is also configurable via next enivronment variables:
typedef std::deque<ACSLoggingLog::LogBinaryRecord *> LoggingProxy::LogBinDeque [private] |
typedef std::deque<ACE_CString> LoggingProxy::LogDeque [private] |
Local cache
LoggingProxy::LoggingProxy | ( | const unsigned long | cacheSize, | |
const unsigned long | minCachePriority, | |||
const unsigned long | maxCachePriority, | |||
Logging::AcsLogService_ptr | centralizedLogger = Logging::AcsLogService::_nil() , |
|||
CosNaming::NamingContext_ptr | namingContext = CosNaming::NamingContext::_nil() , |
|||
const unsigned int | autoFlushTimeoutSec = 5 , |
|||
const int | maxLogsPerSecond = -1 | |||
) |
Constructor WARNING: LoggingProxy MUST be created before calling any of its static methods!
LoggingProxy::~LoggingProxy | ( | ) |
Destructor.
static void LoggingProxy::AddAttribute | ( | const ACE_TCHAR * | szName, | |
const ACE_TCHAR * | szValue | |||
) | [static] |
Add an attribute to the list of next log entries� attributes.
static void LoggingProxy::AddData | ( | const ACE_TCHAR * | szName, | |
const ACE_TCHAR * | szFormat, | |||
... | ||||
) | [static] |
Supply data with the log entry that follows. The maximum lenghth for AddData value is ADD_DATA_VALUE_MAX (255+). If it is too long it will be truncated.
Referenced by Logging::RepeatGuardLogger< ALogger >::log(), and Logging::RepeatGuardLogger< ALogger >::logAndIncrement().
static void LoggingProxy::antenna | ( | const ACE_TCHAR * | aud | ) | [static] |
Set the antenna where the log message was generated.
static const ACE_TCHAR* LoggingProxy::antenna | ( | ) | [static] |
Return the antenna. The name is global per thread (stored in thread-specific storage TSS)
static const ACE_TCHAR* LoggingProxy::array | ( | ) | [static] |
Return the array. The name is global per thread (stored in thread-specific storage TSS)
static void LoggingProxy::array | ( | const ACE_TCHAR * | aud | ) | [static] |
Set the array where the log message was generated.
static void LoggingProxy::audience | ( | const ACE_TCHAR * | aud | ) | [static] |
Set the audience intended for the log message.
static const ACE_TCHAR* LoggingProxy::audience | ( | ) | [static] |
Return the audience. The name is global per thread (stored in thread-specific storage TSS)
static std::string LoggingProxy::BinToXml | ( | ACSLoggingLog::LogBinaryRecord * | record | ) | [static] |
static const ACE_TCHAR* LoggingProxy::Context | ( | ) | [static] |
Retrieve the context in which the code is operating.
static void LoggingProxy::Context | ( | const ACE_TCHAR * | szName | ) | [static] |
Set the context in which the code is operating. Pointer to the name must be stored in the thread-specific storage!
static void LoggingProxy::done | ( | ) | [static] |
returns ACE_LOG_MSG to default state
void LoggingProxy::failedToSend | ( | ) | [private] |
Method to be called when CORBA invocation to the centralized logger failed.
static void LoggingProxy::File | ( | const ACE_TCHAR * | fileName | ) | [static] |
Specifies the name of the file where the following log entry will be generated. Pointer to the string must be stored in the thread-specific storage!
static void LoggingProxy::Flags | ( | unsigned int | uiFlags | ) | [static] |
Set the flags that will apply to the log entry that will be submitted next. Flags must be stored in thread-specific storage! Flags are obtained by OR-ing appropriate LM_* values above. If priority is 0, the default priority associated with ACE's log entry type (LM_INFO, LM_ERROR, ...) is implied.
void LoggingProxy::flush | ( | ) |
Forces logger to flush cache. Thread safe!
static void LoggingProxy::formatISO8601inUTC | ( | const ACE_Time_Value & | timestamp, | |
ACE_TCHAR | str[] | |||
) | [static, private] |
Get time in ISO8601 format in UTC (eg. 2000-12-31T08:12:21.322) - 24 chars (incl. ).
int LoggingProxy::getCacheLogCount | ( | ) | const [inline] |
For testing only (not tread-safe).
static unsigned long LoggingProxy::getPriority | ( | ACE_Log_Record & | log_record | ) | [static] |
static ACE_TSS<LoggingTSSStorage>* LoggingProxy::getTSS | ( | ) | [static] |
static void LoggingProxy::host | ( | const ACE_TCHAR * | aud | ) | [static] |
Set the host where the log message was generated.
static const ACE_TCHAR* LoggingProxy::host | ( | ) | [static] |
Return the host The name is global per thread (stored in thread-specific storage TSS)
static void LoggingProxy::init | ( | LoggingProxy * | loggingProxy | ) | [static] |
ACE log type int-to-string mapping.
initializes ACE_LOG_MSG (must be done per each thread)
static bool LoggingProxy::isInit | ( | ) | [inline, static] |
Returns true if loggin is initialized otherwise false.
static bool LoggingProxy::isInitThread | ( | ) | [static] |
Returns true if logging is initialized in this thread.
static void LoggingProxy::Line | ( | long | lineNumber | ) | [static] |
Specifies the name of the file where the following log entry will be generated. Pointer to the string must be stored in the thread-specific storage!
void LoggingProxy::log | ( | ACE_Log_Record & | log_record | ) |
Receives all log entries submited within the process. Thread safe!
static void LoggingProxy::LogEntryType | ( | const ACE_TCHAR * | szType | ) | [static] |
Specifies the log entry type, if the output representation is different than the one implied with ACE�s log entry type. Applies for the next log entry only. Pointer to the string must be stored in the thread-specific storage!
static void LoggingProxy::LogId | ( | const ACE_TCHAR * | szName | ) | [static] |
Specify the LogId attribute of the log entry that follows. Can be 0 (default) in which case no LogId attribute is output.
static void LoggingProxy::LogLevelLocalType | ( | int | logLevelLocalType | ) | [static] |
static const int LoggingProxy::LogLevelLocalType | ( | ) | [static] |
static void LoggingProxy::LogLevelRemoteType | ( | int | logLevelRemoteType | ) | [static] |
static const int LoggingProxy::LogLevelRemoteType | ( | ) | [static] |
void LoggingProxy::logXML | ( | const ACE_TCHAR * | xml, | |
bool | cache = true | |||
) |
Checks xml if it is XML and "DTD" string and send it to centralized logger. Thread safe!
static void LoggingProxy::PrivateFlags | ( | int | privateFlags | ) | [static] |
Private flags (to be used only internally).
static const int LoggingProxy::PrivateFlags | ( | ) | [static] |
Private flags (to be used only internally).
static void LoggingProxy::ProcessName | ( | const ACE_TCHAR * | szName | ) | [static] |
Specifies the name of the process. Must be stored in a process-wide global variable!
static const ACE_TCHAR* LoggingProxy::ProcessName | ( | ) | [static] |
Returns the name of the process.
Referenced by acsDaemonImpl< T >::acsDaemonImpl().
bool LoggingProxy::reconnectToLogger | ( | ) | [private] |
Tries to reconnect to the centralized logger (after some amount of time) and return <true> if successful.
static void LoggingProxy::ResetAttributes | ( | ) | [static] |
Reset the list of custom attributes. The attributes are applicable to the next log entry only.
static void LoggingProxy::Routine | ( | const ACE_TCHAR * | szRoutine | ) | [static] |
Specifies the name of the routine (function) where the following log entry will be generated. Pointer to the string must be stored in the thread-specific storage!
void LoggingProxy::sendBinLogs | ( | ACE_Log_Record & | log_record, | |
const ACE_TCHAR * | timestamp, | |||
const ACE_TCHAR * | entryType | |||
) | [private] |
void LoggingProxy::sendCache | ( | ) | [private] |
Send local cache file to the centralized logger (Telecom log service).
void LoggingProxy::sendCacheInternal | ( | ) | [private] |
Send local cache file to the centralized logger (Telecom log service).
bool LoggingProxy::sendRecord | ( | CORBA::Any & | record | ) | [private] |
Send given record to the centralized logger (Telecom log service) Return: true if successful, false on failure
bool LoggingProxy::sendRecord | ( | const Logging::XmlLogRecordSeq & | reclist | ) | [private] |
Send given record to the centralized logger (Telecom log service) Return: true if successful, false on failure
void LoggingProxy::sendXmlLogs | ( | ACE_Log_Record & | log_record, | |
const ACE_TCHAR * | timestamp, | |||
const ACE_TCHAR * | entryType | |||
) | [private] |
void LoggingProxy::setCentralizedLogger | ( | Logging::AcsLogService_ptr | centralizedLogger | ) |
Set Centralized Logger.
void LoggingProxy::setNamingContext | ( | CosNaming::NamingContext_ptr | namingContext | ) | [inline] |
Set Naming Context.
void LoggingProxy::setStdio | ( | int | stdio | ) | [inline] |
Sets ACS_LOG_STDOUT runtime.
static const ACE_TCHAR* LoggingProxy::SourceObject | ( | ) | [static] |
Return the name of the source object set by SourceObject The name is global per thread (stored in thread-specific storage TSS)
static void LoggingProxy::SourceObject | ( | const ACE_TCHAR * | soName | ) | [static] |
Set the name of the object which is publishing the log. Pointer to the name must be stored in the thread-specific storage!
static const ACE_TCHAR* LoggingProxy::StackId | ( | ) | [static] |
Returns the the logical thread ID. Must have been set previously using StackId.
static void LoggingProxy::StackId | ( | const ACE_TCHAR * | szId | ) | [static] |
Specifies the stack ID of the current logical thread. Pointer to the name must be stored in the thread-specific storage! Can be set to NULL if the logical thread ID is unknown.
static int LoggingProxy::StackLevel | ( | ) | [static] |
Retrieve the stack level in the current logical thread.
static void LoggingProxy::StackLevel | ( | int | nLevel | ) | [static] |
Set the stack level in the current logical thread. The value must be stored in the thread-specific storage!
void LoggingProxy::successfullySent | ( | ) | [private] |
Method to be called when CORBA invocation to the centralized logger was successful.
virtual int LoggingProxy::svc | ( | ) | [private, virtual] |
Thread entry point (thread worker).
static const ACE_TCHAR* LoggingProxy::ThreadName | ( | ) | [static] |
Returns the name of the thread.
Referenced by acsDaemonImpl< T >::acsDaemonImpl().
static void LoggingProxy::ThreadName | ( | const ACE_TCHAR * | szName | ) | [static] |
Specifies the name of the thread. Pointer to the name must be stored in the thread-specific storage!
static void LoggingProxy::URI | ( | const ACE_TCHAR * | szName | ) | [static] |
Specify the URI attribute of the log entry that follows. Can be 0 (default) in which case no URI attribute is output.
static void* LoggingProxy::worker | ( | void * | ) | [static, private] |
Static thread worker (calls svc).
bool LoggingProxy::initialized [static, private] |
Initialization flag.
int LoggingProxy::instances [static, private] |
logging::LogThrottle* LoggingProxy::logThrottle [private] |
bool LoggingProxy::m_alreadyInformed [private] |
Switch to inform client only once about logging to the file.
unsigned int LoggingProxy::m_autoFlushTimeoutSec [private] |
Timeout in seconds to auto-flush (send cache).
LogBinDeque LoggingProxy::m_bin_cache [private] |
LogDeque LoggingProxy::m_cache [private] |
bool LoggingProxy::m_cacheDisabled [private] |
Cache state.
unsigned long LoggingProxy::m_cacheSize [private] |
The number of log entries that can be kept in the local cache. When this number is reached, all log entries are transferred to the centralized logging. If network connection is not available, the local cache continues to grow, and every submitting of a log entry will attempt to flush the cache to the centralized logging.
ACE_Time_Value LoggingProxy::m_disconnectionTime [private] |
The time CL was disabled. LoggingProxy will try to reconnect after some (defined) time.
ACE_SYNCH_CONDITION LoggingProxy::m_doWorkCond [private] |
Work condition.
ACE_SYNCH_MUTEX LoggingProxy::m_doWorkMutex [private] |
The mutual exclusion mechanism which is required to use the <m_workWorkCond>.
int LoggingProxy::m_envCentralizePriority [private] |
int LoggingProxy::m_envStdioPriority [private] |
Priority of logs to be sent to STDIO (set by ACE_LOG_STDIO env. var.): # < 0 - log only LM_INFO (4) and higher - default # otherwise all >= log all
int LoggingProxy::m_failureCount [private] |
Failure counter for centralized logger (CL). If the failure counter reaches the limit, CL is disabled.
int LoggingProxy::m_failureLimit [static, private] |
Failure count limit.
ACE_CString LoggingProxy::m_filename [private] |
Local output file, if Centralized Logger is unavailable (set by ACE_LOG_FILE env. var).
bool LoggingProxy::m_logBin [private] |
Logging::AcsLogService_var LoggingProxy::m_logger [private] |
Reference to the persistent object which implements the Telecom Log Service�s Log interface, in particular the write_records method.
unsigned long LoggingProxy::m_maxCachePriority [private] |
Log entries whose priority exceeds (is greater than) the one specified with this property will be directly transmitted to the centralized logging, bypassing the local cache. If this is set to MinCachePriority 1, the local cache feature is disabled.
int LoggingProxy::m_maxLogsPerSecond [private] |
Throttling, max Log/second allowed to be sent to the logging system. -1 turn off the throttling
unsigned long LoggingProxy::m_minCachePriority [private] |
Log entries whose priority is below (smaller than) the one specified with this property will be ignored (neither cached nor submitted to the centralized logging). In release version of the system, this will be set to LM_INFO (3), ignoring LM_TRACE and LM_DEBUG log entries. Debug version of the system will set this to LM_DEBUG (2). During development, it will be set to LM_TRACE (1).
int LoggingProxy::m_minReconnectionTime [static, private] |
Reconnection retry (minimum time in sec).
ACE_Recursive_Thread_Mutex LoggingProxy::m_mutex [private] |
Thread mutex to make log() method thread-safe
CosNaming::NamingContext_var LoggingProxy::m_namingContext [private] |
Reference to the naming service. Used to get new reference of the Centralized Logger ("Log") in reconnectToLogger() method.
bool LoggingProxy::m_noLogger [private] |
char LoggingProxy::m_process[256] [static, private] |
Process
volatile bool LoggingProxy::m_sendingPending [private] |
Sending pending...
volatile bool LoggingProxy::m_shutdown [private] |
ACE_CString LoggingProxy::m_syslog [private] |
Syslog setting (set by ACE_LOG_SYSLOG env. var.): not defined - local file cache is used 'localhost' - local syslog is used (if available) hostname - remote syslog is used (by default port 514/udp is used).
volatile bool LoggingProxy::m_threadCreated [private] |
Thread creation flag.
ACE_Barrier LoggingProxy::m_threadShutdown [private] |
Thread start barrier.
Thread shutdown barrier
char* LoggingProxy::oldLog [protected] |
If the environment variable LOG_SERVICE_USE_EXTENSIONS is set the new log way will be used
unsigned int LoggingProxy::setClrCount_m [static, private] |
Set /clear flag counter - number of timest that global flags were set cleared
ACE_CString LoggingProxy::sourceObject_m [static, private] |
ACE_TSS<LoggingTSSStorage>* LoggingProxy::tss [static, private] |
Thread specific storage