You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

  1. #include <log4cplus/logger.h>
  2. #include <log4cplus/configurator.h>
  3. #include <log4cplus/helpers/loglog.h>
  4. #include <log4cplus/helpers/stringhelper.h>
  5. #include <log4cplus/helpers/sleep.h>
  6. #include <log4cplus/loggingmacros.h>
  7. using namespace std;
  8. using namespace log4cplus;
  9. using namespace log4cplus::helpers;
  10. Logger log_1 = Logger::getInstance(LOG4CPLUS_TEXT("test.log_1"));
  11. Logger log_2 = Logger::getInstance(LOG4CPLUS_TEXT("test.log_2"));
  12. Logger log_3 = Logger::getInstance(LOG4CPLUS_TEXT("test.log_3"));
  13. void
  14. printMsgs(Logger& logger)
  15. {
  16. LOG4CPLUS_TRACE_METHOD(logger, LOG4CPLUS_TEXT("printMsgs()"));
  17. LOG4CPLUS_DEBUG(logger, "printMsgs()");
  18. LOG4CPLUS_INFO(logger, "printMsgs()");
  19. LOG4CPLUS_WARN(logger, "printMsgs()");
  20. LOG4CPLUS_ERROR(logger, "printMsgs()");
  21. }
  22. int
  23. main()
  24. {
  25. tcout << LOG4CPLUS_TEXT("Entering main()...") << endl;
  26. LogLog::getLogLog()->setInternalDebugging(true);
  27. Logger root = Logger::getRoot();
  28. try
  29. {
  30. ConfigureAndWatchThread configureThread(
  31. LOG4CPLUS_TEXT("log4cplus.properties"), 5 * 1000);
  32. LOG4CPLUS_WARN(root, "Testing....");
  33. for(int i=0; i<100; ++i) {
  34. printMsgs(log_1);
  35. printMsgs(log_2);
  36. printMsgs(log_3);
  37. log4cplus::helpers::sleep(1);
  38. }
  39. }
  40. catch(...) {
  41. tcout << LOG4CPLUS_TEXT("Exception...") << endl;
  42. LOG4CPLUS_FATAL(root, "Exception occured...");
  43. }
  44. tcout << LOG4CPLUS_TEXT("Exiting main()...") << endl;
  45. return 0;
  46. }