-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
53 lines (44 loc) · 1.44 KB
/
Copy pathlog.cpp
File metadata and controls
53 lines (44 loc) · 1.44 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
/******************************************************************************/
/* */
/* */
/* Log.cpp by CanTale_Games */
/* */
/* */
/******************************************************************************/
#include "Log.h"
void Log::init(void)
{
mkdir(FOLDERPATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
logbook.open(LOGPATH, std::ifstream::trunc);
}
static std::string toString(long val)
{
std::ostringstream os;
os << val;
return (os.str());
}
std::string Log::getTimeAndDate(void)
{
struct timeval tv;
std::time_t currentTime = std::time(NULL);
std::string timeString = std::ctime(¤tTime);
std::string milliString(":");
std::string end("]\t");
std::string beg("[");
timeString.erase(timeString.length() - 6, timeString.length() - 1);
timeString.erase(0, 11);
gettimeofday(&tv, NULL);
milliString += toString(tv.tv_usec / 1000)
+ std::string("_") + toString(tv.tv_usec % 1000);
return (beg + timeString + milliString + end);
}
std::ofstream &Log::print(std::string color)
{
logbook << color;
return (logbook);
}
void Log::quit(void)
{
logbook << RESET;
logbook.close();
}