pcsc-lite  1.8.11
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 Changes to this license can be made only by the copyright author with
22 explicit written consent.
23 
24 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * $Id: debuglog.h 6851 2014-02-14 15:43:32Z rousseau $
36  */
37 
59 #ifndef __debuglog_h__
60 #define __debuglog_h__
61 
62 #ifndef PCSC_API
63 #define PCSC_API
64 #endif
65 
66 enum {
67  DEBUGLOG_NO_DEBUG = 0,
68  DEBUGLOG_SYSLOG_DEBUG,
69  DEBUGLOG_STDOUT_DEBUG,
70  DEBUGLOG_STDOUT_COLOR_DEBUG
71 };
72 
73 #define DEBUG_CATEGORY_NOTHING 0
74 #define DEBUG_CATEGORY_APDU 1
75 #define DEBUG_CATEGORY_SW 2
76 
77 enum {
78  PCSC_LOG_DEBUG = 0,
79  PCSC_LOG_INFO,
80  PCSC_LOG_ERROR,
81  PCSC_LOG_CRITICAL
82 };
83 
84 /* You can't do #ifndef __FUNCTION__ */
85 #if !defined(__GNUC__) && !defined(__IBMC__)
86 #define __FUNCTION__ ""
87 #endif
88 
89 #ifndef __GNUC__
90 #define __attribute__(x) /*nothing*/
91 #endif
92 
93 #ifdef NO_LOG
94 
95 #define Log0(priority) do { } while(0)
96 #define Log1(priority, fmt) do { } while(0)
97 #define Log2(priority, fmt, data) do { } while(0)
98 #define Log3(priority, fmt, data1, data2) do { } while(0)
99 #define Log4(priority, fmt, data1, data2, data3) do { } while(0)
100 #define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0)
101 #define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0)
102 #define LogXxd(priority, msg, buffer, size) do { } while(0)
103 
104 #define DebugLogA(a)
105 #define DebugLogB(a, b)
106 #define DebugLogC(a, b,c)
107 
108 #else
109 
110 #define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
111 #define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
112 #define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
113 #define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
114 #define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
115 #define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4)
116 #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)
117 #define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
118 
119 #define DebugLogA(a) Log1(PCSC_LOG_INFO, a)
120 #define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b)
121 #define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c)
122 
123 #endif /* NO_LOG */
124 
125 PCSC_API void log_msg(const int priority, const char *fmt, ...)
126  __attribute__((format(printf, 2, 3)));
127 
128 PCSC_API void log_xxd(const int priority, const char *msg,
129  const unsigned char *buffer, const int size);
130 
131 void DebugLogSuppress(const int);
132 void DebugLogSetLogType(const int);
133 int DebugLogSetCategory(const int);
134 void DebugLogCategory(const int, const unsigned char *, const int);
135 PCSC_API void DebugLogSetLevel(const int level);
136 
137 #endif /* __debuglog_h__ */
138