-
Notifications
You must be signed in to change notification settings - Fork 2
/
tools.cpp
84 lines (73 loc) · 1.75 KB
/
tools.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
#include <stdio.h>
#include <stdarg.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <time.h>
#include "include/tools.h"
#include "include/config.h"
using namespace std;
using std::map;
using std::string;
tools_t::tools_t(void)
{
//debug_out(info,"Initializing configuration files");
}
void tools_t::debug_out(int type, const char* msg, ...)
{
config_t * a_config = config_t::getInstance();
map<string,string> config=a_config->get_config();
a_debug = ::atoi(config["debug"].c_str());
if ((type == debug) && (a_debug <1)) return;
if ((type == verbose) && (a_debug<2)) return;
if ((type == all) && (a_debug<3)) return;
FILE * log;
log = fopen ("Resources/plugins/xcontrol/xlog.txt","a");
va_list ap;
va_start(ap, msg);
time_t rawtime = time(&rawtime);
struct tm * timeinfo = localtime(&rawtime);
char time[80];
strftime(time,80,"%Y-%m-%d %H:%I:%S",timeinfo);
fprintf(log,"[%s]",time);
switch (type)
{
case all:
fprintf(log, " [all] ");
break;
case verbose:
fprintf(log, " [verbose] ");
break;
case debug:
fprintf(log, " [debug] ");
break;
case info:
fprintf(log, " [info] ");
break;
case warn:
fprintf(log, " [warn] ");
break;
case err:
default:
fprintf(log, "[ err] ");
break;
}
vfprintf(log, msg, ap);
fprintf(log, "\n");
va_end(ap);
fflush(log);
fclose(log);
}
void tools_t::debug_out(const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
FILE * log;
log = fopen ("Resources/plugins/xcontrol/xlog.txt","a");
fprintf(log, "[control]: ");
vfprintf(log, msg, ap);
fprintf(log, "\n");
va_end(ap);
fflush(log);
fclose(log);
}