-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathLog.cpp
executable file
·54 lines (52 loc) · 1.17 KB
/
Log.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
#include "Log.h"
#include <sys/stat.h>
#include "stdafx.h"
//================================================================================================//
/**************************
** global logging system **
***************************/
//================================================================================================//
Log gLog;
#define PRINT_TO_CONSOLE//if defined will print to the console aswell as the logfile
void Log::OutPut(string str)
{
char logpath[PATH_MAX];
#ifdef AMIGAOS4
snprintf(logpath, PATH_MAX, "%s.prototype/Logfile.txt", "PROGDIR:");
#else
snprintf(logpath, PATH_MAX, "%s/.prototype/Logfile.txt", getenv("HOME"));
#endif
if(!bKeepLog)
return;
#ifdef PRINT_TO_CONSOLE
printf(str.c_str());
#endif
ofstream f;
if(!lcount)
{
f.open(logpath);
f << "Logfile created on " << __DATE__ << endl;
}
else
f.open(logpath,ios::app);
if(f.is_open())
{
f << str.c_str();
f.close();
}
lcount++;
}
void Log::SetLogState(int state)
{
bool l = state?true:false;
if(l && !bKeepLog)
{
bKeepLog = l;
OutPut(">>Logging Enabled<<\n");
}
else if(!l && bKeepLog)
{
bKeepLog = l;
OutPut(">>Logging Disabled<<\n");
}
}