-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLog.cpp
More file actions
86 lines (69 loc) · 1.37 KB
/
Log.cpp
File metadata and controls
86 lines (69 loc) · 1.37 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
#include <string.h>
#include "Log.h"
#include "platform.h"
static bool commonlib_logactive;
static char logfilename[512];
static bool log_mutex=false;
void LogStart(void)
{
strcpy(logfilename, platform_GetConfigDir());
strcat(logfilename, "log.txt");
//printf("logfile: %s", logfilename);
FILE *file;
file=fopen(logfilename, "w");
if(file)
fclose(file);
//else
// printf("error creating log.txt");
commonlib_logactive=true;
}
void LogPrint(const char *string, ...)
{
if(!commonlib_logactive)
return;
while(log_mutex) { Sleep(0); }
log_mutex=true;
FILE *file;
char temp[1024];
va_list args;
va_start(args, string);
vsprintf(temp, string, args);
va_end(args);
file=fopen(logfilename, "a");
if(file)
{
fprintf(file,"%s\n", temp);
fclose(file);
}
log_mutex=false;
}
void LogPrintf(const char *string, ...)
{
if(!commonlib_logactive)
return;
while(log_mutex) { Sleep(0); }
log_mutex=true;
FILE *file;
char temp[1024];
va_list args;
va_start(args, string);
vsprintf(temp, string, args);
va_end(args);
file=fopen(logfilename, "a");
if(file)
{
fprintf(file,"%s", temp);
fclose(file);
}
log_mutex=false;
}
void LogEnable()
{
LogPrint("Log enabled");
commonlib_logactive=true;
}
void LogDisable()
{
LogPrint("Log disabled");
commonlib_logactive=false;
}