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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #ifdef DEBUG
00058 #define OSSOLOG_COMPILE
00059 #endif
00060
00061 #ifdef OSSOLOG_COMPILE
00062 #if defined OSSOLOG_STDOUT || defined OSSOLOG_STDERR
00063 #include <stdio.h>
00064 #else
00065 #include <syslog.h>
00066 #endif
00067 #endif
00068
00069
00070
00071 #ifdef OSSOLOG_COMPILE
00072
00073
00074
00075 #if !defined OSSOLOG_STDOUT && !defined OSSOLOG_STDERR
00076
00077
00078
00079 #define ULOG_CRIT(...) syslog(LOG_CRIT | LOG_USER, __VA_ARGS__)
00080 #define ULOG_ERR(...) syslog(LOG_ERR | LOG_USER, __VA_ARGS__)
00081 #define ULOG_WARN(...) syslog(LOG_WARNING | LOG_USER, __VA_ARGS__)
00082 #define ULOG_INFO(...) syslog(LOG_INFO | LOG_USER, __VA_ARGS__)
00083 #define ULOG_DEBUG(...) syslog(LOG_DEBUG | LOG_USER, __VA_ARGS__)
00084 #define ULOG_CRIT_L(FMT, ARG...) syslog(LOG_CRIT | LOG_USER, \
00085 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00086 #define ULOG_ERR_L(FMT, ARG...) syslog(LOG_ERR | LOG_USER, \
00087 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00088 #define ULOG_WARN_L(FMT, ARG...) syslog(LOG_WARNING | LOG_USER, \
00089 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00090 #define ULOG_INFO_L(FMT, ARG...) syslog(LOG_INFO | LOG_USER, \
00091 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00092 #define ULOG_DEBUG_L(FMT, ARG...) syslog(LOG_DEBUG | LOG_USER, \
00093 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00094 #define ULOG_CRIT_F(FMT, ARG...) syslog(LOG_CRIT | LOG_USER, \
00095 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00096 #define ULOG_ERR_F(FMT, ARG...) syslog(LOG_ERR | LOG_USER, \
00097 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00098 #define ULOG_WARN_F(FMT, ARG...) syslog(LOG_WARNING | LOG_USER, \
00099 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00100 #define ULOG_INFO_F(FMT, ARG...) syslog(LOG_INFO | LOG_USER, \
00101 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00102 #define ULOG_DEBUG_F(FMT, ARG...) syslog(LOG_DEBUG | LOG_USER, \
00103 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00104
00105 #define DLOG_CRIT(...) syslog(LOG_CRIT | LOG_DAEMON, __VA_ARGS__)
00106 #define DLOG_ERR(...) syslog(LOG_ERR | LOG_DAEMON, __VA_ARGS__)
00107 #define DLOG_WARN(...) syslog(LOG_WARNING | LOG_DAEMON, __VA_ARGS__)
00108 #define DLOG_INFO(...) syslog(LOG_INFO | LOG_DAEMON, __VA_ARGS__)
00109 #define DLOG_DEBUG(...) syslog(LOG_DEBUG | LOG_DAEMON, __VA_ARGS__)
00110 #define DLOG_CRIT_L(FMT, ARG...) syslog(LOG_CRIT | LOG_DAEMON, \
00111 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00112 #define DLOG_ERR_L(FMT, ARG...) syslog(LOG_ERR | LOG_DAEMON, \
00113 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00114 #define DLOG_WARN_L(FMT, ARG...) syslog(LOG_WARNING | LOG_DAEMON, \
00115 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00116 #define DLOG_INFO_L(FMT, ARG...) syslog(LOG_INFO | LOG_DAEMON, \
00117 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00118 #define DLOG_DEBUG_L(FMT, ARG...) syslog(LOG_DEBUG | LOG_DAEMON, \
00119 "%s:%d: " FMT, __FILE__, __LINE__, ## ARG)
00120 #define DLOG_CRIT_F(FMT, ARG...) syslog(LOG_CRIT | LOG_DAEMON, \
00121 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00122 #define DLOG_ERR_F(FMT, ARG...) syslog(LOG_ERR | LOG_DAEMON, \
00123 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00124 #define DLOG_WARN_F(FMT, ARG...) syslog(LOG_WARNING | LOG_DAEMON, \
00125 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00126 #define DLOG_INFO_F(FMT, ARG...) syslog(LOG_INFO | LOG_DAEMON, \
00127 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00128 #define DLOG_DEBUG_F(FMT, ARG...) syslog(LOG_DEBUG | LOG_DAEMON, \
00129 "%s:%d: " FMT, __FUNCTION__, __LINE__, ## ARG)
00130
00131 #define ULOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_USER)
00132 #define DLOG_OPEN(X) openlog(X, LOG_PID | LOG_NDELAY, LOG_DAEMON)
00133 #define LOG_CLOSE() closelog()
00134
00135 #elif defined OSSOLOG_STDOUT
00136
00137
00138
00139 #define ULOG_CRIT(...) (drint(__VA_ARGS__),dprint("\n"))
00140 #define ULOG_ERR(...) (dprint(__VA_ARGS__),dprint("\n"))
00141 #define ULOG_WARN(...) (dprint(__VA_ARGS__),dprint("\n"))
00142 #define ULOG_INFO(...) (dprint(__VA_ARGS__),dprint("\n"))
00143 #define ULOG_DEBUG(...) (dprint(__VA_ARGS__),dprint("\n"))
00144 #define ULOG_CRIT_L(FMT, ARG...) dprint(\
00145 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00146 #define ULOG_ERR_L(FMT, ARG...) dprint(\
00147 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00148 #define ULOG_WARN_L(FMT, ARG...) dprint(\
00149 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00150 #define ULOG_INFO_L(FMT, ARG...) dprint(\
00151 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00152 #define ULOG_DEBUG_L(FMT, ARG...) dprint(\
00153 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00154 #define ULOG_CRIT_F(FMT, ARG...) dprint(\
00155 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00156 #define ULOG_ERR_F(FMT, ARG...) dprint(\
00157 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00158 #define ULOG_WARN_F(FMT, ARG...) dprint(\
00159 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00160 #define ULOG_INFO_F(FMT, ARG...) dprint(\
00161 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00162 #define ULOG_DEBUG_F(FMT, ARG...) dprint(\
00163 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00164
00165 #define DLOG_CRIT(...) (dprint(__VA_ARGS__),dprint("\n"))
00166 #define DLOG_ERR(...) (dprint(__VA_ARGS__),dprint("\n"))
00167 #define DLOG_WARN(...) (dprint(__VA_ARGS__),dprint("\n"))
00168 #define DLOG_INFO(...) (dprint(__VA_ARGS__),dprint("\n"))
00169 #define DLOG_DEBUG(...) (dprint(__VA_ARGS__),dprint("\n"))
00170 #define DLOG_CRIT_L(FMT, ARG...) dprint(\
00171 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00172 #define DLOG_ERR_L(FMT, ARG...) dprint(\
00173 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00174 #define DLOG_WARN_L(FMT, ARG...) dprint(\
00175 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00176 #define DLOG_INFO_L(FMT, ARG...) dprint(\
00177 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00178 #define DLOG_DEBUG_L(FMT, ARG...) dprint(\
00179 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00180 #define DLOG_CRIT_F(FMT, ARG...) dprint(\
00181 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00182 #define DLOG_ERR_F(FMT, ARG...) dprint(\
00183 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00184 #define DLOG_WARN_F(FMT, ARG...) dprint(\
00185 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00186 #define DLOG_INFO_F(FMT, ARG...) dprint(\
00187 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00188 #define DLOG_DEBUG_F(FMT, ARG...) dprint(\
00189 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00190
00191 #define ULOG_OPEN(X) do {} while (0)
00192 #define DLOG_OPEN(X) do {} while (0)
00193 #define LOG_CLOSE() do {} while (0)
00194
00195 #else
00196
00197
00198
00199 #define ULOG_CRIT(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00200 #define ULOG_ERR(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00201 #define ULOG_WARN(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00202 #define ULOG_INFO(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00203 #define ULOG_DEBUG(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00204 #define ULOG_CRIT_L(FMT, ARG...) fprintf(stderr, \
00205 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00206 #define ULOG_ERR_L(FMT, ARG...) fprintf(stderr, \
00207 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00208 #define ULOG_WARN_L(FMT, ARG...) fprintf(stderr, \
00209 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00210 #define ULOG_INFO_L(FMT, ARG...) fprintf(stderr, \
00211 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00212 #define ULOG_DEBUG_L(FMT, ARG...) fprintf(stderr, \
00213 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00214 #define ULOG_CRIT_F(FMT, ARG...) fprintf(stderr, \
00215 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00216 #define ULOG_ERR_F(FMT, ARG...) fprintf(stderr, \
00217 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00218 #define ULOG_WARN_F(FMT, ARG...) fprintf(stderr, \
00219 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00220 #define ULOG_INFO_F(FMT, ARG...) fprintf(stderr, \
00221 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00222 #define ULOG_DEBUG_F(FMT, ARG...) fprintf(stderr, \
00223 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00224
00225 #define DLOG_CRIT(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00226 #define DLOG_ERR(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00227 #define DLOG_WARN(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00228 #define DLOG_INFO(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00229 #define DLOG_DEBUG(...) (fprintf(stderr, __VA_ARGS__),fprintf(stderr, "\n"))
00230 #define DLOG_CRIT_L(FMT, ARG...) fprintf(stderr, \
00231 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00232 #define DLOG_ERR_L(FMT, ARG...) fprintf(stderr, \
00233 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00234 #define DLOG_WARN_L(FMT, ARG...) fprintf(stderr, \
00235 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00236 #define DLOG_INFO_L(FMT, ARG...) fprintf(stderr, \
00237 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00238 #define DLOG_DEBUG_L(FMT, ARG...) fprintf(stderr, \
00239 "%s:%d: " FMT "\n", __FILE__, __LINE__, ## ARG)
00240 #define DLOG_CRIT_F(FMT, ARG...) fprintf(stderr, \
00241 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00242 #define DLOG_ERR_F(FMT, ARG...) fprintf(stderr, \
00243 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00244 #define DLOG_WARN_F(FMT, ARG...) fprintf(stderr, \
00245 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00246 #define DLOG_INFO_F(FMT, ARG...) fprintf(stderr, \
00247 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00248 #define DLOG_DEBUG_F(FMT, ARG...) fprintf(stderr, \
00249 "%s:%d: " FMT "\n", __FUNCTION__, __LINE__, ## ARG)
00250
00251 #define ULOG_OPEN(X) do {} while (0)
00252 #define DLOG_OPEN(X) do {} while (0)
00253 #define LOG_CLOSE() do {} while (0)
00254
00255 #endif
00256
00257 #else
00258
00259
00260
00261 #define ULOG_CRIT(...) do {} while (0)
00262 #define ULOG_ERR(...) do {} while (0)
00263 #define ULOG_WARN(...) do {} while (0)
00264 #define ULOG_INFO(...) do {} while (0)
00265 #define ULOG_DEBUG(...) do {} while (0)
00266 #define ULOG_CRIT_L(...) do {} while (0)
00267 #define ULOG_ERR_L(...) do {} while (0)
00268 #define ULOG_WARN_L(...) do {} while (0)
00269 #define ULOG_INFO_L(...) do {} while (0)
00270 #define ULOG_DEBUG_L(...) do {} while (0)
00271 #define ULOG_CRIT_F(...) do {} while (0)
00272 #define ULOG_ERR_F(...) do {} while (0)
00273 #define ULOG_WARN_F(...) do {} while (0)
00274 #define ULOG_INFO_F(...) do {} while (0)
00275 #define ULOG_DEBUG_F(...) do {} while (0)
00276
00277 #define DLOG_CRIT(...) do {} while (0)
00278 #define DLOG_ERR(...) do {} while (0)
00279 #define DLOG_WARN(...) do {} while (0)
00280 #define DLOG_INFO(...) do {} while (0)
00281 #define DLOG_DEBUG(...) do {} while (0)
00282 #define DLOG_CRIT_L(...) do {} while (0)
00283 #define DLOG_ERR_L(...) do {} while (0)
00284 #define DLOG_WARN_L(...) do {} while (0)
00285 #define DLOG_INFO_L(...) do {} while (0)
00286 #define DLOG_DEBUG_L(...) do {} while (0)
00287 #define DLOG_CRIT_F(...) do {} while (0)
00288 #define DLOG_ERR_F(...) do {} while (0)
00289 #define DLOG_WARN_F(...) do {} while (0)
00290 #define DLOG_INFO_F(...) do {} while (0)
00291 #define DLOG_DEBUG_F(...) do {} while (0)
00292
00293 #define ULOG_OPEN(X) do {} while (0)
00294 #define DLOG_OPEN(X) do {} while (0)
00295 #define LOG_CLOSE() do {} while (0)
00296
00297 #endif
00298
00299
00300
00301 #endif