Thu Jul 9 13:40:36 2009

Asterisk developer's documentation


logger.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*!
00020   \file logger.h
00021   \brief Support for logging to various files, console and syslog
00022    Configuration in file logger.conf
00023 */
00024 
00025 #ifndef _ASTERISK_LOGGER_H
00026 #define _ASTERISK_LOGGER_H
00027 
00028 #include "asterisk/options.h" /* need option_debug */
00029 
00030 #if defined(__cplusplus) || defined(c_plusplus)
00031 extern "C" {
00032 #endif
00033 
00034 #define EVENTLOG "event_log"
00035 #define  QUEUELOG "queue_log"
00036 
00037 #define DEBUG_M(a) { \
00038    a; \
00039 }
00040 
00041 #define VERBOSE_PREFIX_1 " "
00042 #define VERBOSE_PREFIX_2 "  == "
00043 #define VERBOSE_PREFIX_3 "    -- "
00044 #define VERBOSE_PREFIX_4 "       > "
00045 
00046 /*! \brief Used for sending a log message 
00047    This is the standard logger function.  Probably the only way you will invoke it would be something like this:
00048    ast_log(LOG_WHATEVER, "Problem with the %s Captain.  We should get some more.  Will %d be enough?\n", "flux capacitor", 10);
00049    where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending
00050    on which log you wish to output to. These are implemented as macros, that
00051    will provide the function with the needed arguments.
00052 
00053    \param level   Type of log event
00054    \param file Will be provided by the LOG_* macro
00055    \param line Will be provided by the LOG_* macro
00056    \param function   Will be provided by the LOG_* macro
00057    \param fmt  This is what is important.  The format is the same as your favorite breed of printf.  You know how that works, right? :-)
00058  */
00059 
00060 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
00061    __attribute__((format(printf, 5, 6)));
00062 
00063 void ast_backtrace(void);
00064 
00065 /*! \brief Reload logger without rotating log files */
00066 int logger_reload(void);
00067 
00068 void __attribute__((format(printf, 5, 6))) ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...);
00069 
00070 /*! Send a verbose message (based on verbose level)
00071    \brief This works like ast_log, but prints verbose messages to the console depending on verbosity level set.
00072    ast_verbose(VERBOSE_PREFIX_3 "Whatever %s is happening\n", "nothing");
00073    This will print the message to the console if the verbose level is set to a level >= 3
00074    Note the abscence of a comma after the VERBOSE_PREFIX_3.  This is important.
00075    VERBOSE_PREFIX_1 through VERBOSE_PREFIX_3 are defined.
00076  */
00077 void ast_verbose(const char *fmt, ...)
00078    __attribute__ ((format (printf, 1, 2)));
00079 
00080 int ast_register_verbose(void (*verboser)(const char *string));
00081 int ast_unregister_verbose(void (*verboser)(const char *string));
00082 
00083 void ast_console_puts(const char *string);
00084 
00085 void ast_console_puts_mutable(const char *string);
00086 void ast_console_toggle_mute(int fd, int silent);
00087 
00088 #define _A_ __FILE__, __LINE__, __PRETTY_FUNCTION__
00089 
00090 #ifdef LOG_DEBUG
00091 #undef LOG_DEBUG
00092 #endif
00093 #define __LOG_DEBUG    0
00094 #define LOG_DEBUG      __LOG_DEBUG, _A_
00095 
00096 #ifdef LOG_EVENT
00097 #undef LOG_EVENT
00098 #endif
00099 #define __LOG_EVENT    1
00100 #define LOG_EVENT      __LOG_EVENT, _A_
00101 
00102 #ifdef LOG_NOTICE
00103 #undef LOG_NOTICE
00104 #endif
00105 #define __LOG_NOTICE   2
00106 #define LOG_NOTICE     __LOG_NOTICE, _A_
00107 
00108 #ifdef LOG_WARNING
00109 #undef LOG_WARNING
00110 #endif
00111 #define __LOG_WARNING  3
00112 #define LOG_WARNING    __LOG_WARNING, _A_
00113 
00114 #ifdef LOG_ERROR
00115 #undef LOG_ERROR
00116 #endif
00117 #define __LOG_ERROR    4
00118 #define LOG_ERROR      __LOG_ERROR, _A_
00119 
00120 #ifdef LOG_VERBOSE
00121 #undef LOG_VERBOSE
00122 #endif
00123 #define __LOG_VERBOSE  5
00124 #define LOG_VERBOSE    __LOG_VERBOSE, _A_
00125 
00126 #ifdef LOG_DTMF
00127 #undef LOG_DTMF
00128 #endif
00129 #define __LOG_DTMF  6
00130 #define LOG_DTMF    __LOG_DTMF, _A_
00131 
00132 /*!
00133  * \brief Get the debug level for a file
00134  * \arg file the filename
00135  * \return the debug level
00136  */
00137 unsigned int ast_debug_get_by_file(const char *file);
00138 
00139 /*!
00140  * \brief Get the debug level for a file
00141  * \arg file the filename
00142  * \return the debug level
00143  */
00144 unsigned int ast_verbose_get_by_file(const char *file);
00145 
00146 /*!
00147  * \brief Log a DEBUG message
00148  * \param level The minimum value of option_debug for this message
00149  *        to get logged
00150  */
00151 #define ast_debug(level, ...) do {       \
00152    if (option_debug >= (level) || (ast_opt_dbg_file && ast_debug_get_by_file(__FILE__) >= (level)) ) \
00153       ast_log(LOG_DEBUG, __VA_ARGS__); \
00154 } while (0)
00155 
00156 #define VERBOSITY_ATLEAST(level) (option_verbose >= (level) || (ast_opt_verb_file && ast_verbose_get_by_file(__FILE__) >= (level)))
00157 
00158 #define ast_verb(level, ...) do { \
00159    if (VERBOSITY_ATLEAST((level)) ) { \
00160       if (level >= 4) \
00161          ast_verbose(VERBOSE_PREFIX_4 __VA_ARGS__); \
00162       else if (level == 3) \
00163          ast_verbose(VERBOSE_PREFIX_3 __VA_ARGS__); \
00164       else if (level == 2) \
00165          ast_verbose(VERBOSE_PREFIX_2 __VA_ARGS__); \
00166       else if (level == 1) \
00167          ast_verbose(VERBOSE_PREFIX_1 __VA_ARGS__); \
00168       else \
00169          ast_verbose(__VA_ARGS__); \
00170    } \
00171 } while (0)
00172 
00173 #if defined(__cplusplus) || defined(c_plusplus)
00174 }
00175 #endif
00176 
00177 #endif /* _ASTERISK_LOGGER_H */

Generated on Thu Jul 9 13:40:36 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7