pcsc-lite  1.8.13
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  * $Id: debuglog.h 7004 2014-10-02 09:26:36Z rousseau $
33  */
34 
56 #ifndef __debuglog_h__
57 #define __debuglog_h__
58 
59 #ifndef PCSC_API
60 #define PCSC_API
61 #endif
62 
63 enum {
64  DEBUGLOG_NO_DEBUG = 0,
65  DEBUGLOG_SYSLOG_DEBUG,
66  DEBUGLOG_STDOUT_DEBUG,
67  DEBUGLOG_STDOUT_COLOR_DEBUG
68 };
69 
70 #define DEBUG_CATEGORY_NOTHING 0
71 #define DEBUG_CATEGORY_APDU 1
72 #define DEBUG_CATEGORY_SW 2
73 
74 enum {
75  PCSC_LOG_DEBUG = 0,
76  PCSC_LOG_INFO,
77  PCSC_LOG_ERROR,
78  PCSC_LOG_CRITICAL
79 };
80 
81 /* You can't do #ifndef __FUNCTION__ */
82 #if !defined(__GNUC__) && !defined(__IBMC__)
83 #define __FUNCTION__ ""
84 #endif
85 
86 #ifndef __GNUC__
87 #define __attribute__(x) /*nothing*/
88 #endif
89 
90 #ifdef NO_LOG
91 
92 #define Log0(priority) do { } while(0)
93 #define Log1(priority, fmt) do { } while(0)
94 #define Log2(priority, fmt, data) do { } while(0)
95 #define Log3(priority, fmt, data1, data2) do { } while(0)
96 #define Log4(priority, fmt, data1, data2, data3) do { } while(0)
97 #define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0)
98 #define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0)
99 #define LogXxd(priority, msg, buffer, size) do { } while(0)
100 
101 #define DebugLogA(a)
102 #define DebugLogB(a, b)
103 #define DebugLogC(a, b,c)
104 
105 #else
106 
107 #define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
108 #define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
109 #define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
110 #define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
111 #define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
112 #define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4)
113 #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)
114 #define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
115 
116 #define DebugLogA(a) Log1(PCSC_LOG_INFO, a)
117 #define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b)
118 #define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c)
119 
120 #endif /* NO_LOG */
121 
122 PCSC_API void log_msg(const int priority, const char *fmt, ...)
123  __attribute__((format(printf, 2, 3)));
124 
125 PCSC_API void log_xxd(const int priority, const char *msg,
126  const unsigned char *buffer, const int size);
127 
128 void DebugLogSuppress(const int);
129 void DebugLogSetLogType(const int);
130 int DebugLogSetCategory(const int);
131 void DebugLogCategory(const int, const unsigned char *, const int);
132 PCSC_API void DebugLogSetLevel(const int level);
133 
134 #endif /* __debuglog_h__ */
135