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.

86 lines
2.4 KiB

  1. // -*- C++ -*-
  2. // Module: LOG4CPLUS
  3. // File: log4judpappender.h
  4. // Created: 7/2012
  5. // Author: Siva Chandran P
  6. //
  7. //
  8. // Copyright 2012-2013 Siva Chandran P
  9. //
  10. // Licensed under the Apache License, Version 2.0 (the "License");
  11. // you may not use this file except in compliance with the License.
  12. // You may obtain a copy of the License at
  13. //
  14. // http://www.apache.org/licenses/LICENSE-2.0
  15. //
  16. // Unless required by applicable law or agreed to in writing, software
  17. // distributed under the License is distributed on an "AS IS" BASIS,
  18. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. // See the License for the specific language governing permissions and
  20. // limitations under the License.
  21. /** @file */
  22. #ifndef LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_
  23. #define LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #include <log4cplus/appender.h>
  26. #include <log4cplus/helpers/socket.h>
  27. namespace log4cplus {
  28. /**
  29. * Sends log events as Log4j XML to a remote a log server.
  30. *
  31. * The Log4jUdpAppender has the following properties:
  32. *
  33. * <ul>
  34. * <li>Remote logging is non-intrusive as far as the log event
  35. * is concerned. In other words, the event will be logged with
  36. * the same time stamp, NDC, location info as if it were logged
  37. * locally by the client.</li>
  38. *
  39. * <li>Remote logging uses the UDP protocol.</li>
  40. * </ul>
  41. *
  42. * <h3>Properties</h3>
  43. * <dl>
  44. * <dt><tt>host</tt></dt>
  45. * <dd>Remote host name to connect and send events to.</dd>
  46. *
  47. * <dt><tt>port</tt></dt>
  48. * <dd>Port on remote host to send events to.</dd>
  49. *
  50. * </dl>
  51. */
  52. class LOG4CPLUS_EXPORT Log4jUdpAppender : public Appender {
  53. public:
  54. // Ctors
  55. Log4jUdpAppender(const log4cplus::tstring& host, int port);
  56. Log4jUdpAppender(const log4cplus::helpers::Properties & properties);
  57. // Dtor
  58. ~Log4jUdpAppender();
  59. // Methods
  60. virtual void close();
  61. protected:
  62. void openSocket();
  63. virtual void append(const spi::InternalLoggingEvent& event);
  64. // Data
  65. log4cplus::helpers::Socket socket;
  66. log4cplus::tstring host;
  67. int port;
  68. private:
  69. // Disallow copying of instances of this class
  70. Log4jUdpAppender(const Log4jUdpAppender&);
  71. Log4jUdpAppender& operator=(const Log4jUdpAppender&);
  72. };
  73. } // end namespace log4cplus
  74. #endif // LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_