-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitlog.hpp
63 lines (52 loc) · 1.13 KB
/
gitlog.hpp
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
namespace gitlog{
#include<bits/stdc++.h>
#include<fstream>
#include<ctime>
using namespace std;
string logpath;
char cwd[PATH_MAX];
string getcurrtime(){
time_t curr_time;
curr_time = time(NULL);
tm *tm_local = localtime(&curr_time);
string t ="";
string thour = to_string(tm_local->tm_hour);
string tmin = to_string(tm_local->tm_min);
string tsec = to_string(tm_local->tm_sec);
t += thour+":"+tmin + ":"+tsec;
return t;
}
void setlogpath(){
if(getcwd(cwd,sizeof(cwd))!=NULL){
logpath=cwd;
logpath+="/.mygit/";
logpath += "gitlog.txt";
}
else {
perror("Unable to get current working directory!\n");
exit(1);
}
}
void writeinlog(string logdetails){
std::ofstream flog;
setlogpath();
cout<<logpath<<endl;
flog.open(logpath,std::ios::app);
string currtime = getcurrtime();
cout<<currtime<<endl;
flog<<currtime<<":"<<logdetails<<endl;
flog.close();
}
void printlog(){
ifstream flog ;
string line;
setlogpath();
flog.open(logpath,ios::in);
while(flog){
getline(flog , line);
cout<<line<<endl;
}
flog.close();
}
}
}