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