GnuCash c935c2f+
Loading...
Searching...
No Matches
qoflog.h
1/* qof-log.h
2 * Author: Rob Clark <rclark@cs.hmc.edu>
3 * Copyright (C) 1998-2003 Linas Vepstas <linas@linas.org>
4 * Copyright 2005 Neil Williams <linux@codehelp.co.uk>
5 * Copyright 2007 Joshua Sled <jsled@asynchronous.org>
6 */
7
8/*
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA
23 */
24
85#ifndef _QOF_LOG_H
86#define _QOF_LOG_H
87
88#include <stdarg.h>
89#include <stdio.h>
90#include <glib.h>
91#include "qofutil.h"
92
93#ifdef __cplusplus
94extern "C"
95{
96#endif
97
98typedef const gchar* QofLogModule;
99
100#define QOF_MOD_ENGINE "qof.engine"
101
102typedef enum
103{
104 QOF_LOG_FATAL = G_LOG_LEVEL_ERROR,
105 QOF_LOG_ERROR = G_LOG_LEVEL_CRITICAL,
106 QOF_LOG_WARNING = G_LOG_LEVEL_WARNING,
107 QOF_LOG_MESSAGE = G_LOG_LEVEL_MESSAGE,
108 QOF_LOG_INFO = G_LOG_LEVEL_INFO,
109 QOF_LOG_DEBUG = G_LOG_LEVEL_DEBUG
110} QofLogLevel;
111
112const char* qof_log_level_to_string(QofLogLevel lvl);
113QofLogLevel qof_log_level_from_string(const char *str);
114
116void qof_log_indent(void);
117
121void qof_log_dedent(void);
122
127void qof_log_init (void);
128
130void qof_log_set_level(QofLogModule module, QofLogLevel level);
131
133void qof_log_set_file (FILE *outfile);
134
136void qof_log_init_filename (const gchar* logfilename);
137
143void qof_log_init_filename_special(const char *log_to_filename);
144
158void qof_log_parse_log_config(const char *filename);
159
161void qof_log_shutdown (void);
162
168const gchar * qof_log_prettify (const gchar *name);
169
172gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level);
173
174#define PRETTY_FUNC_NAME qof_log_prettify(G_STRFUNC)
175
176#ifdef _MSC_VER
177/* Microsoft Visual Studio: MSVC compiler has a different syntax for
178 * macros with variadic argument list. */
179
180/* TODO: After the C++2a feature __VA_OPT__ gets implemented in both
181 * flavors, it should be inserted before __VA_ARGS__ and the else branch
182 * gets obsolete and should be removed.
183 */
184
186#define FATAL(format, ...) do { \
187 g_log (log_module, G_LOG_LEVEL_ERROR, \
188 "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
189} while (0)
190
192#define PERR(format, ...) do { \
193 g_log (log_module, G_LOG_LEVEL_CRITICAL, \
194 "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
195} while (0)
196
198#define PWARN(format, ...) do { \
199 g_log (log_module, G_LOG_LEVEL_WARNING, \
200 "[%s()] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
201} while (0)
202
204#define PINFO(format, ...) \
205 if (qof_log_check(log_module, QOF_LOG_INFO) { \
206 g_log (log_module, G_LOG_LEVEL_INFO, \
207 "[%s] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
208}
209
211#define DEBUG(format, ...) \
212 if (qof_log_check(log_module, QOF_LOG_DEBUG) { \
213 g_log (log_module, G_LOG_LEVEL_DEBUG, \
214 "[%s] " format, PRETTY_FUNC_NAME , __VA_ARGS__); \
215}
216
218#define ENTER(format, ...) \
219 if (qof_log_check(log_module, QOFLOG_DEBUG)) { \
220 g_log (log_module, G_LOG_LEVEL_DEBUG, \
221 "[enter %s:%s()] " format, __FILE__, \
222 PRETTY_FUNC_NAME , __VA_ARGS__); \
223 qof_log_indent(); \
224}
225
227#define LEAVE(format, ...) \
228 if (qof_log_check(log_module, QOF_LOG_DEBUG)) { \
229 qof_log_dedent(); \
230 g_log (log_module, G_LOG_LEVEL_DEBUG, \
231 "[leave %s()] " format, \
232 PRETTY_FUNC_NAME , __VA_ARGS__); \
233}
234
235#else /* _MSC_VER */
236
238#define FATAL(format, args...) do { \
239 g_log (log_module, G_LOG_LEVEL_ERROR, \
240 "[%s()] " format, PRETTY_FUNC_NAME , ## args); \
241} while (0)
242
244#define PERR(format, args...) do { \
245 g_log (log_module, G_LOG_LEVEL_CRITICAL, \
246 "[%s()] " format, PRETTY_FUNC_NAME , ## args); \
247} while (0)
248
250#define PWARN(format, args...) do { \
251 g_log (log_module, G_LOG_LEVEL_WARNING, \
252 "[%s()] " format, PRETTY_FUNC_NAME , ## args); \
253} while (0)
254
256#define PINFO(format, args...) do { \
257 if (qof_log_check(log_module, QOF_LOG_INFO)) { \
258 g_log (log_module, G_LOG_LEVEL_INFO, \
259 "[%s] " format, PRETTY_FUNC_NAME , ## args); \
260 } \
261} while (0)
262
264#define DEBUG(format, args...) do { \
265 if (qof_log_check(log_module, QOF_LOG_DEBUG)) { \
266 g_log (log_module, G_LOG_LEVEL_DEBUG, \
267 "[%s] " format, PRETTY_FUNC_NAME , ## args); \
268 } \
269} while(0)
270
272#define ENTER(format, args...) do { \
273 if (qof_log_check(log_module, QOF_LOG_DEBUG)) { \
274 g_log (log_module, G_LOG_LEVEL_DEBUG, \
275 "[enter %s:%s()] " format, __FILE__, \
276 PRETTY_FUNC_NAME , ## args); \
277 qof_log_indent(); \
278 } \
279} while (0)
280
282#define LEAVE(format, args...) do { \
283 if (qof_log_check(log_module, QOF_LOG_DEBUG)) { \
284 qof_log_dedent(); \
285 g_log (log_module, G_LOG_LEVEL_DEBUG, \
286 "[leave %s()] " format, \
287 PRETTY_FUNC_NAME , ## args); \
288 } \
289} while (0)
290
291#endif /* _MSC_VER */
292
294#define gnc_leave_return_val_if_fail(test, val) do { \
295 if (! (test)) { LEAVE(""); } \
296 g_return_val_if_fail(test, val); \
297} while (0);
298
300#define gnc_leave_return_if_fail(test) do { \
301 if (! (test)) { LEAVE(""); } \
302 g_return_if_fail(test); \
303} while (0);
304
305
306#ifdef __cplusplus
307}
308#endif
309
310#endif /* _QOF_LOG_H */
311
void qof_log_set_level(QofLogModule module, QofLogLevel level)
Set the logging level of the given log_module.
Definition qoflog.cpp:297
void qof_log_init(void)
Initialize the error logging subsystem.
Definition qoflog.cpp:156
void qof_log_dedent(void)
De-dent one level, capped at 0; see LEAVE macro.
Definition qoflog.cpp:136
void qof_log_shutdown(void)
Be nice, close the logfile if possible.
Definition qoflog.cpp:264
void qof_log_init_filename(const gchar *logfilename)
Specify a filename for log output.
Definition qoflog.cpp:207
void qof_log_indent(void)
Indents one level; see ENTER macro.
Definition qoflog.cpp:130
void qof_log_parse_log_config(const char *filename)
Parse a log-configuration file.
Definition qoflog.cpp:421
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level)
Check to see if the given log_module is configured to log at the given log_level.
Definition qoflog.cpp:330
void qof_log_set_file(FILE *outfile)
Specify an alternate log output, to pipe or file.
Definition qoflog.cpp:145
void qof_log_init_filename_special(const char *log_to_filename)
If log_to_filename is "stderr" or "stdout" (exactly, case-insensitive), then those special files are ...
Definition qoflog.cpp:402
const gchar * qof_log_prettify(const gchar *name)
Cleans up subroutine names.
QOF utility functions.