pcsc-lite 1.9.5
debuglog.h
Go to the documentation of this file.
1/*
2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
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 *
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
12
131. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
152. 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.
183. 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
21THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30THIS 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
61enum {
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
72enum {
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
120PCSC_API void log_msg(const int priority, const char *fmt, ...)
121 __attribute__((format(printf, 2, 3)));
122
123PCSC_API void log_xxd(const int priority, const char *msg,
124 const unsigned char *buffer, const int size);
125
126void DebugLogSuppress(const int);
127void DebugLogSetLogType(const int);
128void DebugLogSetCategory(const int);
129void DebugLogCategory(const int, const unsigned char *, const int);
130PCSC_API void DebugLogSetLevel(const int level);
131
132#endif /* __debuglog_h__ */
133