-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogModule.cpp
More file actions
81 lines (62 loc) · 1.54 KB
/
LogModule.cpp
File metadata and controls
81 lines (62 loc) · 1.54 KB
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
#include "stdafx.h"
#include "LogModule.h"
unsigned LogModule::ModuleId = 0;
LogModule::LogModule()
{
m_pLogMgr = new LogMgr;
}
LogModule::~LogModule()
{
delete m_pLogMgr;
m_pLogMgr = nullptr;
}
void LogModule::install()
{
m_pLogMgr->start();
DWORD dwThreadId;
hThread = CreateThread( NULL, 0, logThread, this, 0, &dwThreadId );
if ( hThread == NULL )
{
m_pLogMgr->stop();
throw "Error: Create TickThread failed";
}
/*else
{
CloseHandle( hThread );
}*/
printf( "LogModule install succeed!\n" );
}
void LogModule::uninstall()
{
m_pLogMgr->stop();
::WaitForSingleObject( hThread, INFINITE );
CloseHandle( hThread );
hThread = nullptr;
printf( "LogModule uninstall succeed!\n" );
}
DWORD WINAPI LogModule::logThread( void* pParam )
{
LogModule* p_LogModule = (LogModule*)pParam;
LogMgr* m_plogmgr = p_LogModule->m_pLogMgr;
while ( m_plogmgr->isRunning == true )
{
m_plogmgr->logStream.open( m_plogmgr->logFileName, std::ofstream::app | std::ofstream::out );
while ( !m_plogmgr->m_lockList.IsEmpty() )
{
PLOG_STRUCT pLog_struct = m_plogmgr->m_lockList.pop();
m_plogmgr->logStream << "[MODULE]: " << pLog_struct->moduleName << ";\t"
<< "[TIME]: " << pLog_struct->time << ";\t"
<< "[DESC]: " << pLog_struct->logStr << ";\n\n";
delete pLog_struct;
pLog_struct = nullptr;
}
m_plogmgr->logStream.close();
Sleep( THREAD_SLEEP_TIME );
}
printf( "LogThread return\n" );
return 0;
}
void LogModule::push_log( std::string& strModuleName, std::string& p_strLog )
{
m_pLogMgr->push_log( strModuleName, p_strLog );
}