Skip to content

Commit 02b7dd7

Browse files
committed
https://github.com/kbengine/kbengine/issues/195
messagelog需要将不同服务组的日志区分输出到文件,同一台机器上可能有几组服务端在跑
1 parent 982e092 commit 02b7dd7

File tree

4 files changed

+61
-10
lines changed

4 files changed

+61
-10
lines changed

kbe/src/server/tools/guiconsole/LogWindow.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "guiconsole.h"
66
#include "LogWindow.h"
77
#include "guiconsoleDlg.h"
8+
#include "common/common.h"
89
#include "../../../server/tools/message_log/messagelog_interface.h"
910
// CLogWindow dialog
1011

@@ -287,31 +288,39 @@ void CLogWindow::onReceiveRemoteLog(std::string str, bool fromServer)
287288
s.Replace(L"\n\r", L"");
288289
s.Replace(L"\r", L"");
289290

290-
if(s.Find(L"WARNING") >= 0 || s.Find(L"S_WARN") >= 0)
291+
std::vector<std::wstring> logSplit;
292+
KBEngine::strutil::kbe_split<wchar_t>(s.GetBuffer(0), L' ', logSplit);
293+
294+
if(logSplit.size() == 0)
295+
return;
296+
297+
s.Replace((logSplit[2] + L" " + logSplit[3]).c_str(), L"");
298+
299+
if(logSplit[0] == L"WARNING" || logSplit[0] == L"S_WARN")
291300
{
292301
if(fromServer)
293302
m_warnCount++;
294303

295304
if(m_warnChecked)
296305
m_loglist.AddString(s, RGB(0, 0, 0), RGB(255, 165, 0));
297306
}
298-
else if(s.Find(L"ERROR") >= 0 || s.Find(L"S_ERR") >= 0)
307+
else if(logSplit[0] == L"ERROR" || logSplit[0] == L"S_ERR")
299308
{
300309
if(fromServer)
301310
m_errCount++;
302311

303312
if(m_errChecked)
304313
m_loglist.AddString(s, RGB(0, 0, 0), RGB(255, 0, 0));
305314
}
306-
else if(s.Find(L"CRITICAL") >= 0)
315+
else if(logSplit[0] == L"CRITICAL")
307316
{
308317
if(fromServer)
309318
m_errCount++;
310319

311320
if(m_errChecked)
312321
m_loglist.AddString(s, RGB(0, 0, 0), RGB(100, 149, 237));
313322
}
314-
else if(s.Find(L"S_DBG") >= 0 || s.Find(L"S_NORM") >= 0 || s.Find(L"S_INFO") >= 0)
323+
else if(logSplit[0] == L"S_DBG" || logSplit[0] == L"S_NORM" || logSplit[0] == L"S_INFO")
315324
{
316325
if(fromServer)
317326
m_infoCount++;
@@ -371,7 +380,7 @@ void CLogWindow::pullLogs(KBEngine::Network::Address addr)
371380
Network::Bundle bundle;
372381
bundle.newMessage(MessagelogInterface::registerLogWatcher);
373382

374-
int32 uid = 0;
383+
int32 uid = dlg->getSelTreeItemUID();
375384
bundle << uid;
376385

377386
bundle << getSelLogTypes();
@@ -601,7 +610,8 @@ void CLogWindow::updateSettingToServer()
601610
Network::Bundle bundle;
602611
bundle.newMessage(MessagelogInterface::updateLogWatcherSetting);
603612

604-
int32 uid = 0;
613+
CguiconsoleDlg* dlg = static_cast<CguiconsoleDlg*>(theApp.m_pMainWnd);
614+
int32 uid = dlg->getSelTreeItemUID();
605615
bundle << uid;
606616

607617
bundle << getSelLogTypes();
@@ -644,7 +654,6 @@ void CLogWindow::updateSettingToServer()
644654
bundle << (*iter);
645655
}
646656

647-
CguiconsoleDlg* dlg = static_cast<CguiconsoleDlg*>(theApp.m_pMainWnd);
648657
HTREEITEM item = dlg->hasCheckApp(MESSAGELOG_TYPE);
649658
if(item == NULL)
650659
{

kbe/src/server/tools/guiconsole/guiconsoleDlg.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,46 @@ COMPONENT_TYPE CguiconsoleDlg::getTreeItemComponent(HTREEITEM hItem)
12401240
return UNKNOWN_COMPONENT_TYPE;
12411241
}
12421242

1243+
int32 CguiconsoleDlg::getSelTreeItemUID()
1244+
{
1245+
HTREEITEM hItem = m_tree.GetSelectedItem();
1246+
if(hItem == NULL)
1247+
return 0;
1248+
1249+
CString s = m_tree.GetItemText(hItem);
1250+
if(s.Find(L"uid[") >= 0)
1251+
{
1252+
s.Replace(L"uid[", L"");
1253+
s.Replace(L"]", L"");
1254+
}
1255+
else
1256+
{
1257+
hItem = m_tree.GetParentItem(hItem);
1258+
if(hItem == NULL)
1259+
return 0;
1260+
1261+
s = m_tree.GetItemText(hItem);
1262+
if(s.Find(L"uid[") >= 0)
1263+
{
1264+
s.Replace(L"uid[", L"");
1265+
s.Replace(L"]", L"");
1266+
}
1267+
else
1268+
{
1269+
s = L"";
1270+
}
1271+
}
1272+
1273+
if(s.GetLength() == 0)
1274+
return 0;
1275+
1276+
char* buf = KBEngine::strutil::wchar2char(s.GetBuffer(0));
1277+
int32 uid = atoi(buf);
1278+
free(buf);
1279+
1280+
return uid;
1281+
}
1282+
12431283
Network::Address CguiconsoleDlg::getTreeItemAddr(HTREEITEM hItem)
12441284
{
12451285
if(hItem == NULL)
@@ -1273,6 +1313,7 @@ Network::Address CguiconsoleDlg::getTreeItemAddr(HTREEITEM hItem)
12731313

12741314
char* buf = KBEngine::strutil::wchar2char(s.GetBuffer(0));
12751315
std::string sbuf = buf;
1316+
free(buf);
12761317

12771318
std::string::size_type i = sbuf.find("[");
12781319
std::string::size_type j = sbuf.find("]");

kbe/src/server/tools/guiconsole/guiconsoleDlg.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class CguiconsoleDlg : public CDialog
5959
void closeCurrTreeSelChannel();
6060
Network::Address getTreeItemAddr(HTREEITEM hItem);
6161
COMPONENT_TYPE getTreeItemComponent(HTREEITEM hItem);
62-
62+
int32 getSelTreeItemUID();
63+
6364
bool hasTreeComponent(Components::ComponentInfos& cinfos);
6465

6566
void onReceiveRemoteLog(std::string str);

kbe/src/server/tools/message_log/logwatcher.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ void LogWatcher::onMessage(LOG_ITEM* pLogItem)
104104
if(!VALID_COMPONENT(pLogItem->componentType) || filterOptions_.componentBitmap[pLogItem->componentType] == 0)
105105
return;
106106

107-
//if(filterOptions_.uid != pLogItem->uid)
108-
// return;
107+
if(filterOptions_.uid != pLogItem->uid)
108+
return;
109109

110110
if((filterOptions_.logtypes & pLogItem->logtype) <= 0)
111111
return;

0 commit comments

Comments
 (0)