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
2.1 KiB

  1. #include <log4cplus/logger.h>
  2. #include <log4cplus/socketappender.h>
  3. #include <log4cplus/loglevel.h>
  4. #include <log4cplus/tstring.h>
  5. #include <log4cplus/thread/threads.h>
  6. #include <log4cplus/helpers/sleep.h>
  7. #include <log4cplus/loggingmacros.h>
  8. #include <iomanip>
  9. using namespace std;
  10. using namespace log4cplus;
  11. int
  12. main(int argc, char **argv)
  13. {
  14. log4cplus::helpers::sleep(1);
  15. tstring serverName = (argc > 1 ? LOG4CPLUS_C_STR_TO_TSTRING(argv[1]) : tstring());
  16. // tstring host = LOG4CPLUS_TEXT("192.168.2.10");
  17. tstring host = LOG4CPLUS_TEXT("192.168.2.169");
  18. SharedAppenderPtr append_1(new SocketAppender(host, 9998, serverName));
  19. append_1->setName( LOG4CPLUS_TEXT("First") );
  20. Logger::getRoot().addAppender(append_1);
  21. Logger root = Logger::getRoot();
  22. Logger test = Logger::getInstance( LOG4CPLUS_TEXT("socket.test") );
  23. LOG4CPLUS_DEBUG(root,
  24. "This is"
  25. << " a reall"
  26. << "y long message." << endl
  27. << "Just testing it out" << endl
  28. << "What do you think?");
  29. test.setLogLevel(NOT_SET_LOG_LEVEL);
  30. LOG4CPLUS_DEBUG(test, "This is a bool: " << true);
  31. LOG4CPLUS_INFO(test, "This is a char: " << 'x');
  32. LOG4CPLUS_INFO(test, "This is a short: " << static_cast<short>(-100));
  33. LOG4CPLUS_INFO(test, "This is a unsigned short: "
  34. << static_cast<unsigned short>(100));
  35. log4cplus::helpers::sleep(0, 500000);
  36. LOG4CPLUS_INFO(test, "This is a int: " << 1000);
  37. LOG4CPLUS_INFO(test, "This is a unsigned int: " << 1000u);
  38. LOG4CPLUS_INFO(test, "This is a long(hex): " << hex << 100000000l);
  39. LOG4CPLUS_INFO(test, "This is a unsigned long: " << 100000000ul);
  40. LOG4CPLUS_WARN(test, "This is a float: " << 1.2345f);
  41. LOG4CPLUS_ERROR(test,
  42. "This is a double: "
  43. << setprecision(15)
  44. << 1.2345234234);
  45. LOG4CPLUS_FATAL(test,
  46. "This is a long double: "
  47. << setprecision(15)
  48. << 123452342342.342L);
  49. return 0;
  50. }