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 22 /** @file */ 23 24 #ifndef LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_ 25 #define LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_ 26 27 #include <log4cplus/config.hxx> 28 #include <log4cplus/appender.h> 29 #include <log4cplus/helpers/socket.h> 30 31 namespace log4cplus { 32 33 /** 34 * Sends log events as Log4j XML to a remote a log server. 35 * 36 * The Log4jUdpAppender has the following properties: 37 * 38 * <ul> 39 * <li>Remote logging is non-intrusive as far as the log event 40 * is concerned. In other words, the event will be logged with 41 * the same time stamp, NDC, location info as if it were logged 42 * locally by the client.</li> 43 * 44 * <li>Remote logging uses the UDP protocol.</li> 45 * </ul> 46 * 47 * <h3>Properties</h3> 48 * <dl> 49 * <dt><tt>host</tt></dt> 50 * <dd>Remote host name to connect and send events to.</dd> 51 * 52 * <dt><tt>port</tt></dt> 53 * <dd>Port on remote host to send events to.</dd> 54 * 55 * </dl> 56 */ 57 class LOG4CPLUS_EXPORT Log4jUdpAppender : public Appender { 58 public: 59 // Ctors 60 Log4jUdpAppender(const log4cplus::tstring& host, int port); 61 Log4jUdpAppender(const log4cplus::helpers::Properties & properties); 62 63 // Dtor 64 ~Log4jUdpAppender(); 65 66 // Methods 67 virtual void close(); 68 69 protected: 70 void openSocket(); 71 virtual void append(const spi::InternalLoggingEvent& event); 72 73 // Data 74 log4cplus::helpers::Socket socket; 75 log4cplus::tstring host; 76 int port; 77 78 private: 79 // Disallow copying of instances of this class 80 Log4jUdpAppender(const Log4jUdpAppender&); 81 Log4jUdpAppender& operator=(const Log4jUdpAppender&); 82 }; 83 } // end namespace log4cplus 84 85 #endif // LOG4CPLUS_LOG4J_UDP_APPENDER_HEADER_ 86 87