Esempio n. 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()); }
}
Esempio n. 2
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;
}