-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.cpp
More file actions
164 lines (127 loc) · 2.65 KB
/
Copy pathLogger.cpp
File metadata and controls
164 lines (127 loc) · 2.65 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "system.h"
#include <GL/gl.h>
#include <stdio.h>
#include <fstream>
#include "Logger.h"
using namespace std;
namespace utils
{
GLint CLogger::indices = 0;
CLogger::CLogger()
{
}
CLogger::~CLogger()
{
}
DWORD st[100];
GLvoid CLogger::setEntryStart()
{
st[getNextFreeIndex()]=timeGetTime();
}
GLint CLogger::getNextFreeIndex()
{
return indices++;
}
GLint CLogger::getLastIndex()
{
return --indices;
}
GLvoid CLogger::setEntryEnd(const char *text, ...)
{
GLint ref = getLastIndex();
static bool first_line=true;
if (first_line)
{
#ifdef WIN32
SYSTEMTIME systime;
GetSystemTime(&systime);
#else
time_t currenttime;
struct tm *systime;
currenttime = time(NULL);
systime = localtime(¤ttime);
#endif
char date[100];
#ifdef WIN32
sprintf(date,"%d.%d.%d - %d:%d:%d",systime.wDay,systime.wMonth,systime.wYear,systime.wHour,systime.wMinute,systime.wSecond);
#else
strftime(date,sizeof(date),"%d.%m.%Y - %H:%M:%S",systime);
#endif
FILE *log_file=fopen("logger.log","wc");
if (!log_file)
{
return;
}
first_line=false;
char string[100];
sprintf(string,"New entry: %s\n------------------------------\n",date);
fwrite(string,1,strlen(string),log_file);
fclose(log_file);
}
char string[256];
va_list ap;
if (text == NULL)
{
return;
}
va_start(ap,text);
GLint string_length=vsprintf(string,text,ap);
va_end(ap);
FILE *log_file=fopen("logger.log","a");
if (!log_file)
{
return;
}
if (ref==-1)
{
string[string_length]='\n';
}
if (ref!=-1)
{
char line[256];
for (int i=0; i<256; i++)
{
line[i] = ' ';
}
for (int i=0; i<string_length; i++)
{
line[i] = string[i];
}
string_length=sprintf(string,"Time taken: %ld ms\n",timeGetTime()-st[ref]);
memcpy(line+64,string,string_length);
fwrite(line,1,string_length+64,log_file);
}
fclose(log_file);
}
GLvoid CLogger::addEntry(const char *text, ...)
{
char string[256];
va_list ap;
if (text == NULL)
{
return;
}
va_start(ap,text);
GLint string_length=vsprintf(string,text,ap);
va_end(ap);
FILE *log_file=fopen("logger.log","a");
if (!log_file)
{
return;
}
fwrite(string,1,string_length,log_file);
fclose(log_file);
}
GLvoid CLogger::getLog(vector<string> &log)
{
ifstream iFile;
iFile.open("logger.log",ios_base::in);
char line[512];
while (iFile.good())
{
iFile.getline(line,512,'\n');
log.push_back(string(line));
}
iFile.close();
}
};