reSIProcate/rutil  9694
Classes | Defines | Functions
testLogger.cxx File Reference
#include "rutil/Logger.hxx"
#include "rutil/Data.hxx"
#include "rutil/ThreadIf.hxx"
#include "rutil/Timer.hxx"
#include "TestSubsystemLogLevel.hxx"
#include "rutil/WinLeakCheck.hxx"
Include dependency graph for testLogger.cxx:

Go to the source code of this file.

Classes

class  LogThread
class  TestExternalLogger

Defines

#define RESIPROCATE_SUBSYSTEM   Subsystem::SIP

Functions

int logsInCall ()
int debugLogsInCall ()
void testThreadLocalLoggers (const char *appname)
int main (int argc, char *argv[])

Define Documentation

#define RESIPROCATE_SUBSYSTEM   Subsystem::SIP

Definition at line 18 of file testLogger.cxx.


Function Documentation

int debugLogsInCall ( )

Definition at line 57 of file testLogger.cxx.

References DebugLog.

Referenced by main().

{
   DebugLog(<< "Got here?");
   return 17;
}
int logsInCall ( )

Definition at line 50 of file testLogger.cxx.

References InfoLog.

Referenced by main().

{
   InfoLog(<< "Got here?");
   return 17;
}
int main ( int  argc,
char *  argv[] 
)

Definition at line 134 of file testLogger.cxx.

References resip::Log::Cout, resip::Log::Crit, CritLog, resip::Log::Debug, DebugLog, debugLogsInCall(), resip::Log::Err, resip::Log::File, resip::Timer::getTimeMs(), resip::Log::Info, InfoLog, resip::Log::initialize(), resip::ThreadIf::join(), logsInCall(), resip::Log::OnlyExternal, Noisy::outputLogMessages(), resip::ThreadIf::run(), resip::Log::setLevel(), resip::Log::setServiceLevel(), resip::ThreadIf::shutdown(), resip::Log::Stack, resip::Subsystem::TEST, and testThreadLocalLoggers().

{
#if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK) 
   FindMemoryLeaks fml;
#endif

   CritLog(<< "logging before initializing is ok");

   Log::initialize(Log::Cout, Log::Info, argv[0]);

   InfoLog(<<"Subsystem level for TEST subsystem, not level set, global is info.");
   Noisy::outputLogMessages();
   Log::setLevel(Log::Debug, Subsystem::TEST);
   InfoLog(<<"Subsystem level for TEST subsystem, TEST set to Debug, global is info.");
   Noisy::outputLogMessages();
   Log::setLevel(Log::Crit, Subsystem::TEST);
   InfoLog(<<"Subsystem level for TEST subsystem, TEST set to Crit, global is info.");
   Noisy::outputLogMessages();

   DebugLog(<<"This should not appear.");
   InfoLog(<<"This should appear.");

   LogThread service1a("service1----A", Log::ThreadSetting(1, Log::Debug));
   LogThread service1b("service1-------B", Log::ThreadSetting(1, Log::Debug));
   LogThread service1c("service1---------C", Log::ThreadSetting(1, Log::Debug));

   LogThread service2a("service2-----------A", Log::ThreadSetting(2, Log::Debug));
   LogThread service2b("service2------------------B", Log::ThreadSetting(2, Log::Err));

   service1a.run();
   service1b.run();
   service1c.run();
   service2a.run();
   service2b.run();

   sleep(2);

   InfoLog(<<"Setting service 1 to INFO\n");
   Log::setServiceLevel(1, Log::Info);
   sleep(2);

   InfoLog(<<"Setting service 1 to CRIT\n");
   Log::setServiceLevel(1, Log::Crit);
   sleep(2);

   InfoLog(<<"Setting service 2 to STACK\n");
   Log::setServiceLevel(2, Log::Stack);
   sleep(2);

   InfoLog(<<"Setting service 1 to DEBUG\n");
   Log::setServiceLevel(1, Log::Debug);
   sleep(2);

   DebugLog(<<"This should still not appear.");
   InfoLog(<<"This should still appear.");

   InfoLog(<<"Log will now be written to testLoggerOut.txt.");

   Log::initialize(Log::File, Log::Info, argv[0], "testLoggerOut.txt");  
   InfoLog(<<"This should be in the file");
   sleep(2);
   
   Log::initialize(Log::Cout, Log::Info, argv[0]);
   InfoLog(<<"This should appear-back to Cout");
   sleep(2);   

   TestExternalLogger tel;
   Log::initialize(Log::OnlyExternal, Log::Info, argv[0], tel);
   InfoLog(<<"This should appear-back in cout through the extenal logger, and nowhere else");
   sleep(2);   

   service1a.shutdown();
   service1b.shutdown();
   service1c.shutdown();
   service2a.shutdown();
   service2b.shutdown();

   service1a.join();
   service1b.join();
   service1c.join();
   service2a.join();
   service2b.join();
   
   Log::initialize(Log::Cout, Log::Info, argv[0]);
   InfoLog(<<"This should appear-back to Cout");
   sleep(2);   

   Log::setLevel(Log::Info);

   if (false)
   {
      UInt64 start = Timer::getTimeMs();
      for (int i = 0; i < 10000; i++)
      {
         InfoLog(<< "string");
      }
      cerr << "Info Took: " << Timer::getTimeMs() - start << endl;
   }

   if (false)
   {
      UInt64 start = Timer::getTimeMs();
      for (int i = 0; i < 10000; i++)
      {
         DebugLog(<< "string");
      }
      cerr << "Debug Took: " << Timer::getTimeMs() - start << endl;
   }

   InfoLog(<< "Recursive debug: " << debugLogsInCall());
   DebugLog(<< "Recursive non-debug OK: " << logsInCall());

   InfoLog(<< "Recursive non-debug OK!: " << logsInCall());

   cout << endl;
   testThreadLocalLoggers(argv[0]);

   return 0;
}

Here is the call graph for this function:

void testThreadLocalLoggers ( const char *  appname)

Definition at line 80 of file testLogger.cxx.

References resip::Log::Cout, resip::Log::Debug, resip::Log::File, resip::Log::Info, InfoLog, resip::Log::initialize(), resip::ThreadIf::join(), resip::Log::localLoggerCreate(), resip::Log::localLoggerRemove(), Noisy::outputLogMessages(), resip::ThreadIf::run(), and resip::ThreadIf::shutdown().

Referenced by main().

{
   Log::initialize(Log::Cout, Log::Info, appname);

   InfoLog(<<"Going to test thread local loggers.");
   Noisy::outputLogMessages();

   Log::LocalLoggerId id1 = Log::localLoggerCreate(Log::File, Log::Info, "testLogger-local1.txt");
   Log::LocalLoggerId id2 = Log::localLoggerCreate(Log::File, Log::Info, "testLogger-local2.txt");

   LogThread serviceErr("service with wrong local logger Id",
                        Log::ThreadSetting(1, Log::Debug), id2+10);

   LogThread service0("global", Log::ThreadSetting(1, Log::Debug));
   LogThread service1a("local1----A", Log::ThreadSetting(1, Log::Debug), id1);
   LogThread service1b("local1-------B", Log::ThreadSetting(1, Log::Debug), id1);
   LogThread service2a("local2---------C", Log::ThreadSetting(1, Log::Debug), id2);
   LogThread service2b("local2-----------D", Log::ThreadSetting(1, Log::Debug), id2);

   service0.run();
   service1a.run();
   service1b.run();
   service2a.run();
   service2b.run();

   sleep(3);

   service0.shutdown();
   service1a.shutdown();
   service1b.shutdown();
   service2a.shutdown();
   service2b.shutdown();

   service0.join();
   service1a.join();
   service1b.join();
   service2a.join();
   service2b.join();

   int retval = Log::localLoggerRemove(id1);
   if (retval > 0)
   {
      std::cerr << "Local logger 1 hasn't been cleaned up correctly! "
                   "Log::localLoggerRemove() return code is " << retval << std::endl;
   }
   retval = Log::localLoggerRemove(id2);
   if (retval > 0)
   {
      std::cerr << "Local logger 2 hasn't been cleaned up correctly! "
                   "Log::localLoggerRemove() return code is " << retval << std::endl;
   }
}

Here is the call graph for this function: