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.

118 lines
3.4 KiB

  1. // -*- C++ -*-
  2. // Module: Log4CPLUS
  3. // File: syslogappender.h
  4. // Created: 6/2001
  5. // Author: Tad E. Smith
  6. //
  7. //
  8. // Copyright 2001-2013 Tad E. Smith
  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_SYSLOG_APPENDER_HEADER_
  23. #define LOG4CPLUS_SYSLOG_APPENDER_HEADER_
  24. #include <log4cplus/config.hxx>
  25. #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
  26. #pragma once
  27. #endif
  28. #include <log4cplus/appender.h>
  29. #include <log4cplus/helpers/socket.h>
  30. namespace log4cplus
  31. {
  32. /**
  33. * Appends log events to a file.
  34. *
  35. * <h3>Properties</h3>
  36. * <dl>
  37. * <dt><tt>ident</tt></dt>
  38. * <dd>First argument to <code>openlog()</code>, a string that
  39. * will be prepended to every message.</dd>
  40. *
  41. * <dt><tt>facility</tt></dt>
  42. * <dd>Facility is used in combination with syslog level in first
  43. * argument to syslog(). It can be one of the supported facility
  44. * names (case insensitive), e.g. auth, cron, kern, mail, news
  45. * etc.</dd>
  46. *
  47. * <dt><tt>host</tt></dt>
  48. * <dd>Destination syslog host. When this property is specified,
  49. * messages are sent using UDP to destination host, otherwise
  50. * messages are logged to local syslog.</dd>
  51. *
  52. * <dt><tt>port</tt></dt>
  53. * <dd>Destination port of syslog service on host specified by the
  54. * <tt>host</tt> property. The default value is port 514.</dd>
  55. * </dl>
  56. *
  57. * \note Messages sent to remote syslog using UDP are conforming
  58. * to RFC5424.
  59. */
  60. class LOG4CPLUS_EXPORT SysLogAppender : public Appender {
  61. public:
  62. // Ctors
  63. #if defined (LOG4CPLUS_HAVE_SYSLOG_H)
  64. SysLogAppender(const tstring& ident);
  65. #endif
  66. SysLogAppender(const tstring& ident, const tstring & host,
  67. int port = 514, const tstring & facility = tstring ());
  68. SysLogAppender(const log4cplus::helpers::Properties & properties);
  69. // Dtor
  70. virtual ~SysLogAppender();
  71. // Methods
  72. virtual void close();
  73. protected:
  74. virtual int getSysLogLevel(const LogLevel& ll) const;
  75. virtual void append(const spi::InternalLoggingEvent& event);
  76. #if defined (LOG4CPLUS_HAVE_SYSLOG_H)
  77. void appendLocal(const spi::InternalLoggingEvent& event);
  78. #endif
  79. void appendRemote(const spi::InternalLoggingEvent& event);
  80. // Data
  81. tstring ident;
  82. int facility;
  83. typedef void (SysLogAppender:: * AppendFuncType) (
  84. const spi::InternalLoggingEvent&);
  85. AppendFuncType appendFunc;
  86. tstring host;
  87. int port;
  88. helpers::Socket syslogSocket;
  89. static tstring const remoteTimeFormat;
  90. private:
  91. // Disallow copying of instances of this class
  92. SysLogAppender(const SysLogAppender&);
  93. SysLogAppender& operator=(const SysLogAppender&);
  94. std::string identStr;
  95. tstring hostname;
  96. };
  97. } // end namespace log4cplus
  98. #endif // LOG4CPLUS_SYSLOG_APPENDER_HEADER_