1d709248be6b5925e52778a4423b234b97156aaf
[garming/samba-autobuild/.git] / ctdb / lib / util / debug.c
1 /*
2    Unix SMB/CIFS implementation.
3    ctdb debug functions
4    Copyright (C) Volker Lendecke 2007
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "system/time.h"
22 #include <unistd.h>
23
24
25 void do_debug(const char *format, ...)
26 {
27         struct timeval t;
28         va_list ap;
29         char *s = NULL;
30         struct tm *tm;
31         char tbuf[100];
32
33         va_start(ap, format);
34         vasprintf(&s, format, ap);
35         va_end(ap);
36
37         t = timeval_current();
38         tm = localtime(&t.tv_sec);
39
40         strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
41
42         printf("%s.%06u [%5u]: %s", tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s);
43         fflush(stdout);
44         free(s);
45 }