eripc/include/log.h

Go to the documentation of this file.
00001 #ifndef LOG_H
00002 #define LOG_H
00003 
00004 /**
00005  * @addtogroup eripc
00006  * @{
00007   @file log.h
00008   @brief The logging macros
00009   <p>
00010   Macro definitions that have an effect to the logging macros:
00011   
00012   DEBUG, OSSOLOG_COMPILE    Whether to compile the macros
00013                             (prefer OSSOLOG_COMPILE over DEBUG)
00014   OSSOLOG_STDOUT            All logging to stdout(*
00015   OSSOLOG_STDERR            All logging to stderr(*
00016 
00017   *) No timestamp nor file name.
00018 
00019   To see the logging output of D-Bus-activated programs, define
00020   DBUS_DEBUG_OUTPUT environment variable for the D-Bus daemon and
00021   define the OSSOLOG_STDERR macro at compile time.
00022 
00023   Note that these macros are provided because Glib logging does not
00024   currently allow stripping the logging function calls away at
00025   compile time.
00026   </p>
00027  */
00028 
00029 /*
00030  * This file is part of liberipc.
00031  *
00032  * liberipc is free software: you can redistribute it and/or modify
00033  * it under the terms of the GNU General Public License as published by
00034  * the Free Software Foundation, either version 2 of the License, or
00035  * (at your option) any later version.
00036  *
00037  * liberipc is distributed in the hope that it will be useful,
00038  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00039  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00040  * GNU General Public License for more details.
00041  *
00042  * You should have received a copy of the GNU General Public License
00043  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00044  */
00045 
00046 /**
00047  * Copyright (C) 2008 iRex Technologies B.V. 
00048  * All rights reserved.
00049  *
00050  * Based on code found in libosso library by Kimmo Hämäläinen <kimmo.hamalainen@nokia.com>
00051  */
00052 
00053 // Uncomment the two defines below to enable logging to console
00054 //#define DEBUG
00055 //#define OSSOLOG_STDERR
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> /* printf(), fprintf() */
00064 #else
00065 #include <syslog.h> /* syslog(), openlog(), closelog() */
00066 #endif
00067 #endif
00068 
00069 /*** the macros ***/
00070 
00071 #ifdef OSSOLOG_COMPILE
00072 
00073 /* the binary has logging compiled in */
00074 
00075 #if !defined OSSOLOG_STDOUT && !defined OSSOLOG_STDERR
00076 
00077 /* log to the syslog */
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 /* log to the stdout */
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 /* log to the stderr */
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 /* !defined OSSOLOG_STDOUT && !defined OSSOLOG_STDERR */
00256 
00257 #else
00258 
00259 /* no logging is compiled to the binary */
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 /* OSSOLOG_COMPILE */
00298 
00299 /** @} */
00300 
00301 #endif /* LOG_H */
Generated by  doxygen 1.6.2-20100208