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.

58 lines
1.9 KiB

  1. #include <log4cplus/logger.h>
  2. #include <log4cplus/consoleappender.h>
  3. #include <log4cplus/ndc.h>
  4. #include <log4cplus/helpers/loglog.h>
  5. #include <log4cplus/loggingmacros.h>
  6. #include <iostream>
  7. #include <string>
  8. using namespace std;
  9. using namespace log4cplus;
  10. using namespace log4cplus::helpers;
  11. int
  12. main()
  13. {
  14. cout << "Entering main()..." << endl;
  15. log4cplus::initialize ();
  16. LogLog::getLogLog()->setInternalDebugging(true);
  17. try {
  18. SharedObjectPtr<Appender> append_1(new ConsoleAppender());
  19. append_1->setName(LOG4CPLUS_TEXT("First"));
  20. append_1->setLayout(
  21. std::auto_ptr<Layout>(
  22. new log4cplus::PatternLayout(
  23. LOG4CPLUS_TEXT ("%-5p %c <%x> - %m%n"))));
  24. Logger::getRoot().addAppender(append_1);
  25. Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("test"));
  26. log4cplus::tcout << "Logger: " << logger.getName() << endl;
  27. getNDC().push(LOG4CPLUS_TEXT("tsmith"));
  28. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This is a short test..."));
  29. getNDC().push(LOG4CPLUS_TEXT("password"));
  30. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should have my password now"));
  31. getNDC().pop();
  32. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should NOT have my password now"));
  33. getNDC().pop_void ();
  34. cout << "Just returned from pop..." << endl;
  35. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("There should be no NDC..."));
  36. getNDC().push(LOG4CPLUS_TEXT("tsmith"));
  37. getNDC().push(LOG4CPLUS_TEXT("password"));
  38. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should have my password now"));
  39. getNDC().remove();
  40. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("There should be no NDC..."));
  41. }
  42. catch(...) {
  43. cout << "Exception..." << endl;
  44. Logger::getRoot().log(FATAL_LOG_LEVEL, LOG4CPLUS_TEXT("Exception occured..."));
  45. }
  46. cout << "Exiting main()..." << endl;
  47. return 0;
  48. }