forked from LudovicRousseau/CCID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.h
127 lines (89 loc) · 5.46 KB
/
debug.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
debug.h: log (or not) messages using syslog
Copyright (C) 2003-2008 Ludovic Rousseau
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* DEBUG_CRITICAL("text");
* log "text" if (LogLevel & DEBUG_LEVEL_CRITICAL) is TRUE
*
* DEBUG_CRITICAL2("text: %d", 1234);
* log "text: 1234" if (DEBUG_LEVEL_CRITICAL & DEBUG_LEVEL_CRITICAL) is TRUE
* the format string can be anything printf() can understand
*
* same thing for DEBUG_INFO, DEBUG_COMM and DEBUG_PERIODIC
*
* DEBUG_XXD(msg, buffer, size);
* log a dump of buffer if (LogLevel & DEBUG_LEVEL_COMM) is TRUE
*
*/
#ifndef _GCDEBUG_H_
#define _GCDEBUG_H_
/* You can't do #ifndef __FUNCTION__ */
#if !defined(__GNUC__) && !defined(__IBMC__)
#define __FUNCTION__ ""
#endif
extern int LogLevel;
#define DEBUG_LEVEL_CRITICAL 1
#define DEBUG_LEVEL_INFO 2
#define DEBUG_LEVEL_COMM 4
#define DEBUG_LEVEL_PERIODIC 8
#include <debuglog.h> /* from pcsc-lite */
#ifdef USE_OS_LOG
#include <os/log.h>
#define DEBUG_CRITICAL(fmt) os_log_fault(OS_LOG_DEFAULT, fmt)
#define DEBUG_CRITICAL2(fmt, data1) os_log_fault(OS_LOG_DEFAULT, fmt, data1)
#define DEBUG_CRITICAL3(fmt, data1, data2) os_log_fault(OS_LOG_DEFAULT, fmt, data1, data2)
#define DEBUG_CRITICAL4(fmt, data1, data2, data3) os_log_fault(OS_LOG_DEFAULT, fmt, data1, data2, data3)
#define DEBUG_CRITICAL5(fmt, data1, data2, data3, data4) os_log_fault(OS_LOG_DEFAULT, fmt, data1, data2, data3, data4)
#define DEBUG_INFO1(fmt) os_log_info(OS_LOG_DEFAULT, fmt)
#define DEBUG_INFO2(fmt, data1) os_log_info(OS_LOG_DEFAULT, fmt, data1)
#define DEBUG_INFO3(fmt, data1, data2) os_log_info(OS_LOG_DEFAULT, fmt, data1, data2)
#define DEBUG_INFO4(fmt, data1, data2, data3) os_log_info(OS_LOG_DEFAULT, fmt, data1, data2, data3)
#define DEBUG_INFO5(fmt, data1, data2, data3, data4) os_log_info(OS_LOG_DEFAULT, fmt, data1, data2, data3, data4)
#define DEBUG_PERIODIC(fmt) os_log_debug(OS_LOG_DEFAULT, fmt)
#define DEBUG_PERIODIC2(fmt, data1) os_log_debug(OS_LOG_DEFAULT, fmt, data1)
#define DEBUG_PERIODIC3(fmt, data1, data2) os_log_debug(OS_LOG_DEFAULT, fmt, data1, data2)
#define DEBUG_COMM(fmt) os_log_info(OS_LOG_DEFAULT, fmt)
#define DEBUG_COMM2(fmt, data1) os_log_info(OS_LOG_DEFAULT, fmt, data1)
#define DEBUG_COMM3(fmt, data1, data2) os_log_info(OS_LOG_DEFAULT, fmt, data1, data2)
#define DEBUG_COMM4(fmt, data1, data2, data3) os_log_info(OS_LOG_DEFAULT, fmt, data1, data2, data3)
#define DEBUG_INFO_XXD(msg, buffer, size) if (LogLevel & DEBUG_LEVEL_INFO) log_xxd(PCSC_LOG_INFO, msg, buffer, size)
#define DEBUG_XXD(msg, buffer, size) if (LogLevel & DEBUG_LEVEL_COMM) log_xxd(PCSC_LOG_DEBUG, msg, buffer, size)
#else
/* DEBUG_CRITICAL */
#define DEBUG_CRITICAL(fmt) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log1(PCSC_LOG_CRITICAL, fmt)
#define DEBUG_CRITICAL2(fmt, data) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log2(PCSC_LOG_CRITICAL, fmt, data)
#define DEBUG_CRITICAL3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log3(PCSC_LOG_CRITICAL, fmt, data1, data2)
#define DEBUG_CRITICAL4(fmt, data1, data2, data3) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log4(PCSC_LOG_CRITICAL, fmt, data1, data2, data3)
#define DEBUG_CRITICAL5(fmt, data1, data2, data3, data4) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log5(PCSC_LOG_CRITICAL, fmt, data1, data2, data3, data4)
/* DEBUG_INFO */
#define DEBUG_INFO1(fmt) if (LogLevel & DEBUG_LEVEL_INFO) Log1(PCSC_LOG_INFO, fmt)
#define DEBUG_INFO2(fmt, data) if (LogLevel & DEBUG_LEVEL_INFO) Log2(PCSC_LOG_INFO, fmt, data)
#define DEBUG_INFO3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_INFO) Log3(PCSC_LOG_INFO, fmt, data1, data2)
#define DEBUG_INFO4(fmt, data1, data2, data3) if (LogLevel & DEBUG_LEVEL_INFO) Log4(PCSC_LOG_INFO, fmt, data1, data2, data3)
#define DEBUG_INFO5(fmt, data1, data2, data3, data4) if (LogLevel & DEBUG_LEVEL_INFO) Log5(PCSC_LOG_INFO, fmt, data1, data2, data3, data4)
#define DEBUG_INFO_XXD(msg, buffer, size) if (LogLevel & DEBUG_LEVEL_INFO) LogXxd(PCSC_LOG_INFO, msg, buffer, size)
/* DEBUG_PERIODIC */
#define DEBUG_PERIODIC(fmt) if (LogLevel & DEBUG_LEVEL_PERIODIC) Log1(PCSC_LOG_DEBUG, fmt)
#define DEBUG_PERIODIC2(fmt, data) if (LogLevel & DEBUG_LEVEL_PERIODIC) Log2(PCSC_LOG_DEBUG, fmt, data)
#define DEBUG_PERIODIC3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_PERIODIC) Log3(PCSC_LOG_DEBUG, fmt, data1, data2)
/* DEBUG_COMM */
#define DEBUG_COMM(fmt) if (LogLevel & DEBUG_LEVEL_COMM) Log1(PCSC_LOG_DEBUG, fmt)
#define DEBUG_COMM2(fmt, data) if (LogLevel & DEBUG_LEVEL_COMM) Log2(PCSC_LOG_DEBUG, fmt, data)
#define DEBUG_COMM3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_COMM) Log3(PCSC_LOG_DEBUG, fmt, data1, data2)
#define DEBUG_COMM4(fmt, data1, data2, data3) if (LogLevel & DEBUG_LEVEL_COMM) Log4(PCSC_LOG_DEBUG, fmt, data1, data2, data3)
/* DEBUG_XXD */
#define DEBUG_XXD(msg, buffer, size) if (LogLevel & DEBUG_LEVEL_COMM) LogXxd(PCSC_LOG_DEBUG, msg, buffer, size)
#endif
#endif