Blame MacOSX/debuglog.h

Packit Service aee942
/*
Packit Service aee942
 * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
Packit Service aee942
 *
Packit Service aee942
 * Copyright (C) 1999-2004
Packit Service aee942
 *  David Corcoran <corcoran@musclecard.com>
Packit Service aee942
 * Copyright (C) 1999-2011
Packit Service aee942
 *  Ludovic Rousseau <ludovic.rousseau@free.fr>
Packit Service aee942
 *
Packit Service aee942
Redistribution and use in source and binary forms, with or without
Packit Service aee942
modification, are permitted provided that the following conditions
Packit Service aee942
are met:
Packit Service aee942
Packit Service aee942
1. Redistributions of source code must retain the above copyright
Packit Service aee942
   notice, this list of conditions and the following disclaimer.
Packit Service aee942
2. Redistributions in binary form must reproduce the above copyright
Packit Service aee942
   notice, this list of conditions and the following disclaimer in the
Packit Service aee942
   documentation and/or other materials provided with the distribution.
Packit Service aee942
3. The name of the author may not be used to endorse or promote products
Packit Service aee942
   derived from this software without specific prior written permission.
Packit Service aee942
Packit Service aee942
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Packit Service aee942
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit Service aee942
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit Service aee942
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit Service aee942
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit Service aee942
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service aee942
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service aee942
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service aee942
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit Service aee942
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service aee942
 */
Packit Service aee942
Packit Service aee942
/**
Packit Service aee942
 * @file
Packit Service aee942
 * @brief This handles debugging.
Packit Service aee942
 *
Packit Service aee942
 * @note log message is sent to syslog or stderr depending on --foreground
Packit Service aee942
 * command line argument
Packit Service aee942
 *
Packit Service aee942
 * @code
Packit Service aee942
 * Log1(priority, "text");
Packit Service aee942
 *  log "text" with priority level priority
Packit Service aee942
 * Log2(priority, "text: %d", 1234);
Packit Service aee942
 *  log "text: 1234"
Packit Service aee942
 * the format string can be anything printf() can understand
Packit Service aee942
 * Log3(priority, "text: %d %d", 1234, 5678);
Packit Service aee942
 *  log "text: 1234 5678"
Packit Service aee942
 * the format string can be anything printf() can understand
Packit Service aee942
 * LogXxd(priority, msg, buffer, size);
Packit Service aee942
 *  log "msg" + a hex dump of size bytes of buffer[]
Packit Service aee942
 * @endcode
Packit Service aee942
 */
Packit Service aee942
Packit Service aee942
#ifndef __debuglog_h__
Packit Service aee942
#define __debuglog_h__
Packit Service aee942
Packit Service aee942
#ifndef PCSC_API
Packit Service aee942
#define PCSC_API
Packit Service aee942
#endif
Packit Service aee942
Packit Service aee942
enum {
Packit Service aee942
	DEBUGLOG_NO_DEBUG = 0,
Packit Service aee942
	DEBUGLOG_SYSLOG_DEBUG,
Packit Service aee942
	DEBUGLOG_STDOUT_DEBUG,
Packit Service aee942
	DEBUGLOG_STDOUT_COLOR_DEBUG
Packit Service aee942
};
Packit Service aee942
Packit Service aee942
#define DEBUG_CATEGORY_NOTHING  0
Packit Service aee942
#define DEBUG_CATEGORY_APDU     1
Packit Service aee942
#define DEBUG_CATEGORY_SW       2
Packit Service aee942
Packit Service aee942
enum {
Packit Service aee942
	PCSC_LOG_DEBUG = 0,
Packit Service aee942
	PCSC_LOG_INFO,
Packit Service aee942
	PCSC_LOG_ERROR,
Packit Service aee942
	PCSC_LOG_CRITICAL
Packit Service aee942
};
Packit Service aee942
Packit Service aee942
/* You can't do #ifndef __FUNCTION__ */
Packit Service aee942
#if !defined(__GNUC__) && !defined(__IBMC__)
Packit Service aee942
#define __FUNCTION__ ""
Packit Service aee942
#endif
Packit Service aee942
Packit Service aee942
#ifndef __GNUC__
Packit Service aee942
#define __attribute__(x) /*nothing*/
Packit Service aee942
#endif
Packit Service aee942
Packit Service aee942
#ifdef NO_LOG
Packit Service aee942
Packit Service aee942
#define Log0(priority) do { } while(0)
Packit Service aee942
#define Log1(priority, fmt) do { } while(0)
Packit Service aee942
#define Log2(priority, fmt, data) do { } while(0)
Packit Service aee942
#define Log3(priority, fmt, data1, data2) do { } while(0)
Packit Service aee942
#define Log4(priority, fmt, data1, data2, data3) do { } while(0)
Packit Service aee942
#define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0)
Packit Service aee942
#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0)
Packit Service aee942
#define LogXxd(priority, msg, buffer, size) do { } while(0)
Packit Service aee942
Packit Service aee942
#define DebugLogA(a)
Packit Service aee942
#define DebugLogB(a, b)
Packit Service aee942
#define DebugLogC(a, b,c)
Packit Service aee942
Packit Service aee942
#else
Packit Service aee942
Packit Service aee942
#define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
Packit Service aee942
#define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
Packit Service aee942
#define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
Packit Service aee942
#define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
Packit Service aee942
#define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
Packit Service aee942
#define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4)
Packit Service aee942
#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)
Packit Service aee942
#define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
Packit Service aee942
Packit Service aee942
#define DebugLogA(a) Log1(PCSC_LOG_INFO, a)
Packit Service aee942
#define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b)
Packit Service aee942
#define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c)
Packit Service aee942
Packit Service aee942
#endif	/* NO_LOG */
Packit Service aee942
Packit Service aee942
PCSC_API void log_msg(const int priority, const char *fmt, ...)
Packit Service aee942
	__attribute__((format(printf, 2, 3)));
Packit Service aee942
Packit Service aee942
PCSC_API void log_xxd(const int priority, const char *msg,
Packit Service aee942
	const unsigned char *buffer, const int size);
Packit Service aee942
Packit Service aee942
void DebugLogSuppress(const int);
Packit Service aee942
void DebugLogSetLogType(const int);
Packit Service aee942
int DebugLogSetCategory(const int);
Packit Service aee942
void DebugLogCategory(const int, const unsigned char *, const int);
Packit Service aee942
PCSC_API void DebugLogSetLevel(const int level);
Packit Service aee942
Packit Service aee942
#endif							/* __debuglog_h__ */
Packit Service aee942