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.

89 lines
2.5 KiB

  1. // -*- C++ -*-
  2. // Module: LOG4CPLUS
  3. // File: log4judpappender.h
  4. // Created: 7/2012
  5. // Author: Siva Chandran P
  6. //
  7. //
  8. // Copyright 2012 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. *
  35. * <li>Remote logging is non-intrusive as far as the log event
  36. * is concerned. In other words, the event will be logged with
  37. * the same time stamp, NDC, location info as if it were logged
  38. * locally by the client.</li>
  39. *
  40. * <li>Log4jUdpAppender do not use a layout.</li>
  41. *
  42. * <li>Remote logging uses the UDP protocol.</li>
  43. * </ul>
  44. *
  45. * <h3>Properties</h3>
  46. * <dl>
  47. * <dt><tt>host</tt></dt>
  48. * <dd>Remote host name to connect and send events to.</dd>
  49. *
  50. * <dt><tt>port</tt></dt>
  51. * <dd>Port on remote host to send events to.</dd>
  52. *
  53. * </dl>
  54. */
  55. class LOG4CPLUS_EXPORT Log4jUdpAppender : public Appender {
  56. public:
  57. // Ctors
  58. Log4jUdpAppender(const log4cplus::tstring& host, int port);
  59. Log4jUdpAppender(const log4cplus::helpers::Properties & properties);
  60. // Dtor
  61. ~Log4jUdpAppender();
  62. // Methods
  63. virtual void close();
  64. protected:
  65. void openSocket();
  66. virtual void append(const spi::InternalLoggingEvent& event);
  67. // Data
  68. log4cplus::helpers::Socket socket;
  69. log4cplus::tstring host;
  70. int port;
  71. private:
  72. // Disallow copying of instances of this class
  73. Log4jUdpAppender(const Log4jUdpAppender&);
  74. Log4jUdpAppender& operator=(const Log4jUdpAppender&);
  75. };
  76. } // end namespace log4cplus
  77. #endif // LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_