00001
00002
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 #ifndef dprint_h
00029 #define dprint_h
00030
00031 #include <assert.h>
00032 #include <syslog.h>
00033 #include <stdio.h>
00034
00035 #include "compiler_opt.h"
00036 #include "cfg_core.h"
00037
00038
00039
00040 #if __STDC_VERSION__ < 199901L
00041 # if __GNUC__ >= 2
00042 # define _FUNC_NAME_ __FUNCTION__
00043 # else
00044 # define _FUNC_NAME_ ""
00045 # endif
00046 #else
00047 # define _FUNC_NAME_ __func__
00048 #endif
00049
00050 #ifdef NO_DEBUG
00051 # ifdef MOD_NAME
00052 # define LOC_INFO MOD_NAME ": "
00053 # else
00054 # define LOC_INFO "<core>: "
00055 # endif
00056 #else
00057 # define XCT2STR(i) #i
00058 # define CT2STR(l) XCT2STR(l)
00059 #
00060 # ifdef MOD_NAME
00061 # define LOC_INFO MOD_NAME " [" __FILE__ ":" CT2STR(__LINE__) "]: "
00062 # else
00063 # define LOC_INFO "<core> [" __FILE__ ":" CT2STR(__LINE__) "]: "
00064 # endif
00065 #
00066 # ifdef NO_LOG
00067 # undef NO_LOG
00068 # endif
00069 #endif
00070
00071
00072
00073
00074
00075 #define L_ALERT -4
00076 #define L_BUG -3
00077 #define L_CRIT -2
00078 #define L_ERR -1
00079 #define L_WARN 0
00080 #define L_NOTICE 1
00081 #define L_INFO 2
00082 #define L_DBG 3
00083
00084 #define LOG_LEVEL2NAME(level) (log_level_info[(level) - (L_ALERT)].name)
00085 #define LOG2SYSLOG_LEVEL(level) \
00086 (log_level_info[(level) - (L_ALERT)].syslog_level)
00087
00088
00089
00090
00091 extern int process_no;
00092 extern int my_pid();
00093
00094
00095 extern int log_stderr;
00096
00097
00098
00099 struct log_level_info {
00100 char *name;
00101 int syslog_level;
00102 };
00103
00104 extern struct log_level_info log_level_info[];
00105
00106 #ifndef NO_SIG_DEBUG
00107
00108 extern volatile int dprint_crit;
00109 #endif
00110
00111 int str2facility(char *s);
00112 int log_facility_fixup(void *handle, str *gname, str *name, void **val);
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 #ifdef NO_LOG
00125
00126 # ifdef __SUNPRO_C
00127 # define LOG_(level, prefix, fmt, ...)
00128 # define LOG(level, fmt, ...)
00129 # else
00130 # define LOG_(level, prefix, fmt, args...)
00131 # define LOG(level, fmt, args...)
00132 # endif
00133
00134 #else
00135
00136 # ifdef NO_SIG_DEBUG
00137 # define DPRINT_NON_CRIT (1)
00138 # define DPRINT_CRIT_ENTER
00139 # define DPRINT_CRIT_EXIT
00140 # else
00141 # define DPRINT_NON_CRIT (dprint_crit==0)
00142 # define DPRINT_CRIT_ENTER (dprint_crit++)
00143 # define DPRINT_CRIT_EXIT (dprint_crit--)
00144 # endif
00145
00146 # ifdef __SUNPRO_C
00147 # define LOG_(level, prefix, fmt, ...) \
00148 do { \
00149 if (unlikely(cfg_get(core, core_cfg, debug) >= (level) && \
00150 DPRINT_NON_CRIT)) { \
00151 DPRINT_CRIT_ENTER; \
00152 if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \
00153 if (unlikely(log_stderr)) { \
00154 fprintf(stderr, "%2d(%d) %s: %s" fmt, \
00155 process_no, my_pid(), \
00156 LOG_LEVEL2NAME(level), (prefix), \
00157 __VA_ARGS__); \
00158 } else { \
00159 syslog(LOG2SYSLOG_LEVEL(level) | \
00160 cfg_get(core, core_cfg, log_facility),\
00161 "%s: %s" fmt, LOG_LEVEL2NAME(level),\
00162 (prefix), __VA_ARGS__); \
00163 } \
00164 } else { \
00165 if (log_stderr) { \
00166 fprintf(stderr, "%2d(%d) %s" fmt, \
00167 process_no, my_pid(), \
00168 (prefix), __VA_ARGS__); \
00169 } else { \
00170 if ((level)<L_ALERT) \
00171 syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
00172 cfg_get(core, core_cfg, log_facility),\
00173 "%s" fmt, (prefix), __VA_ARGS__); \
00174 else \
00175 syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
00176 cfg_get(core, core_cfg, log_facility),\
00177 "%s" fmt, (prefix), __VA_ARGS__); \
00178 } \
00179 } \
00180 DPRINT_CRIT_EXIT; \
00181 } \
00182 } while(0)
00183
00184 # define LOG(level, fmt, ...) LOG_((level), LOC_INFO, fmt, __VA_ARGS__)
00185
00186 # else
00187 # define LOG_(level, prefix, fmt, args...) \
00188 do { \
00189 if (cfg_get(core, core_cfg, debug) >= (level) && \
00190 DPRINT_NON_CRIT) { \
00191 DPRINT_CRIT_ENTER; \
00192 if (likely(((level) >= L_ALERT) && ((level) <= L_DBG))){ \
00193 if (unlikely(log_stderr)) { \
00194 fprintf(stderr, "%2d(%d) %s: %s" fmt, \
00195 process_no, my_pid(), \
00196 LOG_LEVEL2NAME(level),(prefix), ## args);\
00197 } else { \
00198 syslog(LOG2SYSLOG_LEVEL(level) |\
00199 cfg_get(core, core_cfg, log_facility), \
00200 "%s: %s" fmt, LOG_LEVEL2NAME(level),\
00201 (prefix), ## args); \
00202 } \
00203 } else { \
00204 if (log_stderr) { \
00205 fprintf(stderr, "%2d(%d) %s" fmt, \
00206 process_no, my_pid(), \
00207 (prefix), ## args); \
00208 } else { \
00209 if ((level)<L_ALERT) \
00210 syslog(LOG2SYSLOG_LEVEL(L_ALERT) | \
00211 cfg_get(core, core_cfg, log_facility),\
00212 "%s" fmt, (prefix), ## args); \
00213 else \
00214 syslog(LOG2SYSLOG_LEVEL(L_DBG) | \
00215 cfg_get(core, core_cfg, log_facility),\
00216 "%s" fmt, (prefix), ## args); \
00217 } \
00218 } \
00219 DPRINT_CRIT_EXIT; \
00220 } \
00221 } while(0)
00222
00223 # define LOG(level, fmt, args...) LOG_((level), LOC_INFO, fmt, ## args)
00224
00225 # endif
00226 #endif
00227
00228
00229
00230
00231
00232 #ifdef __SUNPRO_C
00233 # define ALERT(...) LOG(L_ALERT, __VA_ARGS__)
00234 # define BUG(...) LOG(L_BUG, __VA_ARGS__)
00235 # define ERR(...) LOG(L_ERR, __VA_ARGS__)
00236 # define WARN(...) LOG(L_WARN, __VA_ARGS__)
00237 # define NOTICE(...) LOG(L_NOTICE, __VA_ARGS__)
00238 # define INFO(...) LOG(L_INFO, __VA_ARGS__)
00239
00240 # ifdef NO_DEBUG
00241 # define DBG(...)
00242 # else
00243 # define DBG(...) LOG(L_DBG, __VA_ARGS__)
00244 # endif
00245
00246
00247 # define DEBUG(...) DBG(__VA_ARGS__)
00248
00249 #else
00250 # define ALERT(fmt, args...) LOG(L_ALERT, fmt, ## args)
00251 # define BUG(fmt, args...) LOG(L_BUG, fmt, ## args)
00252 # define ERR(fmt, args...) LOG(L_ERR, fmt, ## args)
00253 # define WARN(fmt, args...) LOG(L_WARN, fmt, ## args)
00254 # define NOTICE(fmt, args...) LOG(L_NOTICE, fmt, ## args)
00255 # define INFO(fmt, args...) LOG(L_INFO, fmt, ## args)
00256
00257 # ifdef NO_DEBUG
00258 # define DBG(fmt, args...)
00259 # else
00260 # define DBG(fmt, args...) LOG(L_DBG, fmt, ## args)
00261 # endif
00262
00263
00264 # define DEBUG(fmt, args...) DBG(fmt, ## args)
00265
00266 #endif
00267
00268
00269 #endif