log.h

Go to the documentation of this file.
00001 // Copyright 2006 Benedikt Böhm <hollow@gentoo.org>
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (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
00015 // Free Software Foundation, Inc.,
00016 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 
00018 /*!
00019  * @defgroup log Log system multiplexer
00020  *
00021  * The log system multiplexer allows the caller to send log messages to multiple
00022  * destinations; currently: syslog(3), file, stderr.
00023  *
00024  * An application can only open one connection to the multiplexer during
00025  * runtime. Another call to log_init() will replace the previous connection.
00026  *
00027  * log_init() opens a connection to the multiplexer for a program. The options
00028  * argument is a pointer to a log_options_t structure used for the multiplexer 
00029  * configuration.
00030  *
00031  * @see log_options_t
00032  * @see syslog(3)
00033  *
00034  * @{
00035  */
00036 
00037 #ifndef _LUCID_LOG_H
00038 #define _LUCID_LOG_H
00039 
00040 #include <stdbool.h>
00041 #include <stdarg.h>
00042 #include <libgen.h>
00043 
00044 /*!
00045  * @brief multiplexer configuration data
00046  *
00047  * - The string pointed to by ident is prepended to every message, and is
00048  *   typically set to the program name.
00049  * - The file argument enables (1) or disables (0) multiplexing to the
00050  *   file destination.
00051  * - The stderr argument enables (1) or disables (0) multiplexing to the
00052  *   stderr destination.
00053  * - The time argument enables (1) or disables (0) output of the time string in
00054  *   multiplexed messages; only used for the file and stderr destinations.
00055  * - The syslog argument enables (1) or disables (0) multiplexing to the
00056  *   syslog(3) destination.
00057  * - The flags argument specifies flags which control the operation of the
00058  *   multiplexer.
00059  * - The facility argument is used to specify what type of program is logging
00060  *   the message; only used for the syslog(3) destination.
00061  * - The mask argument is the lower level bound of messages being multiplexed.
00062  */
00063 typedef struct {
00064         char *ident;    /*!< program identifier */
00065         bool  file;     /*!< file destination switch */
00066         int   fd;       /*!< file descriptor */
00067         bool  stderr;   /*!< stderr destination switch */
00068         bool  time;     /*!< time output switch */
00069         bool  syslog;   /*!< syslog destination switch */
00070         int   flags;    /*!< control flags */
00071         int   facility; /*!< program facility */
00072         int   mask;     /*!< lower level bound */
00073 } log_options_t;
00074 
00075 /*!
00076  * @brief initialize log message mutliplexer
00077  *
00078  * @param[in] options multiplexer configuration
00079  *
00080  * @see log_options_t
00081  */
00082 void log_init(log_options_t *options);
00083 
00084 void log_internal(int level, int strerr, const char *fmt, va_list ap);
00085 
00086 /*! @brief simple trace helper */
00087 #define LOG_TRACEME log_debug("[trace] %s (%s:%d)", \
00088                           __FUNCTION__, basename(__FILE__), __LINE__);
00089 
00090 /*!
00091  * @brief send EMERG level message to the multiplexer
00092  *
00093  * @param[in] fmt format string passed to printf
00094  * @param[in] ... variable number of arguments according to fmt
00095  *
00096  * @return EXIT_FAILURE
00097  *
00098  * @see printf
00099  */
00100 int log_emerg(const char *fmt, ...);
00101 
00102 /*!
00103  * @brief send ALERT level message to the multiplexer
00104  *
00105  * @param[in] fmt format string passed to printf
00106  * @param[in] ... variable number of arguments according to fmt
00107  *
00108  * @return EXIT_FAILURE
00109  *
00110  * @see printf
00111  */
00112 int log_alert(const char *fmt, ...);
00113 
00114 /*!
00115  * @brief send CRIT level message to the multiplexer
00116  *
00117  * @param[in] fmt format string passed to printf
00118  * @param[in] ... variable number of arguments according to fmt
00119  *
00120  * @return EXIT_FAILURE
00121  *
00122  * @see printf
00123  */
00124 int log_crit(const char *fmt, ...);
00125 
00126 /*!
00127  * @brief send ERR level message to the multiplexer
00128  *
00129  * @param[in] fmt format string passed to printf
00130  * @param[in] ... variable number of arguments according to fmt
00131  *
00132  * @return EXIT_FAILURE
00133  *
00134  * @see printf
00135  */
00136 int log_error(const char *fmt, ...);
00137 
00138 /*!
00139  * @brief send WARNING level message to the multiplexer
00140  *
00141  * @param[in] fmt format string passed to printf
00142  * @param[in] ... variable number of arguments according to fmt
00143  *
00144  * @return EXIT_SUCCESS
00145  *
00146  * @see printf
00147  */
00148 int log_warn(const char *fmt, ...);
00149 
00150 /*!
00151  * @brief send NOTICE level message to the multiplexer
00152  *
00153  * @param[in] fmt format string passed to printf
00154  * @param[in] ... variable number of arguments according to fmt
00155  *
00156  * @return EXIT_SUCCESS
00157  *
00158  * @see printf
00159  */
00160 int log_notice(const char *fmt, ...);
00161 
00162 /*!
00163  * @brief send INFO level message to the multiplexer
00164  *
00165  * @param[in] fmt format string passed to printf
00166  * @param[in] ... variable number of arguments according to fmt
00167  *
00168  * @return EXIT_SUCCESS
00169  *
00170  * @see printf
00171  */
00172 int log_info(const char *fmt, ...);
00173 
00174 /*!
00175  * @brief send DEBUG level message to the multiplexer
00176  *
00177  * @param[in] fmt format string passed to printf
00178  * @param[in] ... variable number of arguments according to fmt
00179  *
00180  * @return EXIT_SUCCESS
00181  *
00182  * @see printf
00183  */
00184 int log_debug(const char *fmt, ...);
00185 
00186 
00187 /*!
00188  * @brief send EMERG level message to the multiplexer and exit(2)
00189  *
00190  * @param[in] fmt format string passed to printf
00191  * @param[in] ... variable number of arguments according to fmt
00192  *
00193  * @see printf
00194  * @see exit(2)
00195  */
00196 void log_emerg_and_die(const char *fmt, ...);
00197 
00198 /*!
00199  * @brief send ALERT level message to the multiplexer and exit(2)
00200  *
00201  * @param[in] fmt format string passed to printf
00202  * @param[in] ... variable number of arguments according to fmt
00203  *
00204  * @see printf
00205  * @see exit(2)
00206  */
00207 void log_alert_and_die(const char *fmt, ...);
00208 
00209 /*!
00210  * @brief send CRIT level message to the multiplexer and exit(2)
00211  *
00212  * @param[in] fmt format string passed to printf
00213  * @param[in] ... variable number of arguments according to fmt
00214  *
00215  * @see printf
00216  * @see exit(2)
00217  */
00218 void log_crit_and_die(const char *fmt, ...);
00219 
00220 /*!
00221  * @brief send ERR level message to the multiplexer and exit(2)
00222  *
00223  * @param[in] fmt format string passed to printf
00224  * @param[in] ... variable number of arguments according to fmt
00225  *
00226  * @see printf
00227  * @see exit(2)
00228  */
00229 void log_error_and_die(const char *fmt, ...);
00230 
00231 
00232 /*!
00233  * @brief send EMERG level message to the multiplexer and append strerror(errno)
00234  *
00235  * @param[in] fmt format string passed to printf
00236  * @param[in] ... variable number of arguments according to fmt
00237  *
00238  * @return EXIT_FAILURE
00239  *
00240  * @see printf
00241  */
00242 int log_pemerg(const char *fmt, ...);
00243 
00244 /*!
00245  * @brief send ALERT level message to the multiplexer and append strerror(errno)
00246  *
00247  * @param[in] fmt format string passed to printf
00248  * @param[in] ... variable number of arguments according to fmt
00249  *
00250  * @return EXIT_FAILURE
00251  *
00252  * @see printf
00253  */
00254 int log_palert(const char *fmt, ...);
00255 
00256 /*!
00257  * @brief send CRIT level message to the multiplexer and append strerror(errno)
00258  *
00259  * @param[in] fmt format string passed to printf
00260  * @param[in] ... variable number of arguments according to fmt
00261  *
00262  * @return EXIT_FAILURE
00263  *
00264  * @see printf
00265  */
00266 int log_pcrit(const char *fmt, ...);
00267 
00268 /*!
00269  * @brief send ERR level message to the multiplexer and append strerror(errno)
00270  *
00271  * @param[in] fmt format string passed to printf
00272  * @param[in] ... variable number of arguments according to fmt
00273  *
00274  * @return EXIT_FAILURE
00275  *
00276  * @see printf
00277  */
00278 int log_perror(const char *fmt, ...);
00279 
00280 /*!
00281  * @brief send WARNING level message to the multiplexer and append strerror(errno)
00282  *
00283  * @param[in] fmt format string passed to printf
00284  * @param[in] ... variable number of arguments according to fmt
00285  *
00286  * @return EXIT_SUCCESS
00287  *
00288  * @see printf
00289  */
00290 int log_pwarn(const char *fmt, ...);
00291 
00292 /*!
00293  * @brief send NOTICE level message to the multiplexer and append strerror(errno)
00294  *
00295  * @param[in] fmt format string passed to printf
00296  * @param[in] ... variable number of arguments according to fmt
00297  *
00298  * @return EXIT_SUCCESS
00299  *
00300  * @see printf
00301  */
00302 int log_pnotice(const char *fmt, ...);
00303 
00304 /*!
00305  * @brief send INFO level message to the multiplexer and append strerror(errno)
00306  *
00307  * @param[in] fmt format string passed to printf
00308  * @param[in] ... variable number of arguments according to fmt
00309  *
00310  * @return EXIT_SUCCESS
00311  *
00312  * @see printf
00313  */
00314 int log_pinfo(const char *fmt, ...);
00315 
00316 /*!
00317  * @brief send DEBUG level message to the multiplexer and append strerror(errno)
00318  *
00319  * @param[in] fmt format string passed to printf
00320  * @param[in] ... variable number of arguments according to fmt
00321  *
00322  * @return EXIT_SUCCESS
00323  *
00324  * @see printf
00325  */
00326 int log_pdebug(const char *fmt, ...);
00327 
00328 
00329 /*!
00330  * @brief send EMERG level message to the multiplexer, append strerror(errno) and exit(2)
00331  *
00332  * @param[in] fmt format string passed to printf
00333  * @param[in] ... variable number of arguments according to fmt
00334  *
00335  * @see printf
00336  * @see exit(2)
00337  */
00338 void log_pemerg_and_die(const char *fmt, ...);
00339 
00340 /*!
00341  * @brief send ALERT level message to the multiplexer, append strerror(errno) and exit(2)
00342  *
00343  * @param[in] fmt format string passed to printf
00344  * @param[in] ... variable number of arguments according to fmt
00345  *
00346  * @see printf
00347  * @see exit(2)
00348  */
00349 void log_palert_and_die(const char *fmt, ...);
00350 
00351 /*!
00352  * @brief send CRIT level message to the multiplexer, append strerror(errno) and exit(2)
00353  *
00354  * @param[in] fmt format string passed to printf
00355  * @param[in] ... variable number of arguments according to fmt
00356  *
00357  * @see printf
00358  * @see exit(2)
00359  */
00360 void log_pcrit_and_die(const char *fmt, ...);
00361 
00362 /*!
00363  * @brief send ERR level message to the multiplexer, append strerror(errno) and exit(2)
00364  *
00365  * @param[in] fmt format string passed to printf
00366  * @param[in] ... variable number of arguments according to fmt
00367  *
00368  * @see printf
00369  * @see exit(2)
00370  */
00371 void log_perror_and_die(const char *fmt, ...);
00372 
00373 /*!
00374  * @brief close connection to logging system
00375  */
00376 void log_close(void);
00377 
00378 #endif
00379 
00380 /*! @} log */

Generated on Sun Dec 3 17:45:53 2006 for lucid by  doxygen 1.5.1