log4judpappender.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // -*- C++ -*-
  2. // Module: LOG4CPLUS
  3. // File: log4judpappender.h
  4. // Created: 7/2012
  5. // Author: Siva Chandran P
  6. //
  7. //
  8. // Copyright 2012-2017 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. Default is 5000.</dd>
  49. *
  50. * <dt><tt>IPv6</tt></dt>
  51. * <dd>Boolean value specifying whether to use IPv6 (true) or IPv4
  52. * (false). Default value is false.</dd>
  53. *
  54. * </dl>
  55. */
  56. class LOG4CPLUS_EXPORT Log4jUdpAppender : public Appender {
  57. public:
  58. // Ctors
  59. Log4jUdpAppender(const log4cplus::tstring& host, int port,
  60. bool ipv6 = false);
  61. Log4jUdpAppender(const log4cplus::helpers::Properties & properties);
  62. // Dtor
  63. ~Log4jUdpAppender();
  64. // Methods
  65. virtual void close();
  66. protected:
  67. void openSocket();
  68. virtual void append(const spi::InternalLoggingEvent& event);
  69. // Data
  70. log4cplus::helpers::Socket socket;
  71. log4cplus::tstring host;
  72. int port;
  73. bool ipv6 = false;
  74. private:
  75. // Disallow copying of instances of this class
  76. Log4jUdpAppender(const Log4jUdpAppender&);
  77. Log4jUdpAppender& operator=(const Log4jUdpAppender&);
  78. };
  79. } // end namespace log4cplus
  80. #endif // LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_