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