pcsc-lite  1.8.20
debuglog.h
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
3  *
4  * Copyright (C) 1999-2004
5  * David Corcoran <corcoran@musclecard.com>
6  * Copyright (C) 1999-2011
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12 
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.
20 
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.
31  */
32 
54 #ifndef __debuglog_h__
55 #define __debuglog_h__
56 
57 #ifndef PCSC_API
58 #define PCSC_API
59 #endif
60 
61 enum {
62  DEBUGLOG_NO_DEBUG = 0,
63  DEBUGLOG_SYSLOG_DEBUG,
64  DEBUGLOG_STDOUT_DEBUG,
65  DEBUGLOG_STDOUT_COLOR_DEBUG
66 };
67 
68 #define DEBUG_CATEGORY_NOTHING 0
69 #define DEBUG_CATEGORY_APDU 1
70 #define DEBUG_CATEGORY_SW 2
71 
72 enum {
73  PCSC_LOG_DEBUG = 0,
74  PCSC_LOG_INFO,
75  PCSC_LOG_ERROR,
76  PCSC_LOG_CRITICAL
77 };
78 
79 /* You can't do #ifndef __FUNCTION__ */
80 #if !defined(__GNUC__) && !defined(__IBMC__)
81 #define __FUNCTION__ ""
82 #endif
83 
84 #ifndef __GNUC__
85 #define __attribute__(x) /*nothing*/
86 #endif
87 
88 #ifdef NO_LOG
89 
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)
98 
99 #define DebugLogA(a)
100 #define DebugLogB(a, b)
101 #define DebugLogC(a, b,c)
102 
103 #else
104 
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)
113 
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)
117 
118 #endif /* NO_LOG */
119 
120 PCSC_API void log_msg(const int priority, const char *fmt, ...)
121  __attribute__((format(printf, 2, 3)));
122 
123 PCSC_API void log_xxd(const int priority, const char *msg,
124  const unsigned char *buffer, const int size);
125 
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);
131 
132 #endif /* __debuglog_h__ */
133