Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/orxonox/core/Debug.h @ 685

Last change on this file since 685 was 684, checked in by landauf, 17 years ago
  • added new class: the OutputHandler replaces std::cout in Debug.h and redirects the output not only to the console, but also into orxonox.log (this works, of course, only for output using COUT(level) from Debug.h)
  • commented DebugLevel
File size: 6.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Benjamin Grauer
23 *   Co-authors:
24 *      Fabian 'x3n' Landau
25 *
26 */
27
28/*!
29 * @file Debug.h
30 * @brief Handles the output for different verbose-modes.
31 *
32 * There are two modes: HARD and SOFT. HARD is precessed during compiletime, while SOFT is for runtime.
33 */
34
35#ifndef _Debug_H__
36#define _Debug_H__
37
38#include <stdio.h>
39#include "OutputHandler.h"
40
41#include "CorePrereqs.h"
42
43extern "C" _CoreExport int getSoftDebugLevel();
44
45// DEFINE ERROR MODES
46#define ORX_NONE            0
47#define ORX_ERROR           1
48#define ORX_WARNING         2
49#define ORX_INFO            3
50#define ORX_DEBUG           4
51#define ORX_vDEBUG          5
52
53//definitions
54#define ORX_PRINT_DEBUG_OUTPUT 1 // <-- fix that! should be a configurable setting
55
56#define ORX_HARD_DEBUG_LEVEL ORX_DEBUG
57//#define ORX_SOFT_DEBUG_LEVEL ORX_WARNING // <-- fix that! should be a configurable setting
58
59///////////////////////////////////////////////////
60/// PRINTF: prints with filename and linenumber ///
61///////////////////////////////////////////////////
62#define PRINTFORX_NONE    PRINTF0
63#define PRINTFORX_ERROR   PRINTF1
64#define PRINTFORX_WARNING PRINTF2
65#define PRINTFORX_INFO    PRINTF3
66#define PRINTFORX_DEBUG   PRINTF4
67#define PRINTFORX_vDEBUG  PRINTF5
68
69#define PRINT_EXEC  printf
70//#define COUT_EXEC   std::cout
71#define COUT_EXEC   orxonox::OutputHandler::getOutStream()
72
73#ifndef PRINTF
74 #if ORX_PRINT_DEBUG_OUTPUT
75
76  #define PRINTF(x) \
77   PRINTF ## x
78
79  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
80   #define PRINTF1 \
81    if (getSoftDebugLevel() >= ORX_ERROR) \
82     printf("Error (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
83  #else
84   #define PRINTF1 if (ORX_NONE) PRINT_EXEC
85  #endif
86
87  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
88   #define PRINTF2 \
89    if (getSoftDebugLevel() >= ORX_WARNING) \
90     printf("Warning (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
91  #else
92   #define PRINTF2 if (ORX_NONE) PRINT_EXEC
93  #endif
94
95  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
96   #define PRINTF3 \
97    if (getSoftDebugLevel() >= ORX_INFO) \
98     printf("Info (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
99  #else
100   #define PRINTF3 if (ORX_NONE) PRINT_EXEC
101  #endif
102
103  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
104   #define PRINTF4 \
105    if (getSoftDebugLevel() >= ORX_DEBUG) \
106     printf("Debug (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
107  #else
108   #define PRINTF4 if (ORX_NONE) PRINT_EXEC
109  #endif
110
111  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
112   #define PRINTF5 \
113    if (getSoftDebugLevel() >= ORX_vDEBUG) \
114     printf("vDebug (in %s, line %d): ", __FILE__, __LINE__), PRINT_EXEC
115  #else
116   #define PRINTF5 if (ORX_NONE) PRINT_EXEC
117  #endif
118
119 #else /* if ORX_PRINT_DEBUG_OUTPUT */
120  #define PRINTF(x) if (ORX_NONE) PRINT_EXEC
121 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
122
123 #define PRINTF0 \
124  PRINT_EXEC
125#endif /* ifndef PRINTF */
126
127///////////////////////////////////////////////////
128///  PRINT: just prints output as is            ///
129///////////////////////////////////////////////////
130#define PRINTORX_NONE    PRINT0
131#define PRINTORX_ERROR   PRINT1
132#define PRINTORX_WARNING PRINT2
133#define PRINTORX_INFO    PRINT3
134#define PRINTORX_DEBUG   PRINT4
135#define PRINTORX_vDEBUG  PRINT5
136
137#ifndef PRINT
138 #if ORX_PRINT_DEBUG_OUTPUT
139  #define PRINT(x) \
140   PRINT ## x
141
142  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
143   #define PRINT1  \
144    if (getSoftDebugLevel() >= ORX_ERROR)  \
145     PRINT_EXEC
146  #else
147   #define PRINT1 if (ORX_NONE) PRINT_EXEC
148  #endif
149
150  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
151   #define PRINT2 \
152    if (getSoftDebugLevel() >= ORX_WARNING) \
153     PRINT_EXEC
154  #else
155   #define PRINT2 if (ORX_NONE) PRINT_EXEC
156  #endif
157
158  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
159   #define PRINT3 \
160    if (getSoftDebugLevel() >= ORX_INFO) \
161     PRINT_EXEC
162  #else
163   #define PRINT3 if (ORX_NONE) PRINT_EXEC
164  #endif
165
166  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
167   #define PRINT4 \
168    if (getSoftDebugLevel() >= ORX_DEBUG) \
169     PRINT_EXEC
170  #else
171   #define PRINT4 if (ORX_NONE) PRINT_EXEC
172  #endif
173
174  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
175   #define PRINT5 \
176    if (getSoftDebugLevel() >= ORX_vDEBUG) \
177     PRINT_EXEC
178  #else
179   #define PRINT5 if (ORX_NONE) PRINT_EXEC
180  #endif
181
182 #else /* if ORX_PRINT_DEBUG_OUTPUT */
183  #define PRINT(x) if (ORX_NONE) PRINT_EXEC
184 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
185
186 #define PRINT0 \
187  PRINT_EXEC
188#endif /* ifndef PRINT */
189
190
191////////////////////////////////////////////////////////
192///  COUT: just prints output as is with std::cout   ///
193////////////////////////////////////////////////////////
194#define COUTORX_NONE    COUT0
195#define COUTORX_ERROR   COUT1
196#define COUTORX_WARNING COUT2
197#define COUTORX_INFO    COUT3
198#define COUTORX_DEBUG   COUT4
199#define COUTORX_vDEBUG  COUT5
200
201#ifndef COUT
202 #if ORX_PRINT_DEBUG_OUTPUT
203  #define COUT(x) \
204   COUT ## x
205
206  #if ORX_HARD_DEBUG_LEVEL >= ORX_ERROR
207   #define COUT1  \
208    if (getSoftDebugLevel() >= ORX_ERROR)  \
209     COUT_EXEC
210  #else
211   #define COUT1 if (ORX_NONE)\
212    COUT_EXEC
213  #endif
214
215  #if ORX_HARD_DEBUG_LEVEL >= ORX_WARNING
216   #define COUT2 \
217    if (getSoftDebugLevel() >= ORX_WARNING) \
218     COUT_EXEC
219  #else
220   #define COUT2 if (ORX_NONE) \
221    COUT_EXEC
222  #endif
223
224  #if ORX_HARD_DEBUG_LEVEL >= ORX_INFO
225   #define COUT3 \
226    if (getSoftDebugLevel() >= ORX_INFO) \
227     COUT_EXEC
228  #else
229   #define COUT3 if (ORX_NONE) \
230    COUT_EXEC
231  #endif
232
233  #if ORX_HARD_DEBUG_LEVEL >= ORX_DEBUG
234   #define COUT4 \
235    if (getSoftDebugLevel() >= ORX_DEBUG) \
236     COUT_EXEC
237  #else
238   #define COUT4 if (ORX_NONE) \
239    COUT_EXEC
240  #endif
241
242  #if ORX_HARD_DEBUG_LEVEL >= ORX_vDEBUG
243   #define COUT5 \
244    if (getSoftDebugLevel() >= ORX_vDEBUG) \
245     COUT_EXEC
246  #else
247   #define COUT5 if (ORX_NONE) \
248    COUT_EXEC
249  #endif
250
251 #else /* if ORX_PRINT_DEBUG_OUTPUT */
252  #define COUT(x) if (ORX_NONE) \
253   COUT_EXEC
254 #endif /* if ORX_PRINT_DEBUG_OUTPUT */
255
256 #define COUT0 \
257  COUT_EXEC
258#endif /* ifndef COUT */
259
260#endif /* _Debug_H__ */
Note: See TracBrowser for help on using the repository browser.