must call INIT before first TRACE
[nobug.git] / nobug.c
blob1a9e6bd30e199053797d496eb20b3a5f892ead5e
1 /*
2 nobug.c - a small debugging library
4 Copyright (C) 2007, Christian Thaeter <ct@pipapo.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License version 2 as
8 published by the Free Software Foundation.
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
16 along with this program; if not, contact me.
20 #include <pthread.h>
22 #define NOBUG_LIBNOBUG_C
23 #include "nobug.h"
25 struct nobug_ringbuffer nobug_default_ringbuffer;
26 FILE* nobug_default_file = NULL;
28 struct nobug_flag nobug_flag_NOBUG_ON =
29 {NULL, {LOG_DEBUG, LOG_DEBUG, LOG_DEBUG, LOG_DEBUG, LOG_DEBUG}, NULL,NULL,NULL};
31 static int nobug_initialized = 0;
35 default initialization
37 void
38 nobug_init()
40 if (nobug_initialized)
41 return;
43 nobug_initialized = 1;
45 #if NOBUG_USE_PTHREAD
46 pthread_key_create (&nobug_thread_id_key, free);
47 #endif
49 /* we initialize a minimal ringbuffer, if not already done */
50 if (!nobug_default_ringbuffer.start)
51 nobug_ringbuffer_init (&nobug_default_ringbuffer, 4096, NULL, NOBUG_RINGBUFFER_DEFAULT);
53 /* initialize the always-on flag*/
54 nobug_flag_NOBUG_ON.ringbuffer_target = &nobug_default_ringbuffer;
55 nobug_flag_NOBUG_ON.console_target = stderr;
56 nobug_flag_NOBUG_ON.file_target = nobug_default_file;