Пример #1
0
void LoggingUnitTest::checkDefaultStatusTest(void) {
    Logging::Logger::LoggerSmartPtr testLoggerSmartPtr = getLogger();
    testLoggerSmartPtr->setName("testLogger");
    
    if(getenv("LOCATION")) { CPPUNIT_ASSERT(!testLoggerSmartPtr->stats.getDisableStatistics()); }
    else { CPPUNIT_ASSERT(testLoggerSmartPtr->stats.getDisableStatistics()); }
}
Пример #2
0
int main(int argc, char *argv[])
{
    ACS_CHECK_LOGGER;
    Logging::Logger::LoggerSmartPtr globalLoggerSmartPtr = getNamedLogger("MainLogger");

    printf("-------------------------------------------------------------------------\n");
    globalLoggerSmartPtr->log(Logging::Logger::LM_INFO,
			  "This is a global level log message.");
    
    
    TestLoggable noName = TestLoggable();
    TestLoggable withName = TestLoggable("loggableWithName");
    TestLoggable fromLogger = TestLoggable(globalLoggerSmartPtr);

    noName.doTestLogs();
    withName.doTestLogs();
    fromLogger.doTestLogs();
    noName.doTestLogs();
    withName.doTestLogs();
    fromLogger.doTestLogs();

    printf("-------------------------------------------------------------------------\n");
    printf("Here we test if static log macro(s) work(s)\n");
    TestLoggable::doTestStaticLogs();

    return 0;
}
Пример #3
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
Пример #4
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
Пример #5
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;
}
Пример #6
0
/**
 *
 * Test program and example for guarded logs.
 *
 */
int main(int argc, char *argv[])
{
    maci::SimpleClient client;

    if (client.init(argc,argv) == 0)
	{
	return -1;
	}
    else
	{
	// Log into the manager before doing anything
	client.login();
	}

    /*****************************************************************/
    /*
     * This example guards a log
     * produced using any subclass of Logging::BaseLog
     * These are the normal logs
     *
     * All examples follow this same pattern
     */

    /*
     * 1. The first step is to instantiate the guard template.
     * In this case the guarding is not done for multiple
     * executions of this function, since it is the main().
     * 
     * In that case we would have to declare the guard as static.
     * The same applies to all following examples
     *
     * This approach also allows to use the same guard for multiple logs
     * (as long as they are of the same logger type)
     */
    Logging::RepeatGuardLogger<Logging::BaseLog> guardbl(10000000,10);

    /*
     * 2. We get the standard logger for this "object"
     *    and we make a simple normal log, just to see that it works. 
     */
    Logging::Logger::LoggerSmartPtr logger = getLogger();
    logger->log(Logging::Logger::LM_INFO, "Simple test.",
	       __FILE__,__LINE__,
	       "main");

    /*
     * 3. Finally we make a loop with the guarded log
     */
    for(int i=0;i<50;i++)
	{
	guardbl.log(logger, Logging::Logger::LM_INFO, 
		    "Log A without incrementing",
		    __FILE__,__LINE__,
		    "main");
	guardbl.log(logger, Logging::Logger::LM_INFO, 
		    "Log B without incrementing",
		    __FILE__,__LINE__,
		    "main");
	guardbl.logAndIncrement(logger, Logging::Logger::LM_INFO, 
		    "LogAndIncrement",
		    __FILE__,__LINE__,
		    "main");
	}

    /*****************************************************************/
    /*
     * This example guards a type-safe log
     * produced using any subclass of Logging::TypeSafeLog
     */

    Logging::RepeatGuardLogger<Logging::TypeSafeLog> guard(10000000,10);

    repeatGuardLogTypeExample::simpleLog my_simpleLog(__FILE__,__LINE__,"main");
    my_simpleLog.log();


    guard.log(my_simpleLog);

    for(int i=0;i<50;i++)
	{
	guard.logAndIncrement(my_simpleLog);
	}

    /*****************************************************************/
    /*
     * This example guards the logging of an exception
     * produced using any subclass of ACSErr::ACSbaseExImpl
     */


    Logging::RepeatGuardLogger<ACSErr::ACSbaseExImpl> guardex(10000000,10);

    ACSErrTypeCommon::GenericErrorExImpl displayMessageEx(
	__FILE__, __LINE__, "main");
    displayMessageEx.log();


    guardex.log(displayMessageEx);

    for(int i=0;i<50;i++)
	{
	guardex.logAndIncrement(displayMessageEx);
	}

    /*****************************************************************/
    client.logout();

    return 0;

}