-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwater_log.cpp
More file actions
69 lines (56 loc) · 1.2 KB
/
water_log.cpp
File metadata and controls
69 lines (56 loc) · 1.2 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
#include "water_log.h"
#include "string.h"
#include <iostream>
#include "common_api.h"
//#include "sagitdef.h"
using namespace std;
const unsigned max_buf_length = 2048;
char g_wr_buf[max_buf_length] = {0};
CWaterLog* CWaterLog::m_instance = NULL;
CWaterLog* CWaterLog::Instance()
{
if (NULL == m_instance)
{
m_instance = new CWaterLog();
}
return m_instance;
}
void CWaterLog::Destance()
{
if (NULL != m_instance)
{
delete m_instance;
}
m_instance = NULL;
}
CWaterLog::CWaterLog ()
{
}
CWaterLog::~CWaterLog ()
{
}
void CWaterLog::WriteLog(timeval& op_time, int op, char* ip, unsigned port, int ret, char* data)
{
string opString;
if(op == 0)
{
opString = string("Recv");
}
else if(op == 1)
{
opString = string("Send");
}
else
{
opString = string("What");
}
m_log.log_p(0, "[%s] | OP:%s | IP:%s | Port:%u | ret:%d | data:%s\n"
, GetFormatTime(op_time).c_str(), opString.c_str(), ip, port, ret, data);
}
int CWaterLog::Init (const string &path, const string &file_prex, unsigned max_size, unsigned max_num)
{
int log_level = 0;
int log_type = LOG_TYPE_DAILY;
return m_log.open(log_level, log_type, (char*)path.c_str(), (char*)file_prex.c_str()
, max_size, max_num);
}