|
a/src/utils/debuglog.cpp |
|
b/src/utils/debuglog.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: debuglog.cpp,v 1.5 2007-01-16 10:58:09 dockes Exp $ (C) 2006 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: debuglog.cpp,v 1.6 2008-12-16 14:20:10 dockes Exp $ (C) 2006 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
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
|
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
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
27 |
|
27 |
|
28 |
#ifdef INCLUDE_NEW_H
|
28 |
#ifdef INCLUDE_NEW_H
|
29 |
#include <new.h>
|
29 |
#include <new.h>
|
30 |
#endif
|
30 |
#endif
|
31 |
|
31 |
|
|
|
32 |
#include <string>
|
32 |
#include <stack>
|
33 |
#include <set>
|
|
|
34 |
#include <list>
|
|
|
35 |
using std::set;
|
|
|
36 |
using std::string;
|
|
|
37 |
using std::list;
|
33 |
|
38 |
|
34 |
#include "debuglog.h"
|
39 |
#include "debuglog.h"
|
|
|
40 |
#include "pathut.h"
|
|
|
41 |
#include "smallut.h"
|
35 |
|
42 |
|
36 |
#ifndef freeZ
|
43 |
#ifndef freeZ
|
37 |
#define freeZ(X) {if (X) {free(X);X=0;}}
|
44 |
#define freeZ(X) {if (X) {free(X);X=0;}}
|
38 |
#endif
|
45 |
#endif
|
39 |
|
46 |
|
|
... |
|
... |
150 |
int DebugLogFileWriter::put(const char *s)
|
157 |
int DebugLogFileWriter::put(const char *s)
|
151 |
{
|
158 |
{
|
152 |
return impl ? impl->put(s) : -1;
|
159 |
return impl ? impl->put(s) : -1;
|
153 |
};
|
160 |
};
|
154 |
|
161 |
|
155 |
|
162 |
static set<string> yesfiles;
|
|
|
163 |
static void initfiles()
|
|
|
164 |
{
|
|
|
165 |
const char *cp = getenv("DEBUGLOG_FILES");
|
|
|
166 |
if (!cp)
|
|
|
167 |
return;
|
|
|
168 |
list<string> files;
|
|
|
169 |
stringToTokens(cp, files, ",");
|
|
|
170 |
yesfiles.insert(files.begin(), files.end());
|
|
|
171 |
}
|
|
|
172 |
static bool fileInFiles(const string& file)
|
|
|
173 |
{
|
|
|
174 |
string sf = path_getsimple(file);
|
|
|
175 |
if (yesfiles.find(sf) != yesfiles.end()) {
|
|
|
176 |
//fprintf(stderr, "Debug ON: %s \n", file.c_str());
|
|
|
177 |
return true;
|
|
|
178 |
}
|
|
|
179 |
//fprintf(stderr, "Debug OFF: %s \n", file.c_str());
|
|
|
180 |
return false;
|
|
|
181 |
}
|
156 |
|
182 |
|
157 |
#ifdef _WINDOWS
|
183 |
#ifdef _WINDOWS
|
158 |
#include <windows.h>
|
184 |
#include <windows.h>
|
159 |
static void datestring(char *d) {
|
185 |
static void datestring(char *d) {
|
160 |
SYSTEMTIME buf;
|
186 |
SYSTEMTIME buf;
|
|
... |
|
... |
184 |
void
|
210 |
void
|
185 |
DebugLog::prolog(int lev, const char *f, int line)
|
211 |
DebugLog::prolog(int lev, const char *f, int line)
|
186 |
{
|
212 |
{
|
187 |
if (!writer)
|
213 |
if (!writer)
|
188 |
return;
|
214 |
return;
|
|
|
215 |
if (!yesfiles.empty() && !fileInFiles(f)) {
|
|
|
216 |
fileyes = false;
|
|
|
217 |
return;
|
|
|
218 |
} else {
|
|
|
219 |
fileyes = true;
|
|
|
220 |
}
|
189 |
if (dodate) {
|
221 |
if (dodate) {
|
190 |
char dts[100];
|
222 |
char dts[100];
|
191 |
datestring(dts);
|
223 |
datestring(dts);
|
192 |
writer->put(dts);
|
224 |
writer->put(dts);
|
193 |
}
|
225 |
}
|
|
... |
|
... |
208 |
}
|
240 |
}
|
209 |
|
241 |
|
210 |
void
|
242 |
void
|
211 |
DebugLog::log(const char *s ...)
|
243 |
DebugLog::log(const char *s ...)
|
212 |
{
|
244 |
{
|
213 |
if (!writer)
|
245 |
if (!writer || !fileyes)
|
214 |
return;
|
246 |
return;
|
215 |
va_list ap;
|
247 |
va_list ap;
|
216 |
va_start(ap,s);
|
248 |
va_start(ap,s);
|
217 |
|
249 |
|
218 |
#ifdef HAVE_VASPRINTF_nono // not sure vasprintf is really such a great idea
|
250 |
#ifdef HAVE_VASPRINTF_nono // not sure vasprintf is really such a great idea
|
|
... |
|
... |
306 |
}
|
338 |
}
|
307 |
DebugLog *dbl;
|
339 |
DebugLog *dbl;
|
308 |
if (!(dbl = (DebugLog *)pthread_getspecific(dbl_key))) {
|
340 |
if (!(dbl = (DebugLog *)pthread_getspecific(dbl_key))) {
|
309 |
dbl = new DebugLog;
|
341 |
dbl = new DebugLog;
|
310 |
dbl->setwriter(theWriter);
|
342 |
dbl->setwriter(theWriter);
|
|
|
343 |
initfiles();
|
311 |
status = pthread_setspecific(dbl_key, dbl);
|
344 |
status = pthread_setspecific(dbl_key, dbl);
|
312 |
if (status) {
|
345 |
if (status) {
|
313 |
fprintf(stderr, "debuglog: cant initialize pthread "
|
346 |
fprintf(stderr, "debuglog: cant initialize pthread "
|
314 |
"thread private storage key (pthread_setspecific)\n");
|
347 |
"thread private storage key (pthread_setspecific)\n");
|
315 |
abort();
|
348 |
abort();
|
|
... |
|
... |
324 |
DebugLog *getdbl()
|
357 |
DebugLog *getdbl()
|
325 |
{
|
358 |
{
|
326 |
if (!dbl) {
|
359 |
if (!dbl) {
|
327 |
dbl = new DebugLog;
|
360 |
dbl = new DebugLog;
|
328 |
dbl->setwriter(theWriter);
|
361 |
dbl->setwriter(theWriter);
|
|
|
362 |
initfiles();
|
329 |
}
|
363 |
}
|
330 |
return dbl;
|
364 |
return dbl;
|
331 |
}
|
365 |
}
|
332 |
#endif
|
366 |
#endif
|
333 |
|
367 |
|