00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00016 00017 /*! 00018 * @defgroup log Log system multiplexer 00019 * 00020 * The log system multiplexer allows the caller to send log messages to multiple 00021 * destinations; currently: syslog(3), file, stderr. 00022 * 00023 * An application can only open one connection to the multiplexer during 00024 * runtime. Another call to log_init() will replace the previous connection. 00025 * 00026 * log_init() opens a connection to the multiplexer for a program. The options 00027 * argument is a pointer to a log_options_t structure used for the multiplexer 00028 * configuration. 00029 * 00030 * @see log_options_t 00031 * @see syslog(3) 00032 * 00033 * @{ 00034 */ 00035 00036 #ifndef _LUCID_LOG_H 00037 #define _LUCID_LOG_H 00038 00039 #include <stdarg.h> 00040 00041 /* destinations */ 00042 #define LOGD_SYSLOG 0x01 /*!< Log to syslog */ 00043 #define LOGD_FILE 0x02 /*!< Log to a file */ 00044 #define LOGD_STDERR 0x04 /*!< Log to STDERR */ 00045 00046 /* priorities */ 00047 #define LOGP_ALERT 0 /*!< action must be taken immediately */ 00048 #define LOGP_ERROR 1 /*!< error conditions */ 00049 #define LOGP_WARN 2 /*!< warning conditions */ 00050 #define LOGP_NOTE 3 /*!< normal but significant condition */ 00051 #define LOGP_INFO 4 /*!< informational */ 00052 #define LOGP_DEBUG 5 /*!< debug-level messages */ 00053 #define LOGP_TRACE 6 /*!< trace messages */ 00054 00055 /* options */ 00056 #define LOGO_PID 0x01 /*!< log the pid with each message */ 00057 #define LOGO_TIME 0x02 /*!< log the time with each message */ 00058 #define LOGO_PRIO 0x04 /*!< log the priority with each message */ 00059 #define LOGO_IDENT 0x08 /*!< log the ident string with each message */ 00060 00061 /*! @brief simple trace helper */ 00062 #define LOG_TRACEME log_traceme(__FILE__, __FUNCTION__, __LINE__); 00063 00064 /*! 00065 * @brief multiplexer configuration data 00066 * 00067 * - The string pointed to by log_ident is prepended to every message, and is 00068 * typically set to the program name. 00069 * - The log_dest argument specifies the log destination 00070 * - The log_facility argument is used to specify what type of program is logging 00071 * the message; only used for the syslog(3) destination. 00072 * - The log_opts argument specifies flags which control the operation of the 00073 * multiplexer. 00074 * - The log_mask argument is the lower level bound of messages being multiplexed. 00075 */ 00076 typedef struct { 00077 char *log_ident; /*!< program identifier */ 00078 int log_dest; /*!< file destination switch */ 00079 int log_fd; /*!< file descriptor for LOGD_FILE target */ 00080 int log_facility; /*!< program facility */ 00081 int log_opts; /*!< control flags */ 00082 int log_mask; /*!< lower log level bound */ 00083 } log_options_t; 00084 00085 /*! 00086 * @brief initialize log message mutliplexer 00087 * 00088 * @param[in] options multiplexer configuration 00089 * 00090 * @see log_options_t 00091 */ 00092 void log_init(log_options_t *options); 00093 00094 /*! 00095 * @brief send ALERT level message to the multiplexer 00096 * 00097 * @param[in] fmt format string passed to printf 00098 * @param[in] ... variable number of arguments according to fmt 00099 * 00100 * @return EXIT_FAILURE 00101 * 00102 * @see printf 00103 */ 00104 int log_alert(const char *fmt, ...); 00105 00106 /*! 00107 * @brief send ERR level message to the multiplexer 00108 * 00109 * @param[in] fmt format string passed to printf 00110 * @param[in] ... variable number of arguments according to fmt 00111 * 00112 * @return EXIT_FAILURE 00113 * 00114 * @see printf 00115 */ 00116 int log_error(const char *fmt, ...); 00117 00118 /*! 00119 * @brief send WARNING level message to the multiplexer 00120 * 00121 * @param[in] fmt format string passed to printf 00122 * @param[in] ... variable number of arguments according to fmt 00123 * 00124 * @return EXIT_SUCCESS 00125 * 00126 * @see printf 00127 */ 00128 int log_warn(const char *fmt, ...); 00129 00130 /*! 00131 * @brief send NOTICE level message to the multiplexer 00132 * 00133 * @param[in] fmt format string passed to printf 00134 * @param[in] ... variable number of arguments according to fmt 00135 * 00136 * @return EXIT_SUCCESS 00137 * 00138 * @see printf 00139 */ 00140 int log_notice(const char *fmt, ...); 00141 00142 /*! 00143 * @brief send INFO level message to the multiplexer 00144 * 00145 * @param[in] fmt format string passed to printf 00146 * @param[in] ... variable number of arguments according to fmt 00147 * 00148 * @return EXIT_SUCCESS 00149 * 00150 * @see printf 00151 */ 00152 int log_info(const char *fmt, ...); 00153 00154 /*! 00155 * @brief send DEBUG level message to the multiplexer 00156 * 00157 * @param[in] fmt format string passed to printf 00158 * @param[in] ... variable number of arguments according to fmt 00159 * 00160 * @return EXIT_SUCCESS 00161 * 00162 * @see printf 00163 */ 00164 int log_debug(const char *fmt, ...); 00165 00166 /*! 00167 * @brief send TRACE level message to the multiplexer 00168 * 00169 * @param[in] fmt format string passed to printf 00170 * @param[in] ... variable number of arguments according to fmt 00171 * 00172 * @return EXIT_SUCCESS 00173 * 00174 * @see printf 00175 */ 00176 int log_trace(const char *fmt, ...); 00177 00178 /*! 00179 * @brief send TRACE level message to the multiplexer 00180 * 00181 * @param[in] file File name 00182 * @param[in] func Function name 00183 * @param[in] line Line number 00184 * 00185 * @return EXIT_SUCCESS 00186 * 00187 * @see printf 00188 */ 00189 int log_traceme(const char *file, const char *func, int line); 00190 00191 00192 /*! 00193 * @brief send ALERT level message to the multiplexer and exit(2) 00194 * 00195 * @param[in] fmt format string passed to printf 00196 * @param[in] ... variable number of arguments according to fmt 00197 * 00198 * @see printf 00199 * @see exit(2) 00200 */ 00201 void log_alert_and_die(const char *fmt, ...); 00202 00203 /*! 00204 * @brief send ERR level message to the multiplexer and exit(2) 00205 * 00206 * @param[in] fmt format string passed to printf 00207 * @param[in] ... variable number of arguments according to fmt 00208 * 00209 * @see printf 00210 * @see exit(2) 00211 */ 00212 void log_error_and_die(const char *fmt, ...); 00213 00214 00215 /*! 00216 * @brief send ALERT level message to the multiplexer and append strerror(errno) 00217 * 00218 * @param[in] fmt format string passed to printf 00219 * @param[in] ... variable number of arguments according to fmt 00220 * 00221 * @return EXIT_FAILURE 00222 * 00223 * @see printf 00224 */ 00225 int log_palert(const char *fmt, ...); 00226 00227 /*! 00228 * @brief send ERR level message to the multiplexer and append strerror(errno) 00229 * 00230 * @param[in] fmt format string passed to printf 00231 * @param[in] ... variable number of arguments according to fmt 00232 * 00233 * @return EXIT_FAILURE 00234 * 00235 * @see printf 00236 */ 00237 int log_perror(const char *fmt, ...); 00238 00239 /*! 00240 * @brief send WARNING level message to the multiplexer and append strerror(errno) 00241 * 00242 * @param[in] fmt format string passed to printf 00243 * @param[in] ... variable number of arguments according to fmt 00244 * 00245 * @return EXIT_SUCCESS 00246 * 00247 * @see printf 00248 */ 00249 int log_pwarn(const char *fmt, ...); 00250 00251 /*! 00252 * @brief send NOTICE level message to the multiplexer and append strerror(errno) 00253 * 00254 * @param[in] fmt format string passed to printf 00255 * @param[in] ... variable number of arguments according to fmt 00256 * 00257 * @return EXIT_SUCCESS 00258 * 00259 * @see printf 00260 */ 00261 int log_pnotice(const char *fmt, ...); 00262 00263 /*! 00264 * @brief send INFO level message to the multiplexer and append strerror(errno) 00265 * 00266 * @param[in] fmt format string passed to printf 00267 * @param[in] ... variable number of arguments according to fmt 00268 * 00269 * @return EXIT_SUCCESS 00270 * 00271 * @see printf 00272 */ 00273 int log_pinfo(const char *fmt, ...); 00274 00275 /*! 00276 * @brief send DEBUG level message to the multiplexer and append strerror(errno) 00277 * 00278 * @param[in] fmt format string passed to printf 00279 * @param[in] ... variable number of arguments according to fmt 00280 * 00281 * @return EXIT_SUCCESS 00282 * 00283 * @see printf 00284 */ 00285 int log_pdebug(const char *fmt, ...); 00286 00287 /*! 00288 * @brief send TRACE level message to the multiplexer and append strerror(errno) 00289 * 00290 * @param[in] fmt format string passed to printf 00291 * @param[in] ... variable number of arguments according to fmt 00292 * 00293 * @return EXIT_SUCCESS 00294 * 00295 * @see printf 00296 */ 00297 int log_ptrace(const char *fmt, ...); 00298 00299 00300 /*! 00301 * @brief send ALERT level message to the multiplexer, append strerror(errno) and exit(2) 00302 * 00303 * @param[in] fmt format string passed to printf 00304 * @param[in] ... variable number of arguments according to fmt 00305 * 00306 * @see printf 00307 * @see exit(2) 00308 */ 00309 void log_palert_and_die(const char *fmt, ...); 00310 00311 /*! 00312 * @brief send ERR level message to the multiplexer, append strerror(errno) and exit(2) 00313 * 00314 * @param[in] fmt format string passed to printf 00315 * @param[in] ... variable number of arguments according to fmt 00316 * 00317 * @see printf 00318 * @see exit(2) 00319 */ 00320 void log_perror_and_die(const char *fmt, ...); 00321 00322 /*! 00323 * @brief close connection to logging system 00324 */ 00325 void log_close(void); 00326 00327 #endif 00328 00329 /*! @} log */