00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef LOG4SENDPP_TCPIP_APPENDER_H
00031 #define LOG4SENDPP_TCPIP_APPENDER_H
00032
00033 #include <log4sendpp/log4sendpp.h>
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