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.

50 lines
1.7 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. using namespace std;
  7. using namespace log4cplus;
  8. int
  9. main()
  10. {
  11. SharedAppenderPtr append_1(new ConsoleAppender());
  12. append_1->setName(LOG4CPLUS_TEXT("First"));
  13. Logger::getRoot().addAppender(append_1);
  14. Logger root = Logger::getRoot();
  15. Logger test = Logger::getInstance(LOG4CPLUS_TEXT("test"));
  16. LOG4CPLUS_DEBUG(root,
  17. "This is"
  18. << " a reall"
  19. << "y long message." << endl
  20. << "Just testing it out" << endl
  21. << "What do you think?");
  22. test.setLogLevel(NOT_SET_LOG_LEVEL);
  23. LOG4CPLUS_DEBUG(test, "This is a bool: " << true);
  24. LOG4CPLUS_INFO(test, "This is a char: " << 'x');
  25. LOG4CPLUS_INFO(test, "This is a short: " << static_cast<short>(-100));
  26. LOG4CPLUS_INFO(test, "This is a unsigned short: "
  27. << static_cast<unsigned short>(100));
  28. LOG4CPLUS_INFO(test, "This is a int: " << 1000);
  29. LOG4CPLUS_INFO(test, "This is a unsigned int: " << 1000u);
  30. LOG4CPLUS_INFO(test, "This is a long(hex): " << hex << 100000000l);
  31. LOG4CPLUS_INFO(test, "This is a unsigned long: " << 100000000ul);
  32. LOG4CPLUS_WARN(test, "This is a float: " << 1.2345f);
  33. LOG4CPLUS_ERROR(test,
  34. "This is a double: "
  35. << setprecision(15)
  36. << 1.2345234234);
  37. LOG4CPLUS_FATAL(test,
  38. "This is a long double: "
  39. << setprecision(15)
  40. << 123452342342.342L);
  41. LOG4CPLUS_WARN(test, "The following message is empty:");
  42. LOG4CPLUS_WARN(test, "");
  43. return 0;
  44. }