2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
4 * Copyright (C) 1999-2004
5 * David Corcoran <corcoran@musclecard.com>
6 * Copyright (C) 1999-2011
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
13 1. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 3. The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * @brief This handles debugging.
37 * @note log message is sent to syslog or stderr depending on --foreground
38 * command line argument
41 * Log1(priority, "text");
42 * log "text" with priority level priority
43 * Log2(priority, "text: %d", 1234);
45 * the format string can be anything printf() can understand
46 * Log3(priority, "text: %d %d", 1234, 5678);
47 * log "text: 1234 5678"
48 * the format string can be anything printf() can understand
49 * LogXxd(priority, msg, buffer, size);
50 * log "msg" + a hex dump of size bytes of buffer[]
54 #ifndef __debuglog_h__
55 #define __debuglog_h__
62 DEBUGLOG_NO_DEBUG = 0,
63 DEBUGLOG_SYSLOG_DEBUG,
64 DEBUGLOG_STDOUT_DEBUG,
65 DEBUGLOG_STDOUT_COLOR_DEBUG
68 #define DEBUG_CATEGORY_NOTHING 0
69 #define DEBUG_CATEGORY_APDU 1
70 #define DEBUG_CATEGORY_SW 2
79 /* You can't do #ifndef __FUNCTION__ */
80 #if !defined(__GNUC__) && !defined(__IBMC__)
81 #define __FUNCTION__ ""
85 #define __attribute__(x) /*nothing*/
90 #define Log0(priority) do { } while(0)
91 #define Log1(priority, fmt) do { } while(0)
92 #define Log2(priority, fmt, data) do { } while(0)
93 #define Log3(priority, fmt, data1, data2) do { } while(0)
94 #define Log4(priority, fmt, data1, data2, data3) do { } while(0)
95 #define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0)
96 #define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0)
97 #define LogXxd(priority, msg, buffer, size) do { } while(0)
100 #define DebugLogB(a, b)
101 #define DebugLogC(a, b,c)
105 #define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
106 #define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
107 #define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
108 #define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
109 #define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
110 #define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4)
111 #define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4, data5, data6, data7, data8)
112 #define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
114 #define DebugLogA(a) Log1(PCSC_LOG_INFO, a)
115 #define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b)
116 #define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c)
120 PCSC_API void log_msg(const int priority, const char *fmt, ...)
121 __attribute__((format(printf, 2, 3)));
123 PCSC_API void log_xxd(const int priority, const char *msg,
124 const unsigned char *buffer, const int size);
126 void DebugLogSuppress(const int);
127 void DebugLogSetLogType(const int);
128 void DebugLogSetCategory(const int);
129 void DebugLogCategory(const int, const unsigned char *, const int);
130 PCSC_API void DebugLogSetLevel(const int level);
132 #endif /* __debuglog_h__ */