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.

59 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::initialize ();
  15. log4cplus::helpers::sleep(1);
  16. tstring serverName = (argc > 1 ? LOG4CPLUS_C_STR_TO_TSTRING(argv[1]) : tstring());
  17. // tstring host = LOG4CPLUS_TEXT("192.168.2.10");
  18. tstring host = LOG4CPLUS_TEXT("192.168.2.169");
  19. SharedAppenderPtr append_1(new SocketAppender(host, 9998, serverName));
  20. append_1->setName( LOG4CPLUS_TEXT("First") );
  21. Logger::getRoot().addAppender(append_1);
  22. Logger root = Logger::getRoot();
  23. Logger test = Logger::getInstance( LOG4CPLUS_TEXT("socket.test") );
  24. LOG4CPLUS_DEBUG(root,
  25. "This is"
  26. << " a reall"
  27. << "y long message." << endl
  28. << "Just testing it out" << endl
  29. << "What do you think?");
  30. test.setLogLevel(NOT_SET_LOG_LEVEL);
  31. LOG4CPLUS_DEBUG(test, "This is a bool: " << true);
  32. LOG4CPLUS_INFO(test, "This is a char: " << 'x');
  33. LOG4CPLUS_INFO(test, "This is a short: " << static_cast<short>(-100));
  34. LOG4CPLUS_INFO(test, "This is a unsigned short: "
  35. << static_cast<unsigned short>(100));
  36. log4cplus::helpers::sleep(0, 500000);
  37. LOG4CPLUS_INFO(test, "This is a int: " << 1000);
  38. LOG4CPLUS_INFO(test, "This is a unsigned int: " << 1000u);
  39. LOG4CPLUS_INFO(test, "This is a long(hex): " << hex << 100000000l);
  40. LOG4CPLUS_INFO(test, "This is a unsigned long: " << 100000000ul);
  41. LOG4CPLUS_WARN(test, "This is a float: " << 1.2345f);
  42. LOG4CPLUS_ERROR(test,
  43. "This is a double: "
  44. << setprecision(15)
  45. << 1.2345234234);
  46. LOG4CPLUS_FATAL(test,
  47. "This is a long double: "
  48. << setprecision(15)
  49. << 123452342342.342L);
  50. return 0;
  51. }