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.

54 lines
1.8 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. LogLog::getLogLog()->setInternalDebugging(true);
  16. try {
  17. SharedObjectPtr<Appender> append_1(new ConsoleAppender());
  18. append_1->setName(LOG4CPLUS_TEXT("First"));
  19. append_1->setLayout( std::auto_ptr<Layout>(new log4cplus::TTCCLayout()) );
  20. Logger::getRoot().addAppender(append_1);
  21. Logger logger = Logger::getInstance(LOG4CPLUS_TEXT("test"));
  22. log4cplus::tcout << "Logger: " << logger.getName() << endl;
  23. getNDC().push(LOG4CPLUS_TEXT("tsmith"));
  24. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This is a short test..."));
  25. getNDC().push(LOG4CPLUS_TEXT("password"));
  26. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should have my password now"));
  27. getNDC().pop();
  28. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should NOT have my password now"));
  29. getNDC().pop_void ();
  30. cout << "Just returned from pop..." << endl;
  31. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("There should be no NDC..."));
  32. getNDC().push(LOG4CPLUS_TEXT("tsmith"));
  33. getNDC().push(LOG4CPLUS_TEXT("password"));
  34. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("This should have my password now"));
  35. getNDC().remove();
  36. LOG4CPLUS_DEBUG(logger, LOG4CPLUS_TEXT("There should be no NDC..."));
  37. }
  38. catch(...) {
  39. cout << "Exception..." << endl;
  40. Logger::getRoot().log(FATAL_LOG_LEVEL, LOG4CPLUS_TEXT("Exception occured..."));
  41. }
  42. cout << "Exiting main()..." << endl;
  43. return 0;
  44. }