demos: py_simple: New demo showimage.py.
[gfxprim.git] / doc / debug.txt
blobcdc3d4baca434152b149be8c447954b916de858b
1 Debug Messages
2 --------------
4 The GFXprim library includes a debug message infrastructure in order to ease
5 the debugging.
6  
7 Many places of the library uses debug messages to report warnings, bugs, or
8 generally important events (i.e. context has been allocated, filter function
9 has been called).
11 Debug messages are printed into the stderr and could be redirected to custom
12 handler.
14 The verbosity of the messages could be changed by the debug level. The debug
15 level is an unsigned integer (by default set to '0') and only messages that have
16 debug level lower or equal to debug level are printed.
18 There are few special debug message types with negative debug level (that
19 means that they are always printed), and as so these are used on various error
20 conditions, see bellow for more information.
22 [source,c]
23 -------------------------------------------------------------------------------
24 #include <core/GP_Debug.h>
25 /* or */
26 #include <GP.h>
28 void GP_SetDebugLevel(unsigned int level);
30 unsigned int GP_GetDebugLevel(void);
31 -------------------------------------------------------------------------------
33 Sets or gets library debug level. The default level is '0' at which only
34 'FATAL', 'BUG', 'WARNING', 'TODO' and messages with debug level '0' are shown.
36 Increasing this number would cause the library to be more verbose in debugging
37 messages.
39 Setting debug level to '1' would expose debug messages when object was created
40 or destroyed or when particular algorithm has been started.
42 Setting debug level to value higher than '1' would expose even more verbose
43 messages the current maximum used by debug messages is '4'.
45 The debug level may also be set by setting the 'GP_DEBUG' environment
46 variable. In such case the debug level is set accordingly to its value when
47 first debug message is about to be printed.
49 [source,c]
50 -------------------------------------------------------------------------------
51 #include <core/GP_Debug.h>
52 /* or */
53 #include <GP.h>
55 GP_DEBUG(level, ...)
57 GP_TODO(...)
59 GP_WARN(...)
61 GP_BUG(...)
63 GP_FATAL(...)
65 void GP_DebugPrint(int level, const char *file, const char *function, int line,
66                    const char *fmt, ...);
67 -------------------------------------------------------------------------------
69 Printf-like macros used to print debug messages. All of them calls the
70 'GP_DebugPrint()' function with slightly parameters.
72 [source,c]
73 -------------------------------------------------------------------------------
74 enum GP_DebugType {
75         GP_DEBUG_TODO  = -1,
76         GP_DEBUG_WARN  = -2,
77         GP_DEBUG_BUG   = -3,
78         GP_DEBUG_FATAL = -4,
82  * Custom debug message handler structure.
83  */
84 struct GP_DebugMsg {
85         int level;
86         const char *file;
87         const char *fn;
88         unsigned int line;
89         const char *msg;
93  * Sets custom debug message handler.
94  *
95  * If NULL is passed, custom handler is disabled and debug messages are printed
96  * into the stderr.
97  */
98 void GP_SetDebugHandler(void (*handler)(const struct GP_DebugMsg *msg));
100 -------------------------------------------------------------------------------
102 By default debug messages are printed into the 'stderr' you can redirect them
103 to your debug handler by this function.
105 NOTE: For more information see debug message handler
106       link:example_debug_handler.html[example].