1:
2:
3: /**********************
4: * *
5: * COMPILER INCLUDES *
6: * *
7: **********************/
8:
9:
10: #include <cassert>
11: #include <iostream>
12: #include <syslog.h>
13: #include <sys/time.h>
14: #include <unistd.h>
15:
16:
17: /*********************
18: * *
19: * PROJECT INCLUDES *
20: * *
21: *********************/
22:
23:
24: #include "mindlog.h"
25: #include "wwwi/mutexholder.h"
26:
27:
28: using WWWI::MutexHolder;
29:
30:
31: /************************
32: * *
33: * MINDLOG CONSTRUCTOR *
34: * *
35: ************************/
36:
37:
38: MINDLog::MINDLog() {
39: m_lya = new LogPriority[(unsigned)LF_MAX];
40: m_smp = &std::cerr;
41: this->SetPriority(LY_DEBUG);
42: this->SetMethod(LM_TERMINAL);
43: }
44:
45:
46: /***************
47: * *
48: * METHOD LOG *
49: * *
50: ***************/
51:
52:
53: void MINDLog::Log(LogFacility i_lf, LogPriority i_ly, const char *i_strMessage) {
54: MutexHolder mh(&m_mx);
55: char strTime[128];
56: time_t tm;
57:
58: assert(i_strMessage!=NULL);
59: if (this->WouldLog(i_lf,i_ly)==false) return;
60: if (*i_strMessage==0) return;
61: switch(m_lm) {
62: case LM_TERMINAL:
63:
64: time(&tm);
65: strftime(strTime,128,"%b %d %H:%M:%S",localtime(&tm));
66: assert(m_smp!=NULL);
67: (*m_smp) << strTime << " mnamed[" << getpid() << "]: " << i_strMessage << endl;
68: break;
69: case LM_SYSLOG:
70: syslog(SyslogPri(i_ly),i_strMessage);
71: break;
72: default:
73: assert("Unknown log method!"==0);
74: }
75: }
76:
77:
78: /***********************
79: * *
80: * MINDLOG DESTRUCTOR *
81: * *
82: ***********************/
83:
84:
85: MINDLog::~MINDLog() {
86: FastLog(LF_OBJNEWDEL,LY_DEBUG,"MINDLog::~MINDLog()");
87: m_smp = NULL;
88: delete[] m_lya;
89: }
90:
91:
92: