Exemplo n.º 1
0
Thread::Thread(const ACE_CString & name,
	       const TimeInterval& responseTime,
	       const TimeInterval& sleepTime,
	       const bool del,
	       const long _thrFlags,
	       const size_t _stackSize
		     ):
    ThreadBase(name,
	       ACE_Thread_Manager::instance(),
	       (void*)Thread::threadSvc,
//	       (void*)this,
	       static_cast<void*>(this),
	       responseTime,
	       sleepTime,
	       false /* super class shall not create a thread */,
	       THR_NEW_LWP | THR_DETACHED,
	       _stackSize),
    logger_mp(0), thrMgr_mp(0), delete_m(del)
{
    ACS_TRACE("ACS::Thread::Thread");
    thrMgr_mp = ACS::ThreadManager::threadManagerTSS->getThreadManager(true);
    if (thrMgr_mp != NULL)
    {
        if(!thrMgr_mp->add(name, static_cast<ACS::Thread*>(this)))
        {
            acsthreadErrType::ThreadAlreadyExistExImpl ex1(__FILE__, __LINE__, "ACS::Thread::Thread");
            ex1.setThreadName(getName());
            acsthreadErrType::CanNotSpawnThreadExImpl ex2(ex1, __FILE__, __LINE__, "ACS::Thread::Thread");
            ex2.setThreadName(getName());
            throw ex2;
        }

        // set logger
        Logging::Logger::LoggerSmartPtr thrMgrLog = getThreadManager()->getLogger();
        //if thread manager's logger is not global logger
        if (thrMgrLog->getName() != Logging::Logger::getGlobalLogger()->getName() )
        {
        	setLogger(thrMgrLog);
        }//if
    }//if
    /*
     * We create a Kernel Thread and the thread is:
     * But we have to be careful: if we have a JOINABLE thread,
     * we HAVE TO JOIN to it to release resources!!!!
     */
    if (!create(_thrFlags))
    {
        if (thrMgr_mp != NULL)  thrMgr_mp->removeFromMap(name);
        acsthreadErrType::CanNotSpawnThreadExImpl ex(__FILE__, __LINE__, "ACS::Thread::Thread");
        ex.setThreadName(getName());
        throw ex;
    }//if
}//Thread::Thread
Exemplo n.º 2
0
void logBatchDirectLog(Logging::Logger::LoggerSmartPtr logger)
{
	std::ostringstream oss;
	oss.clear();
	oss.str(std::string());
	oss << "Log batch for logger [" << logger->getName() << "]. USING log() functions.";
	logger->log(Logging::Logger::LM_INFO, oss.str());

	// Test all messages
	//logger->log(Logging::Logger::LM_SHUTDOWN, "Testing LM_SHUTDOWN message: Shutdown messages"); // NOT logging a thing
	logger->log(Logging::Logger::LM_TRACE, "Testing LM_TRACE message: Messages indicating function-calling sequence");
	logger->log(Logging::Logger::LM_DEBUG, "Testing LM_DEBUG message: Messages that contain information normally of use only when debugging a program");
	logger->log(Logging::Logger::LM_INFO, "Testing LM_INFO message: Informational messages");
	logger->log(Logging::Logger::LM_NOTICE, "Testing LM_NOTICE message: Conditions that are not error conditions, but that may require");
	logger->log(Logging::Logger::LM_WARNING, "Testing LM_WARNING message: Warning messages");
	logger->log(Logging::Logger::LM_ERROR, "Testing LM_ERROR message: Error messages");
	logger->log(Logging::Logger::LM_CRITICAL, "Testing LM_CRITICAL message: Critical conditions, such as hard device errors");
	logger->log(Logging::Logger::LM_ALERT, "Testing LM_ALERT message: A condition that should be corrected immediately, such as a corrupted system database");
	logger->log(Logging::Logger::LM_EMERGENCY, "Testing LM_EMERGENCY message: A panic condition.  This is normally broadcast to all users");

} // 10 messages
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	std::ostringstream oss;

    ACS_CHECK_LOGGER;

    // First logger
    Logging::Logger::LoggerSmartPtr firstLoggerSmartPtr = getLogger();
    firstLoggerSmartPtr->setName("FirstLogger");

    // Second logger
    Logging::Logger::LoggerSmartPtr secondLoggerSmartPtr = getNamedLogger("SecondLogger");

    // Third logger
    Logging::Logger::LoggerSmartPtr thirdLoggerSmartPtr = getNamedLogger("ThirdLogger");

    // BY DEFAULT STATISTICS ARE NOT ACTIVE: Those messages are not counted
    {
		oss.clear();
		oss.str(std::string());
		oss << "Statistics for logger [" << firstLoggerSmartPtr->getName() << "] are by default disabled";
		firstLoggerSmartPtr->log(Logging::Logger::LM_INFO, oss.str());
		logBatchDirectLog(firstLoggerSmartPtr);
    } // Batch for first logger
    {
		oss.clear();
		oss.str(std::string());
		oss << "Statistics for logger [" << secondLoggerSmartPtr->getName() << "] are by default disabled";
		secondLoggerSmartPtr->log(Logging::Logger::LM_INFO, oss.str());
		logBatchDirectLog(secondLoggerSmartPtr);
    } // Batch for second logger
    {
		oss.clear();
		oss.str(std::string());
		oss << "Statistics for logger [" << thirdLoggerSmartPtr->getName() << "] are by default disabled";
		thirdLoggerSmartPtr->log(Logging::Logger::LM_INFO, oss.str());
		logBatchDirectLog(thirdLoggerSmartPtr);
    } // Batch for third logger

    // Log to general logger using macros
    {
    	logBatchUsingMacrosGeneralLogger();
    } // is the First Logger

    // Activate statistics for first logger
    firstLoggerSmartPtr->log(Logging::Logger::LM_INFO, "Activate statistics for first logger -----------");
    firstLoggerSmartPtr->stats.configureStatistics("testLoggerStats",false, 3, 1);
    // and send a second batch
    {
    	logBatchDirectLog(firstLoggerSmartPtr);
    	logBatchDirectLog(secondLoggerSmartPtr);
    	logBatchDirectLog(thirdLoggerSmartPtr);
    } // only firstLoggerSmartPtr logs will be counted in statistics

    // Log to general logger using macros
    {
    	logBatchUsingMacrosGeneralLogger();
    } // is the First Logger

    // Log to general logger using macros
    {
    	logBatchUsingMacrosStaticLogger();
    } // no stats

    // Activate statistics for second logger
    secondLoggerSmartPtr->log(Logging::Logger::LM_INFO, "Activate statistics for second logger -----------");
    secondLoggerSmartPtr->stats.configureStatistics("testLoggerStats",false, 3, 1);
	// wait 2 seconds to force statistics to be calculated
	unsigned int microseconds = 3100000;
	usleep(microseconds);
	// and send logs to all three loggers
	firstLoggerSmartPtr->log(Logging::Logger::LM_INFO, "FIRST LOGGER STATS ACTIVE");
	secondLoggerSmartPtr->log(Logging::Logger::LM_INFO, "SECOND LOGGER STATS ACTIVE");
	thirdLoggerSmartPtr->log(Logging::Logger::LM_INFO, "THIRD LOGGER STATS INACTIVE");

	// and then send a second batch
	{
    	logBatchDirectLog(firstLoggerSmartPtr);
    	logBatchDirectLog(secondLoggerSmartPtr);
    	logBatchDirectLog(thirdLoggerSmartPtr);
    } // first and second loggers will use them for stats

	// and then send a third batch
	{
		logBatchDirectLog(firstLoggerSmartPtr);
		logBatchDirectLog(secondLoggerSmartPtr);
		logBatchDirectLog(thirdLoggerSmartPtr);
	} // first and second loggers will use them for stats

	// Activate also static logger stats
	firstLoggerSmartPtr->log(Logging::Logger::LM_INFO, "Activate statistics for static logger -----------");
	Logging::Logger::getStaticLogger()->stats.configureStatistics("testLoggerStats",false, 3, 1);
	// and send static batch
	{
    	logBatchUsingMacrosStaticLogger();
	} // stats calculated

    return 0;
}