Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / APG / Logging / Callback-3.h
blobebba8d4ce17f3cb1af6648bcb15a9074f927dec4
1 #ifndef APG_CALLBACK3_H
2 #define APG_CALLBACK3_H
4 #include "ace/streams.h"
5 #include "ace/CDR_Stream.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/Log_Msg_Callback.h"
8 #include "ace/Log_Record.h"
9 #include "ace/SOCK_Stream.h"
10 #include "ace/SOCK_Connector.h"
11 #include "ace/INET_Addr.h"
13 #define LOGGER_PORT 20009
15 class Callback : public ACE_Log_Msg_Callback
17 public:
18 Callback ()
20 this->logger_ = new ACE_SOCK_Stream;
21 ACE_SOCK_Connector connector;
22 ACE_INET_Addr addr (LOGGER_PORT, ACE_DEFAULT_SERVER_HOST);
24 if (connector.connect (*(this->logger_), addr) == -1)
26 delete this->logger_;
27 this->logger_ = 0;
31 virtual ~Callback ()
33 if (this->logger_)
35 this->logger_->close ();
37 delete this->logger_;
40 void log (ACE_Log_Record &log_record)
42 if (!this->logger_)
44 # if defined (ACE_LACKS_IOSTREAM_TOTALLY)
45 log_record.print (ACE_TEXT (""), ACE_Log_Msg::VERBOSE, stderr);
46 # else
47 log_record.print(ACE_TEXT (""), ACE_Log_Msg::VERBOSE, cerr);
48 # endif /* ACE_LACKS_IOSTREAM_TOTALLY */
49 return;
52 ACE_OutputCDR cdr;
53 cdr << log_record;
54 if (this->logger_->send_n (cdr.begin ()) == -1)
56 delete this->logger_;
57 this->logger_ = 0;
61 private:
62 ACE_SOCK_Stream *logger_;
65 #endif /* APG_CALLBACK3_H */