1 /* libmpd (high level libmpdclient library)
2 * Copyright (C) 2004-2009 Qball Cow <qball@sarine.nl>
3 * Project homepage: http://gmpcwiki.sarine.nl/
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.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "debug_printf.h"
31 /* Compiler does not like it when I initialize this to stdout, complaints about
32 * not being constant. stoud is a macro..
36 #define ERROR_BUFFER_SIZE 2048
37 char error_buffer
[ERROR_BUFFER_SIZE
];
39 void debug_set_output(FILE *fp
)
44 void debug_set_level(DebugLevel dl
)
46 debug_level
= (dl
<0)?DEBUG_NO_OUTPUT
:((dl
> DEBUG_INFO
)?DEBUG_INFO
:dl
);
50 void debug_printf_real(DebugLevel dp
, const char *file
,const int line
,const char *function
, const char *format
,...)
55 time_t ts
= time(NULL
);
61 va_start(arglist
,format
);
63 /* Windows has no thread-safe localtime_r function, so ignore it for now */
65 localtime_r(&ts
, &tm
);
66 strftime(buffer
, 32, "%d/%m/%y %T",&tm
);
73 fprintf(out
,"%s: INFO: %s %s():#%d:\t",buffer
,file
,function
,line
);
75 else if(dp
== DEBUG_WARNING
)
77 fprintf(out
,"%s: WARNING: %s %s():#%i:\t",buffer
,file
,function
,line
);
81 fprintf(out
,"%s: ERROR: %s %s():#%i:\t",buffer
,file
,function
,line
);
83 vsnprintf(error_buffer
,ERROR_BUFFER_SIZE
,format
, arglist
);
84 temp
= g_locale_from_utf8(error_buffer
, -1,NULL
, NULL
, NULL
);
89 if(format
[strlen(format
)-1] != '\n')