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.

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