|
GnuCash 2.4.99
|
00001 /* qof-log.h 00002 * Author: Rob Clark <rclark@cs.hmc.edu> 00003 * Copyright (C) 1998-2003 Linas Vepstas <linas@linas.org> 00004 * Copyright 2005 Neil Williams <linux@codehelp.co.uk> 00005 * Copyright 2007 Joshua Sled <jsled@asynchronous.org> 00006 */ 00007 00008 /* 00009 * This program is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00022 * 02110-1301, USA 00023 */ 00024 00084 #ifndef _QOF_LOG_H 00085 #define _QOF_LOG_H 00086 00087 #include <stdarg.h> 00088 #include <stdio.h> 00089 #include <glib.h> 00090 #include "qofutil.h" 00091 00092 #define QOF_MOD_ENGINE "qof.engine" 00093 00094 #define LOG_LEVEL_LIST(_) \ 00095 _(QOF_LOG_FATAL, = G_LOG_LEVEL_ERROR) \ 00096 _(QOF_LOG_ERROR, = G_LOG_LEVEL_CRITICAL) \ 00097 _(QOF_LOG_WARNING, = G_LOG_LEVEL_WARNING) \ 00098 _(QOF_LOG_MESSAGE, = G_LOG_LEVEL_MESSAGE) \ 00099 _(QOF_LOG_INFO, = G_LOG_LEVEL_INFO) \ 00100 _(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG) 00101 00102 DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST) 00103 00104 gchar* qof_log_level_to_string(QofLogLevel lvl); 00105 QofLogLevel qof_log_level_from_string(const gchar *str); 00106 00108 void qof_log_indent(void); 00109 00113 void qof_log_dedent(void); 00114 00119 void qof_log_init (void); 00120 00122 void qof_log_set_level(QofLogModule module, QofLogLevel level); 00123 00125 void qof_log_set_file (FILE *outfile); 00126 00128 void qof_log_init_filename (const gchar* logfilename); 00129 00135 void qof_log_init_filename_special(const char *log_to_filename); 00136 00150 void qof_log_parse_log_config(const char *filename); 00151 00153 void qof_log_shutdown (void); 00154 00160 const gchar * qof_log_prettify (const gchar *name); 00161 00164 gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level); 00165 00167 void qof_log_set_default(QofLogLevel log_level); 00168 00169 #define PRETTY_FUNC_NAME qof_log_prettify(G_STRFUNC) 00170 00171 #ifdef _MSC_VER 00172 /* Microsoft Visual Studio: MSVC compiler has a different syntax for 00173 * macros with variadic argument list. */ 00174 00176 #define FATAL(format, ...) do { \ 00177 g_log (log_module, G_LOG_LEVEL_ERROR, \ 00178 "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \ 00179 } while (0) 00180 00182 #define PERR(format, ...) do { \ 00183 g_log (log_module, G_LOG_LEVEL_CRITICAL, \ 00184 "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \ 00185 } while (0) 00186 00188 #define PWARN(format, ...) do { \ 00189 g_log (log_module, G_LOG_LEVEL_WARNING, \ 00190 "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \ 00191 } while (0) 00192 00194 #define PINFO(format, ...) do { \ 00195 g_log (log_module, G_LOG_LEVEL_INFO, \ 00196 "[%s] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \ 00197 } while (0) 00198 00200 #define DEBUG(format, ...) do { \ 00201 g_log (log_module, G_LOG_LEVEL_DEBUG, \ 00202 "[%s] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \ 00203 } while (0) 00204 00206 #define ENTER(format, ...) do { \ 00207 if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \ 00208 g_log (log_module, G_LOG_LEVEL_DEBUG, \ 00209 "[enter %s:%s()] " format, __FILE__, \ 00210 PRETTY_FUNC_NAME , __VA_ARGS__); \ 00211 qof_log_indent(); \ 00212 } \ 00213 } while (0) 00214 00216 #define LEAVE(format, ...) do { \ 00217 if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \ 00218 qof_log_dedent(); \ 00219 g_log (log_module, G_LOG_LEVEL_DEBUG, \ 00220 "[leave %s()] " format, \ 00221 PRETTY_FUNC_NAME , __VA_ARGS__); \ 00222 } \ 00223 } while (0) 00224 00225 #else /* _MSC_VER */ 00226 00228 #define FATAL(format, args...) do { \ 00229 g_log (log_module, G_LOG_LEVEL_ERROR, \ 00230 "[%s()] " format, PRETTY_FUNC_NAME , ## args); \ 00231 } while (0) 00232 00234 #define PERR(format, args...) do { \ 00235 g_log (log_module, G_LOG_LEVEL_CRITICAL, \ 00236 "[%s()] " format, PRETTY_FUNC_NAME , ## args); \ 00237 } while (0) 00238 00240 #define PWARN(format, args...) do { \ 00241 g_log (log_module, G_LOG_LEVEL_WARNING, \ 00242 "[%s()] " format, PRETTY_FUNC_NAME , ## args); \ 00243 } while (0) 00244 00246 #define PINFO(format, args...) do { \ 00247 g_log (log_module, G_LOG_LEVEL_INFO, \ 00248 "[%s] " format, PRETTY_FUNC_NAME , ## args); \ 00249 } while (0) 00250 00252 #define DEBUG(format, args...) do { \ 00253 g_log (log_module, G_LOG_LEVEL_DEBUG, \ 00254 "[%s] " format, PRETTY_FUNC_NAME , ## args); \ 00255 } while (0) 00256 00258 #define ENTER(format, args...) do { \ 00259 if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \ 00260 g_log (log_module, G_LOG_LEVEL_DEBUG, \ 00261 "[enter %s:%s()] " format, __FILE__, \ 00262 PRETTY_FUNC_NAME , ## args); \ 00263 qof_log_indent(); \ 00264 } \ 00265 } while (0) 00266 00268 #define LEAVE(format, args...) do { \ 00269 if (qof_log_check(log_module, (QofLogLevel)G_LOG_LEVEL_DEBUG)) { \ 00270 qof_log_dedent(); \ 00271 g_log (log_module, G_LOG_LEVEL_DEBUG, \ 00272 "[leave %s()] " format, \ 00273 PRETTY_FUNC_NAME , ## args); \ 00274 } \ 00275 } while (0) 00276 00277 #endif /* _MSC_VER */ 00278 00280 #define gnc_leave_return_val_if_fail(test, val) do { \ 00281 if (! (test)) { LEAVE(""); } \ 00282 g_return_val_if_fail(test, val); \ 00283 } while (0); 00284 00286 #define gnc_leave_return_if_fail(test) do { \ 00287 if (! (test)) { LEAVE(""); } \ 00288 g_return_if_fail(test); \ 00289 } while (0); 00290 00291 00292 #endif /* _QOF_LOG_H */ 00293
1.7.4