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.

63 lines
2.3 KiB

  1. #include "log4cplus/logger.h"
  2. #include "log4cplus/consoleappender.h"
  3. #include "log4cplus/loglevel.h"
  4. #include <log4cplus/loggingmacros.h>
  5. #include <iomanip>
  6. #include <iostream>
  7. using namespace std;
  8. using namespace log4cplus;
  9. // Forward Declarations
  10. void writeLogMessage();
  11. int
  12. main()
  13. {
  14. cout << "Entering main()..." << endl;
  15. {
  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, "\nSetting 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, "\nSetting test to ERROR");
  34. test.setLogLevel(ERROR_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, "\nSetting 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()) << '\n');
  43. writeLogMessage();
  44. cout << "Returned from writeLogMessage()..." << endl;
  45. }
  46. cout << "REALLY exiting main()..." << endl;
  47. return 0;
  48. }