2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 \brief Support for logging to various files, console and syslog
22 Configuration in file logger.conf
25 #ifndef _ASTERISK_LOGGER_H
26 #define _ASTERISK_LOGGER_H
28 #include "asterisk/compat.h"
32 #if defined(__cplusplus) || defined(c_plusplus)
36 #define EVENTLOG "event_log"
37 #define QUEUELOG "queue_log"
39 #define DEBUG_M(a) { \
43 #define VERBOSE_PREFIX_1 " "
44 #define VERBOSE_PREFIX_2 " == "
45 #define VERBOSE_PREFIX_3 " -- "
46 #define VERBOSE_PREFIX_4 " > "
48 /*! Used for sending a log message */
50 \brief This is the standard logger function. Probably the only way you will invoke it would be something like this:
51 ast_log(LOG_WHATEVER, "Problem with the %s Captain. We should get some more. Will %d be enough?\n", "flux capacitor", 10);
52 where WHATEVER is one of ERROR, DEBUG, EVENT, NOTICE, or WARNING depending
53 on which log you wish to output to. These are implemented as macros, that
54 will provide the function with the needed arguments.
56 \param level Type of log event
57 \param file Will be provided by the LOG_* macro
58 \param line Will be provided by the LOG_* macro
59 \param function Will be provided by the LOG_* macro
60 \param fmt This is what is important. The format is the same as your favorite breed of printf. You know how that works, right? :-)
63 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
64 __attribute__ ((format (printf, 5, 6)));
66 void ast_backtrace(void);
68 void ast_queue_log(const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt, ...)
69 __attribute__ ((format (printf, 5, 6)));
71 /*! Send a verbose message (based on verbose level)
72 \brief This works like ast_log, but prints verbose messages to the console depending on verbosity level set.
73 ast_verbose(VERBOSE_PREFIX_3 "Whatever %s is happening\n", "nothing");
74 This will print the message to the console if the verbose level is set to a level >= 3
75 Note the abscence of a comma after the VERBOSE_PREFIX_3. This is important.
76 VERBOSE_PREFIX_1 through VERBOSE_PREFIX_3 are defined.
78 void ast_verbose(const char *fmt, ...)
79 __attribute__ ((format (printf, 1, 2)));
81 int ast_register_verbose(void (*verboser)(const char *string));
82 int ast_unregister_verbose(void (*verboser)(const char *string));
84 void ast_console_puts(const char *string);
86 void ast_console_puts_mutable(const char *string);
87 void ast_console_toggle_mute(int fd);
89 #define _A_ __FILE__, __LINE__, __PRETTY_FUNCTION__
95 #define LOG_DEBUG __LOG_DEBUG, _A_
100 #define __LOG_EVENT 1
101 #define LOG_EVENT __LOG_EVENT, _A_
106 #define __LOG_NOTICE 2
107 #define LOG_NOTICE __LOG_NOTICE, _A_
112 #define __LOG_WARNING 3
113 #define LOG_WARNING __LOG_WARNING, _A_
118 #define __LOG_ERROR 4
119 #define LOG_ERROR __LOG_ERROR, _A_
124 #define __LOG_VERBOSE 5
125 #define LOG_VERBOSE __LOG_VERBOSE, _A_
131 #define LOG_DTMF __LOG_DTMF, _A_
134 * \brief Get the debug level for a file
135 * \arg file the filename
136 * \return the debug level
138 unsigned int ast_debug_get_by_file(const char *file);
141 * \brief Get the debug level for a file
142 * \arg file the filename
143 * \return the debug level
145 unsigned int ast_verbose_get_by_file(const char *file);
148 * \brief Log a DEBUG message
149 * \param level The minimum value of option_debug for this message
152 #define ast_debug(level, ...) do { \
153 if (option_debug >= (level) || (ast_opt_dbg_file && ast_debug_get_by_file(__FILE__) >= (level)) ) \
154 ast_log(LOG_DEBUG, __VA_ARGS__); \
157 #define ast_verb(level, ...) do { \
158 if (option_verbose >= (level) || (ast_opt_verb_file && ast_verbose_get_by_file(__FILE__) >= (level)) ) { \
160 ast_verbose(VERBOSE_PREFIX_4 __VA_ARGS__); \
161 else if (level == 3) \
162 ast_verbose(VERBOSE_PREFIX_3 __VA_ARGS__); \
163 else if (level == 2) \
164 ast_verbose(VERBOSE_PREFIX_2 __VA_ARGS__); \
165 else if (level == 1) \
166 ast_verbose(VERBOSE_PREFIX_1 __VA_ARGS__); \
168 ast_verbose(__VA_ARGS__); \
172 #if defined(__cplusplus) || defined(c_plusplus)
176 #endif /* _ASTERISK_LOGGER_H */