00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <CAlarmLogger.h>
00015 #include <stdio.h>
00016 #include <CDuplicateNameException.h>
00017 #include <CNoSuchObjectException.h>
00018
00027 CAlarmLogger::CAlarmLogger(string facility,
00028 string host = "localhost",
00029 string port = "daqalarm") :
00030 m_sFacility(facility),
00031 m_sHost(host)
00032 {
00033 if(port == "daqalarm") {
00034 struct servent* pServ = getservbyname("daqalarm", "tcp");
00035 if(pServ) {
00036 Int_t nPort = pServ->s_port;
00037 char port[4];
00038 sprintf(port, "%d", nPort);
00039 m_sPort = string(port);
00040 }
00041 else {
00042 m_sPort = "2702";
00043 }
00044 }
00045 }
00046
00053 CAlarmLogger::CAlarmLogger(const CAlarmLogger& aCAlarmLogger) :
00054 m_sFacility(aCAlarmLogger.m_sFacility),
00055 m_sHost(aCAlarmLogger.m_sHost),
00056 m_sPort(aCAlarmLogger.m_sPort)
00057 { }
00058
00063 CAlarmLogger::~CAlarmLogger()
00064 { }
00065
00098 void
00099 CAlarmLogger::Log(string message)
00100 {
00101
00102
00103
00104 string entry("Alarm::Log [list ");
00105 entry += m_sFacility + " " + message + "]\n";
00106 void* pBuf = (void*)entry.c_str();
00107
00108
00109
00110
00111 try {
00112 CSocket sock;
00113 sock.Connect(m_sHost, m_sPort);
00114 sock.Write(pBuf, entry.size());
00115 sock.Shutdown();
00116 }
00117 catch (CException& e) {
00118 cerr << "Caught exception while attempting to connect to host "
00119 << m_sHost << endl;
00120 cerr << "Reason was: " << e.ReasonText() << endl;
00121 cerr << e.WasDoing() << endl;
00122 }
00123 }