00001 #ifndef __ERUTILS_LOG_H__
00002 #define __ERUTILS_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 #include <stdio.h>
00032
00033 #define LOG_PREFIX "ERUTILS"
00034
00035 #ifndef USE_SYSLOG
00036 #define USE_SYSLOG 0
00037 #endif
00038
00039 #ifndef LOGGING_ON
00040 #define LOGGING_ON 0
00041 #endif
00042
00043 #ifndef WARNING_ON
00044 #define WARNING_ON 1
00045 #endif
00046
00047 #ifndef ERROR_ON
00048 #define ERROR_ON 1
00049 #endif
00050
00051
00052 #if (USE_SYSLOG)
00053 #include <syslog.h>
00054 #define LOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_USER)
00055 #define LOG_CLOSE() closelog()
00056 #else
00057 #define LOG_OPEN(X) do {} while (0)
00058 #define LOG_CLOSE() do {} while (0)
00059 #endif
00060
00061 #if (LOGGING_ON)
00062 #if (USE_SYSLOG)
00063 #define LOGPRINTF(format, args...) syslog(LOG_INFO | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00064 #else
00065 #define LOGPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_L)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00066 #endif
00067 #else
00068 #define LOGPRINTF(format, args...) do {} while (0)
00069 #endif
00070
00071 #if (WARNING_ON)
00072 #if (USE_SYSLOG)
00073 #define WARNPRINTF(format, args...) syslog(LOG_WARNING | LOG_USER, __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00074 #else
00075 #define WARNPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_W)" __FILE__ ":%d,%s() " format "\n", __LINE__, __func__ , ##args)
00076 #endif
00077 #else
00078 #define WARNPRINTF(format, args...) do {} while (0)
00079 #endif
00080
00081 #if (ERROR_ON)
00082 #include <errno.h>
00083 #include <string.h>
00084 #if (USE_SYSLOG)
00085 #define ERRORPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00086 #define ERRNOPRINTF(format, args...) syslog(LOG_ERR | LOG_USER, __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00087 #else
00088 #define ERRORPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format "\n", __LINE__, __func__ , ##args)
00089 #define ERRNOPRINTF(format, args...) fprintf(stderr, "(" LOG_PREFIX "_E)" __FILE__ ":%d,%s() --- " format ", errno [%d] [%s]\n", __LINE__, __func__ , ##args, errno, strerror(errno))
00090 #endif
00091 #else
00092 #define ERRORPRINTF(format, args...) do {} while (0)
00093 #define ERRNOPRINTF(format, args...) do {} while (0)
00094 #endif
00095
00096 #endif // __ERUTILS_LOG_H__