00001 #ifndef SCBLOG_H_
00002 #define SCBLOG_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031
00032 #define LOG_PREFIX "SCB"
00033
00034 #ifndef USE_SYSLOG
00035 #define USE_SYSLOG 0
00036 #endif
00037
00038 #ifndef LOGGING_ON
00039 #define LOGGING_ON 0
00040 #endif
00041
00042 #ifndef DUMP_ON
00043 #define DUMP_ON 0
00044 #endif
00045
00046 #ifndef WARNING_ON
00047 #define WARNING_ON 1
00048 #endif
00049
00050 #ifndef ERROR_ON
00051 #define ERROR_ON 1
00052 #endif
00053
00054
00055 #if (USE_SYSLOG)
00056 #include <syslog.h>
00057 #define LOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_USER)
00058 #define LOG_CLOSE() closelog()
00059 #else
00060 #define LOG_OPEN(X) do {} while (0)
00061 #define LOG_CLOSE() do {} while (0)
00062 #endif
00063
00064 #if (LOGGING_ON)
00065 #if (USE_SYSLOG)
00066 #define LOGPRINTF(format, args...) syslog(LOG_INFO | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00067 #else
00068 #define LOGPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_L)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00069 #endif
00070 #else
00071 #define LOGPRINTF(format, args...) do {} while (0)
00072 #endif
00073
00074 #if (DUMP_ON)
00075 #if (USE_SYSLOG)
00076 #define DUMPPRINTF(format, args...) syslog(LOG_INFO | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00077 #else
00078 #define DUMPPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_DUMP)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00079 #endif
00080 #else
00081 #define DUMPPRINTF(format, args...) do {} while (0)
00082 #endif
00083
00084 #if (WARNING_ON)
00085 #if (USE_SYSLOG)
00086 #define WARNPRINTF(format, args...) syslog(LOG_WARNING | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00087 #else
00088 #define WARNPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_W)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00089 #endif
00090 #else
00091 #define WARNPRINTF(format, args...) do {} while (0)
00092 #endif
00093
00094 #if (ERROR_ON)
00095 #include <errno.h>
00096 #include <string.h>
00097 #if (USE_SYSLOG)
00098 #define ERRORPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00099 #define ERRNOPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00100 #else
00101 #define ERRORPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00102 #define ERRNOPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00103 #endif
00104 #else
00105 #define ERRORPRINTF(format, args...) do {} while (0)
00106 #define ERRNOPRINTF(format, args...) do {} while (0)
00107 #endif
00108
00109
00110
00111
00112 #define ERSCRIBBLE_RET_FALSE_IF(expr, x, args...) if (expr) { ERRORPRINTF(x, ##args); return FALSE; }
00113 #define ERSCRIBBLE_RET_NULL_IF(expr, x, args...) if (expr) { ERRORPRINTF(x, ##args); return NULL; }
00114 #define ERSCRIBBLE_RET_IF(expr, x, args...) if (expr) { ERRORPRINTF(x, ##args); return; }
00115 #define ERSCRIBBLE_RET_INT_IF(expr, ret, x, args...) if (expr) { ERRORPRINTF(x, ##args); return ret; }
00116
00117 #endif