/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/ZZLog.cpp
ViewVC logotype

Contents of /trunk/plugins/zzogl-pg/opengl/ZZLog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 273 - (show annotations) (download)
Fri Nov 12 01:10:22 2010 UTC (9 years, 7 months ago) by william
File size: 5237 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4013 local: v0.9.7.197-latest) in ./trunk
1 /* ZZ Open GL graphics plugin
2 * Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
3 * Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include <stdio.h>
21 #include "ZZLog.h"
22
23 extern GSconf conf;
24
25 namespace ZZLog
26 {
27 std::string s_strLogPath("logs/");
28 FILE *gsLog;
29
30 bool IsLogging()
31 {
32 // gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session.
33 // (GSinit won't have been called then)
34 return (gsLog != NULL && conf.log);
35 }
36
37 void Open()
38 {
39 const std::string LogFile(s_strLogPath + "GSzzogl.log");
40
41 gsLog = fopen(LogFile.c_str(), "w");
42 if (gsLog != NULL)
43 setvbuf(gsLog, NULL, _IONBF, 0);
44 else
45 SysMessage("Can't create log file %s\n", LogFile.c_str());
46
47 }
48
49 void Close()
50 {
51 if (gsLog != NULL) {
52 fclose(gsLog);
53 gsLog = NULL;
54 }
55 }
56
57 void SetDir(const char* dir)
58 {
59 // Get the path to the log directory.
60 s_strLogPath = (dir==NULL) ? "logs/" : dir;
61
62 // Reload previously open log file
63 if (gsLog) {
64 Close();
65 Open();
66 }
67 }
68
69 void WriteToScreen(const char* pstr, u32 ms)
70 {
71 ZeroGS::AddMessage(pstr, ms);
72 }
73
74 void _Message(const char *str)
75 {
76 SysMessage(str);
77 }
78
79 void _Log(const char *str)
80 {
81 if (IsLogging()) fprintf(gsLog, str);
82 }
83
84 void _WriteToConsole(const char *str)
85 {
86 fprintf(stderr,"ZZogl-PG: %s", str);
87 }
88
89 void _Print(const char *str)
90 {
91 fprintf(stderr,"ZZogl-PG: %s", str);
92
93 if (IsLogging()) fprintf(gsLog, str);
94 }
95
96 void Message(const char *fmt, ...)
97 {
98 va_list list;
99 char tmp[512];
100
101 va_start(list, fmt);
102 vsprintf(tmp, fmt, list);
103 va_end(list);
104
105 SysMessage(tmp);
106 }
107
108 void Log(const char *fmt, ...)
109 {
110 va_list list;
111
112 va_start(list, fmt);
113
114 if (IsLogging()) vfprintf(gsLog, fmt, list);
115
116 va_end(list);
117 }
118
119 void WriteToConsole(const char *fmt, ...)
120 {
121 va_list list;
122
123 va_start(list, fmt);
124
125 fprintf(stderr, "ZZogl-PG: ");
126 vfprintf(stderr, fmt, list);
127 va_end(list);
128 }
129
130 void Print(const char *fmt, ...)
131 {
132 va_list list;
133
134 va_start(list, fmt);
135
136 if (IsLogging()) vfprintf(gsLog, fmt, list);
137
138 fprintf(stderr, "ZZogl-PG: ");
139 vfprintf(stderr, fmt, list);
140
141 va_end(list);
142 }
143
144
145 void WriteLn(const char *fmt, ...)
146 {
147 va_list list;
148
149 va_start(list, fmt);
150
151 if (IsLogging()) vfprintf(gsLog, fmt, list);
152
153 fprintf(stderr, "ZZogl-PG: ");
154 vfprintf(stderr, fmt, list);
155 va_end(list);
156 fprintf(stderr,"\n");
157 }
158
159 void Greg_Log(const char *fmt, ...)
160 {
161 #if defined(WRITE_GREG_LOGS)
162 va_list list;
163 char tmp[512];
164
165 va_start(list, fmt);
166
167 if (IsLogging()) {
168 fprintf(gsLog, "GRegs: ");
169 vfprintf(gsLog, fmt, list);
170 }
171 //fprintf(stderr,"GRegs: ");
172 //vfprintf(stderr, fmt, list);
173
174 va_end(list);
175
176 if (IsLogging()) fprintf(gsLog, "\n");
177 //fprintf(stderr,"\n");
178 #endif
179 }
180
181 void Prim_Log(const char *fmt, ...)
182 {
183 #if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS)
184 va_list list;
185 char tmp[512];
186
187 va_start(list, fmt);
188
189 if (conf.log /*& 0x00000010*/)
190 {
191 if (IsLogging()) vfprintf(gsLog, fmt, list);
192
193 fprintf(stderr, "ZZogl-PG(PRIM): ");
194 vfprintf(stderr, fmt, list);
195
196 vprintf(fmt, list);
197 }
198
199 va_end(list);
200 fprintf(stderr,"\n");
201
202 #endif
203 }
204
205 void GS_Log(const char *fmt, ...)
206 {
207 #ifdef ZEROGS_DEVBUILD
208 va_list list;
209
210 va_start(list, fmt);
211
212 if (IsLogging())
213 {
214 vfprintf(gsLog, fmt, list);
215 fprintf(gsLog, "\n");
216 }
217
218 fprintf(stderr, "ZZogl-PG: ");
219 vfprintf(stderr, fmt, list);
220 fprintf(stderr, "\n");
221
222 va_end(list);
223 #endif
224 }
225
226 void Warn_Log(const char *fmt, ...)
227 {
228 #ifdef ZEROGS_DEVBUILD
229 va_list list;
230
231 va_start(list, fmt);
232
233 if (IsLogging())
234 {
235 vfprintf(gsLog, fmt, list);
236 fprintf(gsLog, "\n");
237 }
238
239 fprintf(stderr, "ZZogl-PG: ");
240 vfprintf(stderr, fmt, list);
241 fprintf(stderr, "\n");
242
243 va_end(list);
244 #endif
245 }
246
247 void Dev_Log(const char *fmt, ...)
248 {
249 #ifdef ZEROGS_DEVBUILD
250 va_list list;
251
252 va_start(list, fmt);
253
254 if (IsLogging())
255 {
256 vfprintf(gsLog, fmt, list);
257 fprintf(gsLog, "\n");
258 }
259
260 fprintf(stderr, "ZZogl-PG: ");
261 vfprintf(stderr, fmt, list);
262 fprintf(stderr, "\n");
263
264 va_end(list);
265 #endif
266 }
267
268 void Debug_Log(const char *fmt, ...)
269 {
270 #if _DEBUG
271 va_list list;
272
273 va_start(list, fmt);
274
275 if (IsLogging())
276 {
277 vfprintf(gsLog, fmt, list);
278 fprintf(gsLog, "\n");
279 }
280
281 fprintf(stderr, "ZZogl-PG: ");
282 vfprintf(stderr, fmt, list);
283 fprintf(stderr, "\n");
284
285 va_end(list);
286 #endif
287 }
288
289 void Error_Log(const char *fmt, ...)
290 {
291 va_list list;
292
293 va_start(list, fmt);
294
295 if (IsLogging())
296 {
297 vfprintf(gsLog, fmt, list);
298 fprintf(gsLog, "\n");
299 }
300
301 fprintf(stderr, "ZZogl-PG: ");
302 vfprintf(stderr, fmt, list);
303 fprintf(stderr, "\n");
304
305 va_end(list);
306 }
307 };

  ViewVC Help
Powered by ViewVC 1.1.22