gnc-trace.h

Go to the documentation of this file.
00001 /********************************************************************\
00002  * gnc-trace.h -- QOF logging and tracing facility                  *
00003  * Copyright (C) 1998-2003 Linas Vepstas <linas@linas.org>          *
00004  *                                                                  *
00005  * This program is free software; you can redistribute it and/or    *
00006  * modify it under the terms of the GNU General Public License as   *
00007  * published by the Free Software Foundation; either version 2 of   *
00008  * the License, or (at your option) any later version.              *
00009  *                                                                  *
00010  * This program is distributed in the hope that it will be useful,  *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00013  * GNU General Public License for more details.                     *
00014  *                                                                  *
00015  * You should have received a copy of the GNU General Public License*
00016  * along with this program; if not, contact:                        *
00017  *                                                                  *
00018  * Free Software Foundation           Voice:  +1-617-542-5942       *
00019  * 59 Temple Place - Suite 330        Fax:    +1-617-542-2652       *
00020  * Boston, MA  02111-1307,  USA       gnu@gnu.org                   *
00021  *                                                                  *
00022  *   Author: Linas Vepstas (linas@linas.org)                        *
00023 \********************************************************************/
00024 
00033 #ifndef GNC_TRACE_H
00034 #define GNC_TRACE_H
00035 
00036 #include <glib.h>
00037 #include <stdarg.h>
00038 #include <stdio.h>
00039 #include "gnc-engine-util.h"
00040 
00041 #define QOF_MOD_ENGINE "qof-engine"
00042 
00043 #define LOG_LEVEL_LIST(_) \
00044   _(GNC_LOG_FATAL, = 0)   \
00045   _(GNC_LOG_ERROR, = 1)   \
00046   _(GNC_LOG_WARNING, = 2) \
00047   _(GNC_LOG_INFO, = 3)    \
00048   _(GNC_LOG_DEBUG, = 4)   \
00049   _(GNC_LOG_DETAIL, = 5)  \
00050   _(GNC_LOG_TRACE, = 6)
00051 
00052 DEFINE_ENUM (gncLogLevel, LOG_LEVEL_LIST)
00053 
00054 
00060 AS_STRING_DEC(gncLogLevel, LOG_LEVEL_LIST)
00061 
00066 FROM_STRING_DEC(gncLogLevel, LOG_LEVEL_LIST)
00067 
00068 #define GNC_TRACE_INDENT_WIDTH 4
00069 
00080 void gnc_log_init (void);
00081 
00083 void gnc_set_log_level(QofLogModule module, gncLogLevel level);
00084 
00091 void gnc_set_log_level_global(gncLogLevel level);
00092 
00098 void gnc_set_logfile (FILE *outfile);
00099 
00104 void qof_log_init_filename (const gchar* logfilename);
00105 
00107 void qof_log_shutdown (void);
00108 
00114 const char * gnc_log_prettify (const char *name);
00115 
00123 gboolean gnc_should_log(QofLogModule log_module, gncLogLevel log_level);
00124 
00126 void qof_log_set_default(gncLogLevel log_level);
00127 
00128 typedef void (*QofLogCB) (QofLogModule log_module, gncLogLevel* log_level, gpointer user_data);
00129 
00135 void qof_log_module_foreach(QofLogCB cb, gpointer data);
00136 
00138 gint qof_log_module_count(void);
00139 
00140 #define FUNK gnc_log_prettify(__FUNCTION__)
00141 
00155 #define FATAL(format, args...) do {                  \
00156     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR,          \
00157       "Fatal Error: %s(): " format, FUNK , ## args); \
00158 } while (0)
00159 
00161 #define PERR(format, args...) do {                   \
00162   if (gnc_should_log (log_module, GNC_LOG_ERROR)) {    \
00163     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,     \
00164       "Error: %s(): " format, FUNK , ## args);     \
00165   }                                                \
00166 } while (0)
00167 
00169 #define PWARN(format, args...) do {                    \
00170   if (gnc_should_log (log_module, GNC_LOG_WARNING)) {  \
00171     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,      \
00172       "Warning: %s(): " format, FUNK , ## args);   \
00173   }                                                \
00174 } while (0)
00175 
00177 #define PINFO(format, args...) do {                 \
00178   if (gnc_should_log (log_module, GNC_LOG_INFO)) {     \
00179     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO,         \
00180       "Info: %s(): " format,                       \
00181       FUNK , ## args);                             \
00182   }                                                \
00183 } while (0)
00184 
00186 #define DEBUG(format, args...) do {                 \
00187   if (gnc_should_log (log_module, GNC_LOG_DEBUG)) {    \
00188     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,        \
00189       "Debug: %s(): " format,                      \
00190       FUNK , ## args);                             \
00191   }                                                \
00192 } while (0)
00193 
00195 #define ENTER(format, args...) do {                 \
00196   extern gint gnc_trace_num_spaces;                \
00197   if (gnc_should_log (log_module, GNC_LOG_DEBUG)) {    \
00198     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,        \
00199       "Enter in %s: %s()" format, __FILE__,        \
00200       FUNK , ## args);                             \
00201     gnc_trace_num_spaces += GNC_TRACE_INDENT_WIDTH; \
00202   }                                                \
00203 } while (0)
00204 
00206 #define LEAVE(format, args...) do {                 \
00207   extern gint gnc_trace_num_spaces;                \
00208   if (gnc_should_log (log_module, GNC_LOG_DEBUG)) {    \
00209     gnc_trace_num_spaces -= GNC_TRACE_INDENT_WIDTH; \
00210     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,        \
00211       "Leave: %s()" format,                        \
00212       FUNK , ## args);                             \
00213   }                                                \
00214 } while (0)
00215 
00217 #define TRACE(format, args...) do {                 \
00218   if (gnc_should_log (log_module, GNC_LOG_TRACE)) {    \
00219     g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,        \
00220       "Trace: %s(): " format, FUNK , ## args);     \
00221   }                                                \
00222 } while (0)
00223 
00224 #define DEBUGCMD(x) do {                            \
00225   if (gnc_should_log (log_module, GNC_LOG_DEBUG)) { \
00226                 (x);                                        \
00227         }                                               \
00228 } while (0)
00229 
00230 /* -------------------------------------------------------- */
00235 void gnc_start_clock (int clockno, QofLogModule log_module, gncLogLevel log_level,
00236                       const char *function_name, const char *format, ...);
00237 
00238 void gnc_report_clock (int clockno,
00239                        QofLogModule log_module,
00240                        gncLogLevel log_level,
00241                        const char *function_name,
00242                        const char *format, ...);
00243 
00244 void gnc_report_clock_total (int clockno,
00245                              QofLogModule log_module,
00246                              gncLogLevel log_level,
00247                              const char *function_name,
00248                              const char *format, ...);
00249 
00251 #define START_CLOCK(clockno,format, args...) do {        \
00252   if (gnc_should_log (log_module, GNC_LOG_INFO))                \
00253     gnc_start_clock (clockno, log_module, GNC_LOG_INFO,  \
00254              __FUNCTION__, format , ## args);               \
00255 } while (0)
00256 
00258 #define REPORT_CLOCK(clockno,format, args...) do {       \
00259   if (gnc_should_log (log_module, GNC_LOG_INFO))                \
00260     gnc_report_clock (clockno, log_module, GNC_LOG_INFO, \
00261              __FUNCTION__, format , ## args);               \
00262 } while (0)
00263 
00265 #define REPORT_CLOCK_TOTAL(clockno,format, args...) do {       \
00266   if (gnc_should_log (log_module, GNC_LOG_INFO))                \
00267     gnc_report_clock_total (clockno, log_module, GNC_LOG_INFO, \
00268              __FUNCTION__, format , ## args);               \
00269 } while (0)
00270 
00271 #endif /* GNC_TRACE_H */
00272 /* @} */

Generated on Fri Oct 21 15:49:54 2005 for QOF by  doxygen 1.4.5