-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger.cpp
More file actions
56 lines (47 loc) · 1.29 KB
/
logger.cpp
File metadata and controls
56 lines (47 loc) · 1.29 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
#include <stdarg.h>
#include <stdlib.h>
#include "predef.h"
#include "logger.h"
//#include "network.h"
#include "utils.h"
void Logger::log(int camnum, const char* format, ...)
{
bool consolelog_enable = true;
//bool filelog_enable = (FILE_LOG & logtype) == 0 ? false : true; // define으로 제어
bool filelog_enable = MemDB::getInstance()->getBoolValue("filelog");
char buf[2048] = { 0, };
va_list ap;
va_start(ap, format);
vsprintf(buf, format, ap);
va_end(ap);
std::string ds = Utils::getCurrentDateTime();
if(camnum > -1)
ds = Utils::format_string("Camara[%d] ", camnum) + ds + buf + '\n';
else
ds = ds + buf + '\n';
if (filelog_enable)
{
FILE * fp = fopen("log.txt", "at");
if (fp == NULL) return;
fputs(ds.c_str(), fp);
fclose(fp);
}
if(consolelog_enable)
printf(ds.c_str());
#ifdef TESTBUILD
if (Network::getinstance()->getenable())
{
#define CLIENT_LOG_INFO 0x0a
#define CLIENT_LOG_WARN 0x0b
#define CLIENT_LOG_ERR 0x0c
char packet = CLIENT_LOG_INFO;
if(logtype == LOG_INFO)
packet = CLIENT_LOG_INFO;
else if (logtype == LOG_WARN)
packet = CLIENT_LOG_WARN;
else if (logtype == LOG_ERR)
packet = CLIENT_LOG_ERR;
Network::getinstance()->write(packet, (char*)ds.c_str(), ds.size());
}
#endif
}