-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSS_LogManagerC.cpp
205 lines (184 loc) · 4.33 KB
/
SSS_LogManagerC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include "StdAfx.h"
#include "SSS_LogManagerC.h"
#include <stdlib.h>
#include "SSS_LogManagerU.h"
#include "LogProcess.h"
#include "MsgThread.h"
#define DEBUG_LOG_DK 1
#ifdef __Win32__
#define snprintf _snprintf
#else
#include "SSS_IniReader.h"
#endif
//class CSSS_LogManagerCInit
//{
//public:
// CSSS_LogManagerCInit();
// ~CSSS_LogManagerCInit();
//};
//
//static CSSS_LogManagerCInit sCSSS_LogManagerCInit;
//
//Xh_LogManager_PortMode CSSS_LogManagerC* pSSS_LogManagerC = NULL;
//CSSS_LogManagerCInit::CSSS_LogManagerCInit()
//{
// //printf("%s\n", __func__);
// if (pSSS_LogManagerC) {
// delete(pSSS_LogManagerC);
// pSSS_LogManagerC = NULL;
// }
// pSSS_LogManagerC = new CSSS_LogManagerC;
//}
//
//CSSS_LogManagerCInit::~CSSS_LogManagerCInit()
//{
// //printf("%s\n", __func__);
// if (pSSS_LogManagerC) {
// delete (pSSS_LogManagerC);
// pSSS_LogManagerC = NULL;
// }
//}
//////////////////////////////////////////////////////////////////////////
CSSS_LogManagerC::CSSS_LogManagerC()
{
m_bInitOk = false;
m_lkLog = new CAkCritSec;
CAkAutoLock lk(m_lkLog);
//IniReader* pIniReader = IniReader::GetShareInstance();
//char* theIniPath = "log.ini";
//if(pIniReader->Init(theIniPath) <= 0) {
// fprintf(stderr, "Read Ini File Failed!\n");
//}
m_pMsg = new char [LogMsgLen+10];
memset(m_pMsg, 0, LogMsgLen+10);
m_pLogMsg = new char [LogMsgLen+10];
memset(m_pLogMsg, 0, LogMsgLen+10);
m_pLog = new SBT_LogManagerU;
m_pLog->ConfigName("_log_default_");
m_nLogDebug = 0;
InitAKLogEnv();
m_bInitOk = true;
}
CSSS_LogManagerC::~CSSS_LogManagerC()
{
m_bInitOk = false;
{CAkAutoLock lk(m_lkLog);
UninitAKLogEnv();
if (m_pLog) {
delete m_pLog;
m_pLog = NULL;
}
if(m_pMsg){
delete [] m_pMsg;
m_pMsg = NULL;
}
if(m_pLogMsg){
delete [] m_pLogMsg;
m_pLogMsg = NULL;
}}
if (m_lkLog) {
delete (m_lkLog);
m_lkLog = NULL;
}
}
int CSSS_LogManagerC::InitAKLogEnv()
{
return 0;
}
int CSSS_LogManagerC::UninitAKLogEnv()
{
return 0;
}
int CSSS_LogManagerC::WriteLog(const int nLevel, const char * pErrMsg , ...)
{
if (!m_bInitOk) {
return 0;
}
CAkAutoLock lk(m_lkLog);
memset(m_pMsg, 0, LogMsgLen);
va_list arg_ptr;
va_start(arg_ptr, pErrMsg);
vsnprintf(m_pMsg, LogMsgLen, pErrMsg, arg_ptr);
va_end(arg_ptr);
switch (nLevel) {
case SSSDebug:
*m_pLog -m_pMsg -endl;
printf("%s\n", m_pMsg);
break;
case SSSError:
*m_pLog <<m_pMsg <<endl;
break;
case SSSWarning:
*m_pLog <m_pMsg <endl;
break;
case SSSProcess:
*m_pLog -m_pMsg -endl;
break;
case SSSScreen:
printf("%s\n", m_pMsg);
break;
default:
*m_pLog -m_pMsg -endl;
break;
}
return 0;
}
int CSSS_LogManagerC::WriteLog(const int nLevel, const char *pFile, int nLine, const char * pErrMsg , ...)
{
if (!m_bInitOk) {
return 0;
}
CAkAutoLock lk(m_lkLog);
memset(m_pMsg, 0, LogMsgLen);
memset(m_pLogMsg, 0, LogMsgLen);
va_list arg_ptr;
va_start(arg_ptr, pErrMsg);
vsnprintf(m_pMsg, LogMsgLen, pErrMsg, arg_ptr);
switch (m_nLogDebug) {
case 2:
snprintf(m_pLogMsg, LogMsgLen, "%s, %s:%d", m_pMsg, pFile, nLine);
fprintf(stderr, "%s", m_pLogMsg);
break;
case 1:
snprintf(m_pLogMsg, LogMsgLen, "%s, %s:%d", m_pMsg, pFile, nLine);
break;
case 0:
snprintf(m_pLogMsg, LogMsgLen, "%s", m_pMsg);
default:
break;
}
va_end(arg_ptr);
switch (nLevel) {
case SSSDebug:
*m_pLog -m_pLogMsg -endl;
printf("%s\n", m_pLogMsg);
break;
case SSSError:
*m_pLog <<m_pLogMsg <<endl;
break;
case SSSWarning:
*m_pLog <m_pLogMsg <endl;
break;
case SSSProcess:
*m_pLog -m_pLogMsg -endl;
break;
case SSSScreen:
printf("%s\n", m_pLogMsg);
break;
default:
*m_pLog -m_pLogMsg -endl;
break;
}
return 0 ;
}
int CSSS_LogManagerC::SetDebugLog(int nLevel)
{
CAkAutoLock lk(m_lkLog);
m_nLogDebug = nLevel;
return 0;
}
int CSSS_LogManagerC::ConfigName(const char* name)
{
m_pLog->ConfigName(name);
return 0;
}