Problem

Logging (from threads not managed by ACS) does not work. What am I doing wrong?

Solution

You might find yourself in the situation of putting logs using the ACS logging system and nothing gets published.

This might happen if the function is called by threads that are not managed by ACS (or by ACE/TAO, which provides the underlying logging engine used by ACS).
For example, if you create your own pthreads instead of using ACSThreads or if you use libraries calling your own callbacks in self managed threads.
The typical situation where we have traced this problem is by using RTI DDS, where user defined callback are called when data is received.

If these cases you just have to remember to properly initialize the ACS Logging system for the thread by using the following code:


    if (maci::ContainerImpl::getLoggerProxy())
       {
        LoggingProxy::init(maci::ContainerImpl::getLoggerProxy());
       }

Remember also that normally callbacks are static functions and, therefore, you have to use the STATIC_LOG methogs, like:


    ACS_STATIC_LOG( LM_FULL_INFO, "main",(LM_TRACE, "ProbeSimulatorImpl::gsCoordHandlerFunction")); 

or

    ACS_STATIC_TRACE("ProbeSimulatorImpl::gsCoordHandlerFunction");

Not doing this will result in a compile time error.

From a technical point of view, the ACE logging system relies on data in Thread Specific Storage (TSS) to attach application specific logging publishers to the logging engine and this structure needs therefore to be properly initialized for each thread.

Threads managed by ACS/ACE/TAO do this, but fully user defined threads know nothing of ACE Logging and the logs would therefore go to the sink.



-- GianlucaChiozzi - 10 Sep 2009