00001 #ifndef __ERMETADB_LOG_H__
00002 #define __ERMETADB_LOG_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
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdio.h>
00039
00040 #define LOG_PREFIX "ERMDB"
00041
00042 #ifndef USE_SYSLOG
00043 #define USE_SYSLOG 0
00044 #endif
00045
00046 #ifndef TRACING_ON
00047 #define TRACING_ON 0
00048 #endif
00049
00050 #ifndef LOGGING_ON
00051 #define LOGGING_ON 0
00052 #endif
00053
00054 #ifndef QUERY_ON
00055 #define QUERY_ON 0
00056 #endif
00057
00058 #ifndef WARNING_ON
00059 #define WARNING_ON 1
00060 #endif
00061
00062 #ifndef ERROR_ON
00063 #define ERROR_ON 1
00064 #endif
00065
00066
00067 #if (USE_SYSLOG)
00068 #include <syslog.h>
00069 #define LOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_USER)
00070 #define LOG_CLOSE() closelog()
00071 #else
00072 #define LOG_OPEN(X) do {} while (0)
00073 #define LOG_CLOSE() do {} while (0)
00074 #endif
00075
00076 #if (TRACING_ON)
00077 #define TRACE(format, args...) fprintf(stderr, "(" LOG_PREFIX "_L)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00078 #else
00079 #define TRACE(format, args...) do {} while (0)
00080 #endif
00081
00082 #if (LOGGING_ON)
00083 #if (USE_SYSLOG)
00084 #define LOGPRINTF(format, args...) syslog(LOG_INFO | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00085 #else
00086 #define LOGPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_L)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00087 #endif
00088 #else
00089 #define LOGPRINTF(format, args...) do {} while (0)
00090 #endif
00091
00092 #if (QUERY_ON)
00093 #if (USE_SYSLOG)
00094 #define QUERYPRINTF(format, args...) syslog(LOG_INFO | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00095 #else
00096 #define QUERYPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_Q)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00097 #endif
00098 #else
00099 #define QUERYPRINTF(format, args...) do {} while (0)
00100 #endif
00101
00102 #if (WARNING_ON)
00103 #if (USE_SYSLOG)
00104 #define WARNPRINTF(format, args...) syslog(LOG_WARNING | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00105 #else
00106 #define WARNPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_W)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00107 #endif
00108 #else
00109 #define WARNPRINTF(format, args...) do {} while (0)
00110 #endif
00111
00112 #if (ERROR_ON)
00113 #include <errno.h>
00114 #include <string.h>
00115 #if (USE_SYSLOG)
00116 #define ERRORPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00117 #define ERRNOPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00118 #else
00119 #define ERRORPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00120 #define ERRNOPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00121 #endif
00122 #else
00123 #define ERRORPRINTF(format, args...) do {} while (0)
00124 #define ERRNOPRINTF(format, args...) do {} while (0)
00125 #endif
00126
00127 #endif // __ERMETADB_LOG_H__