Added verbose tracing level
[distributed.git] / src / libs / misc / trace.h
blobf0bf8962a37c4ff1562b4cd5e63ab18512174d38
1 //
2 // Copyright (C) 2008 Francesco Salvestrini
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #ifndef LIBS_MISC_TRACES_H
20 #define LIBS_MISC_TRACES_H
22 #include <cstdio>
25 // NOTE:
26 // This tracing interface is really awful. It will be replaced ASAP.
29 extern int trace_level;
30 extern char * trace_prefix;
32 // Trace levels
33 #define TR_LVL_CRITICAL 5
34 #define TR_LVL_ERROR 4
35 #define TR_LVL_WARNING 3
36 #define TR_LVL_NOTICE 2
37 #define TR_LVL_VERBOSE 1
38 #define TR_LVL_DEBUG 0
40 #define TR_LVL_DEFAULT TR_LVL_NOTICE
42 #define _TRACE(LVL,FMT,ARGS...) { \
43 if ((LVL) >= trace_level) { \
44 if (trace_prefix) { \
45 fprintf(stdout, "%s: " FMT, trace_prefix, ##ARGS); \
46 } else { \
47 fprintf(stdout, FMT, ##ARGS); \
48 } \
49 } \
52 // Shortcuts for configuration
53 #define TR_CONFIG_LVL(LVL) { trace_level = LVL; }
54 #define TR_CONFIG_PFX(PFX) { trace_prefix = PFX; }
56 // Shortcuts for traces
57 #define TR_DBG(FMT,ARGS...) _TRACE(TR_LVL_DEBUG, FMT, ##ARGS);
58 #define TR_VRB(FMT,ARGS...) _TRACE(TR_LVL_VERBOSE, FMT, ##ARGS);
59 #define TR_WRN(FMT,ARGS...) _TRACE(TR_LVL_WARNING, FMT, ##ARGS);
60 #define TR_ERR(FMT,ARGS...) _TRACE(TR_LVL_ERROR, FMT, ##ARGS);
61 #define TR_CRT(FMT,ARGS...) _TRACE(TR_LVL_CRITICAL, FMT, ##ARGS);
63 #endif // LIBS_MISC_TRACES_H