tcpip_appender.h

Go to the documentation of this file.
00001 
00008 /**************************************************************************
00009 
00010    begin                : Fri Sep 14 2007
00011    copyright            : (C) 2007 by Ewald Arnold
00012    email                : log4sendpp at ewald-arnold dot de
00013 
00014    This program is free software; you can redistribute it and/or modify
00015    it under the terms of the GNU Lesser General Public License as
00016    published by the Free Software Foundation; either version 2 of the License,
00017    or (at your option) any later version.
00018 
00019    This program is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022    GNU General Public License for more details.
00023 
00024    You should have received a copy of the GNU Lesser General Public License
00025    along with this program; if not, write to the Free Software
00026    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027 
00028  **/
00029 
00030 #ifndef LOG4SENDPP_TCPIP_APPENDER_H
00031 #define LOG4SENDPP_TCPIP_APPENDER_H
00032 
00033 #include <log4sendpp/log4sendpp.h>  // always first header
00034 
00035 #include <string>
00036 
00037 #include <log4sendpp/appender.h>
00038 
00039 
00040 LOG4SENDPP_NS_START
00041 
00042 
00045 class LOG4SENDPP_API_DECL0 TcpIpAppender : public Appender
00046 {
00047  public:
00048 
00054    TcpIpAppender(Formatter *formatter, const LOG4SENDPP_STD_NS::string &host, unsigned port = 4448);
00055 
00061    TcpIpAppender(Formatter *formatter, long adr, unsigned port = 4448);
00062 
00065    virtual ~TcpIpAppender();
00066 
00076     virtual void append (Logger::Level level,
00077                          LOG4SENDPP_STD_NS::string msg,
00078                          LOG4SENDPP_STD_NS::string category,
00079                          LOG4SENDPP_INT64 stamp,
00080                          const LocationInformation *loginfo,
00081                          const Logger::DiagnosticInformation *diaginfo);
00082 
00086     virtual void writeString(const LOG4SENDPP_STD_NS::string &data);
00087 
00091    virtual bool isWorking() const;
00092 
00097    static LOG4SENDPP_STD_NS::string gethostname();
00098 
00099   protected:
00100 
00103    void open();
00104 
00107    void close();
00108 
00109  private:
00110 
00114    void init (unsigned port);
00115 
00120    signed long low_level_write(char const *buff, long len);
00121 
00125    struct hostent * getHostAdress(const LOG4SENDPP_STD_NS::string &dom);
00126 
00130    void asciiToInAddr(const char *address, struct in_addr &saddr);
00131 
00135    static LOG4SENDPP_STD_NS::string getErrorString(int err_number);
00136 
00140    static int getLastError();
00141 
00142 #if defined(__WIN32__)  && !defined (LOG4SENDPP_NO_WSA_STARTUP)
00143 
00147    static void WSA_init();
00148 
00149 #endif
00150 
00151  private:
00152 
00153    struct Impl;
00154    Impl  *pimpl;
00155 
00156 #if defined(__WIN32__)  && !defined (LOG4SENDPP_NO_WSA_STARTUP)
00157    static bool WSA_is_initialized; 
00158 #endif
00159 };
00160 
00161 
00162 LOG4SENDPP_NS_END
00163 
00164 
00165 #endif // LOG4SENDPP_TCPIP_APPENDER_H
00166 

Generated on Sat Nov 24 14:41:22 2007 for log4sendpp by  doxygen 1.5.3