-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.c
104 lines (88 loc) · 2.93 KB
/
log.c
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/***************************************************************************
* Copyright (C) 2006-2009 by Dead_Body *
* jamesholodnak@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "system/file.h"
#include "log.h"
static FILE *logfd = 0;
#ifdef LOGGER
static char logfilename[1024] = "nesemu.log";
#endif
extern char curdir[];
void log_init()
{
#ifdef LOGGER
sprintf(logfilename,"%s/nesemu.log",curdir);
if(logfd)
return;
if((logfd = fopen(logfilename,"wt")) == 0) {
printf("error opening log file\n");
return;
}
#else
printf("logging disabled\n");
#endif
}
void log_kill()
{
if(logfd)
fclose(logfd);
logfd = 0;
}
void log_print(char *str)
{
//output message to console
printf(str);
//if log file isnt open, maybe logging is disabled or file isnt opened yet
if(logfd == 0)
return;
//write to log file
fputs(str,logfd);
//flush file
fflush(logfd);
}
void log_message(char *str,...)
{
char buffer[512]; //buffer to store vsprintf'd message in
va_list argptr; //argument data
va_start(argptr,str); //get data
vsprintf(buffer,str,argptr); //print to buffer
va_end(argptr); //done!
log_print(buffer);
}
void log_warning(char *str,...)
{
char buffer[512]; //buffer to store vsprintf'd message in
va_list argptr; //argument data
va_start(argptr,str); //get data
vsprintf(buffer,str,argptr); //print to buffer
va_end(argptr); //done!
log_message("error: %s",buffer);
}
void log_error(char *str,...)
{
char buffer[512]; //buffer to store vsprintf'd message in
va_list argptr; //argument data
va_start(argptr,str); //get data
vsprintf(buffer,str,argptr); //print to buffer
va_end(argptr); //done!
log_message("error: %s",buffer);
}