forked from shashankkumar/CodeRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogs.cpp
executable file
·74 lines (62 loc) · 1.69 KB
/
Logs.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
#include "Logs.h"
FILE * Logs::pLogFile;
time_t Logs::rawtime;
char Logs::curtime[100];
void Logs::OpenLogFile(){
pLogFile = fopen(LOGFILEPATH, "a");
if(pLogFile==NULL)printf("Cannot open log file for logging.");
}
void Logs::CloseLogFile(){
fclose(pLogFile);
}
void Logs::SetTime(){
time( &rawtime );
strcpy(curtime, ctime(&rawtime));
int l = strlen(curtime);
//curtime[l-5]='\0';
}
void Logs::SetAndPrintTime(){
time( &rawtime );
strcpy(curtime, ctime(&rawtime));
int l = strlen(curtime);
//curtime[l-5]='\0';
fwrite(curtime, 1, sizeof(curtime), pLogFile);
printf("%s", curtime);
}
void Logs::Write(const char* logs, bool PrintTime){
if(PrintTime) SetAndPrintTime();
fputs(logs, pLogFile);
printf("%s", logs);
}
void Logs::Write(char* logs, bool PrintTime){
if(PrintTime) SetAndPrintTime();
fputs(logs, pLogFile);
printf("%s", logs);
}
void Logs::WriteLine(const char* logs, bool PrintTime){
if(PrintTime) SetAndPrintTime();
fputs(logs, pLogFile);
fputs("\n", pLogFile);
printf("%s\n", logs);
}
void Logs::WriteLine(char* logs, bool PrintTime){
if(PrintTime) SetAndPrintTime();
//printf("\n%lu\n" , sizeof((*logs)));
fputs(logs, pLogFile);
fputs("\n", pLogFile);
printf("%s\n", logs);
}
void Logs::GoToSleep(){
char SleepText[50];;
sprintf(SleepText, "Going to sleep for %d seconds.\n", SLEEPINTERVAL);
Logs::WriteLine(SleepText);
Logs::WriteLine("============================================================================\n");
}
void Logs::CodeRunnerStarted(){
Logs::WriteLine("============================================================================\n");
Logs::WriteLine("CodeRunner Started", false);
Logs::LeaveLine();
}
void Logs::LeaveLine(){
Logs::WriteLine("");
}