Remove mtime from mpd_Song
[libmpd.git] / src / debug_printf.c
blob35a2e949ff937f35c85e790f0b80c39b35cea259
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.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <time.h>
26 #include <glib.h>
27 #include "config.h"
28 #include "debug_printf.h"
30 int debug_level = 0;
31 /* Compiler does not like it when I initialize this to stdout, complaints about
32 * not being constant. stoud is a macro..
33 * So use this "hack"
35 FILE *rout = NULL;
36 #define ERROR_BUFFER_SIZE 2048
37 char error_buffer[ERROR_BUFFER_SIZE];
39 void debug_set_output(FILE *fp)
41 rout = 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,...)
52 if(debug_level >= dp)
54 va_list arglist;
55 time_t ts = time(NULL);
56 struct tm tm;
57 char buffer[32];
58 FILE *out = stdout;
59 char *temp;
60 if(rout) out = rout;
61 va_start(arglist,format);
63 /* Windows has no thread-safe localtime_r function, so ignore it for now */
64 #ifndef WIN32
65 localtime_r(&ts, &tm);
66 strftime(buffer, 32, "%d/%m/%y %T",&tm);
67 #else
68 buffer[0] = '\0';
69 #endif
71 if(dp == DEBUG_INFO)
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);
79 else
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);
85 if(temp) {
86 fputs(temp,out);
87 g_free(temp);
89 if(format[strlen(format)-1] != '\n')
91 fprintf(out,"\n");
93 fflush(out);
94 va_end(arglist);