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.

62 lines
2.2 KiB

  1. #include "customloglevel.h"
  2. #include <log4cplus/consoleappender.h>
  3. #include <log4cplus/loggingmacros.h>
  4. #include <iomanip>
  5. #include <iostream>
  6. using namespace std;
  7. using namespace log4cplus;
  8. // Forward Declarations
  9. void writeLogMessage();
  10. int
  11. main()
  12. {
  13. cout << "Entering main()..." << endl;
  14. {
  15. SharedAppenderPtr append_1(new ConsoleAppender());
  16. append_1->setName(LOG4CPLUS_TEXT("First"));
  17. // append_1->setLayout( std::auto_ptr<Layout>(new TTCCLayout()) );
  18. cout << "Getting root logger...DONE" << endl;
  19. Logger::getRoot().addAppender(append_1);
  20. Logger root = Logger::getRoot();
  21. Logger test = Logger::getInstance(LOG4CPLUS_TEXT("test"));
  22. Logger subTest = Logger::getInstance(LOG4CPLUS_TEXT("test.subtest"));
  23. LogLevelManager& llm = getLogLevelManager();
  24. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  25. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  26. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()));
  27. LOG4CPLUS_FATAL(root, "\nSetting test.subtest to WARN");
  28. subTest.setLogLevel(WARN_LOG_LEVEL);
  29. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  30. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  31. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()));
  32. LOG4CPLUS_FATAL(root, "\nSetting test to CRITICAL");
  33. test.setLogLevel(CRITICAL_LOG_LEVEL);
  34. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  35. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  36. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()));
  37. LOG4CPLUS_FATAL(root, "\nSetting test.subtest to NOT_SET_LOG_LEVEL");
  38. subTest.setLogLevel(NOT_SET_LOG_LEVEL);
  39. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  40. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  41. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()) << '\n');
  42. writeLogMessage();
  43. cout << "Returned from writeLogMessage()..." << endl;
  44. }
  45. cout << "REALLY exiting main()..." << endl;
  46. return 0;
  47. }