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.

61 lines
2.4 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. log4cplus::initialize ();
  16. SharedAppenderPtr append_1(new ConsoleAppender());
  17. append_1->setName(LOG4CPLUS_TEXT("First"));
  18. // append_1->setLayout( std::auto_ptr<Layout>(new TTCCLayout()) );
  19. cout << "Getting root logger...DONE" << endl;
  20. Logger::getRoot().addAppender(append_1);
  21. Logger root = Logger::getRoot();
  22. Logger test = Logger::getInstance(LOG4CPLUS_TEXT("test"));
  23. Logger subTest = Logger::getInstance(LOG4CPLUS_TEXT("test.subtest"));
  24. LogLevelManager& llm = getLogLevelManager();
  25. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  26. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  27. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()));
  28. LOG4CPLUS_FATAL(root, "Setting test.subtest to WARN");
  29. subTest.setLogLevel(WARN_LOG_LEVEL);
  30. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  31. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  32. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()));
  33. LOG4CPLUS_FATAL(root, "Setting test to CRITICAL");
  34. test.setLogLevel(CRITICAL_LOG_LEVEL);
  35. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  36. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  37. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()));
  38. LOG4CPLUS_FATAL(root, "Setting test.subtest to NOT_SET_LOG_LEVEL");
  39. subTest.setLogLevel(NOT_SET_LOG_LEVEL);
  40. LOG4CPLUS_FATAL(root, "root: " << llm.toString(root.getChainedLogLevel()));
  41. LOG4CPLUS_FATAL(root, "test: " << llm.toString(test.getChainedLogLevel()));
  42. LOG4CPLUS_FATAL(root, "test.subtest: " << llm.toString(subTest.getChainedLogLevel()));
  43. writeLogMessage();
  44. cout << "Returned from writeLogMessage()..." << endl;
  45. }
  46. cout << "REALLY exiting main()..." << endl;
  47. return 0;
  48. }