2006-01-08 11:51:29 -06:00
|
|
|
/***************************************************************************
|
|
|
|
* qof-log.h
|
|
|
|
*
|
2006-02-05 06:25:45 -06:00
|
|
|
* Author: Rob Clark (rclark@cs.hmc.edu)
|
2006-01-08 11:51:29 -06:00
|
|
|
* Copyright (C) 1998-2003 Linas Vepstas <linas@linas.org>
|
2007-02-09 11:35:00 -06:00
|
|
|
* Copyright 2005 Neil Williams <linux@codehelp.co.uk>
|
|
|
|
* Copyright 2007 Joshua Sled <jsled@asynchronous.org>
|
2006-01-08 11:51:29 -06:00
|
|
|
****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @addtogroup Trace
|
|
|
|
@{ */
|
|
|
|
|
2006-02-19 16:54:39 -06:00
|
|
|
/** @file qoflog.h
|
2006-01-08 11:51:29 -06:00
|
|
|
* @brief QOF error logging and tracing facility
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _QOF_LOG_H
|
|
|
|
#define _QOF_LOG_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2007-02-09 11:35:00 -06:00
|
|
|
#include <glib.h>
|
2006-04-07 13:50:08 -05:00
|
|
|
#include "qofutil.h"
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
#define QOF_MOD_ENGINE "qof.engine"
|
2006-01-08 11:51:29 -06:00
|
|
|
|
|
|
|
#define LOG_LEVEL_LIST(_) \
|
2007-02-09 11:35:00 -06:00
|
|
|
_(QOF_LOG_FATAL, = G_LOG_LEVEL_ERROR) \
|
|
|
|
_(QOF_LOG_ERROR, = G_LOG_LEVEL_CRITICAL) \
|
|
|
|
_(QOF_LOG_WARNING, = G_LOG_LEVEL_WARNING) \
|
|
|
|
_(QOF_LOG_INFO, = G_LOG_LEVEL_INFO) \
|
2007-02-09 15:52:09 -06:00
|
|
|
_(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG)
|
2006-01-08 11:51:29 -06:00
|
|
|
|
|
|
|
DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST)
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
gchar* qof_log_level_to_string(QofLogLevel lvl);
|
|
|
|
QofLogLevel qof_log_level_from_string(gchar *str);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2007-02-09 15:52:09 -06:00
|
|
|
/** indents once for each ENTER macro **/
|
|
|
|
void qof_log_indent(void);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
/**
|
2007-02-09 15:52:09 -06:00
|
|
|
* drops back one indent for each LEAVE macro, capped at 0.
|
2007-02-09 11:35:00 -06:00
|
|
|
**/
|
2007-02-09 15:52:09 -06:00
|
|
|
void qof_log_dedent(void);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
/**
|
|
|
|
* Initialize the error logging subsystem. Defaults to a level-threshold of
|
|
|
|
* "warning", and logging to stderr.
|
|
|
|
**/
|
2006-01-08 11:51:29 -06:00
|
|
|
void qof_log_init (void);
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
/**
|
|
|
|
* Set the logging level of the given log_module.
|
|
|
|
**/
|
2006-01-08 11:51:29 -06:00
|
|
|
void qof_log_set_level(QofLogModule module, QofLogLevel level);
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
/**
|
|
|
|
* Specify an alternate log output, to pipe or file.
|
|
|
|
**/
|
2006-01-08 11:51:29 -06:00
|
|
|
void qof_log_set_file (FILE *outfile);
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
/**
|
|
|
|
* Specify a filename for log output.
|
|
|
|
**/
|
2006-01-08 11:51:29 -06:00
|
|
|
void qof_log_init_filename (const gchar* logfilename);
|
|
|
|
|
|
|
|
/** Be nice, close the logfile if possible. */
|
|
|
|
void qof_log_shutdown (void);
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
/**
|
|
|
|
* qof_log_prettify() cleans up subroutine names. AIX/xlC has the habit
|
2006-01-08 11:51:29 -06:00
|
|
|
* of printing signatures not names; clean this up. On other operating
|
2007-02-09 11:35:00 -06:00
|
|
|
* systems, truncate name to QOF_LOG_MAX_CHARS chars.
|
|
|
|
**/
|
2006-04-07 13:50:08 -05:00
|
|
|
const gchar * qof_log_prettify (const gchar *name);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
|
|
|
/** Do not log log_modules that have not been enabled. */
|
|
|
|
gboolean qof_log_check(QofLogModule log_module, QofLogLevel log_level);
|
|
|
|
|
|
|
|
/** Set the default QOF log_modules to the log level. */
|
|
|
|
void qof_log_set_default(QofLogLevel log_level);
|
|
|
|
|
|
|
|
typedef void (*QofLogCB) (QofLogModule log_module, QofLogLevel* log_level,
|
|
|
|
gpointer user_data);
|
|
|
|
|
2007-02-09 11:35:00 -06:00
|
|
|
#define PRETTY_FUNC_NAME qof_log_prettify(__FUNCTION__)
|
2006-01-08 11:51:29 -06:00
|
|
|
|
|
|
|
/** Log a fatal error */
|
2007-02-09 11:35:00 -06:00
|
|
|
#define FATAL(format, args...) do { \
|
|
|
|
g_log (log_module, G_LOG_LEVEL_FATAL, \
|
|
|
|
"[%s()] " format, PRETTY_FUNC_NAME , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** Log a serious error */
|
2007-02-09 11:35:00 -06:00
|
|
|
#define PERR(format, args...) do { \
|
|
|
|
g_log (log_module, G_LOG_LEVEL_CRITICAL, \
|
|
|
|
"[%s()] " format, PRETTY_FUNC_NAME , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** Log a warning */
|
2007-02-09 11:35:00 -06:00
|
|
|
#define PWARN(format, args...) do { \
|
|
|
|
g_log (log_module, G_LOG_LEVEL_WARNING, \
|
|
|
|
"[%s()] " format, PRETTY_FUNC_NAME , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** Print an informational note */
|
2007-02-09 11:35:00 -06:00
|
|
|
#define PINFO(format, args...) do { \
|
|
|
|
g_log (log_module, G_LOG_LEVEL_INFO, \
|
|
|
|
"[%s] " format, PRETTY_FUNC_NAME , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** Print a debugging message */
|
2007-02-09 11:35:00 -06:00
|
|
|
#define DEBUG(format, args...) do { \
|
|
|
|
g_log (log_module, G_LOG_LEVEL_DEBUG, \
|
|
|
|
"[%s] " format, PRETTY_FUNC_NAME , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** Print a function entry debugging message */
|
2007-02-09 11:35:00 -06:00
|
|
|
#define ENTER(format, args...) do { \
|
2007-02-09 15:52:09 -06:00
|
|
|
if (qof_log_check(log_module, G_LOG_LEVEL_DEBUG)) { \
|
|
|
|
g_log (log_module, G_LOG_LEVEL_DEBUG, \
|
|
|
|
"[enter %s:%s()] " format, __FILE__, \
|
|
|
|
PRETTY_FUNC_NAME , ## args); \
|
|
|
|
qof_log_indent(); \
|
|
|
|
} \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
2007-02-09 15:52:09 -06:00
|
|
|
#define gnc_leave_return_val_if_fail(test, val) do { \
|
|
|
|
if (! (test)) { LEAVE(""); } \
|
|
|
|
g_return_val_if_fail(test, val); \
|
|
|
|
} while (0);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2007-02-09 15:52:09 -06:00
|
|
|
#define gnc_leave_return_if_fail(test) do { \
|
|
|
|
if (! (test)) { LEAVE(""); } \
|
|
|
|
g_return_if_fail(test); \
|
|
|
|
} while (0);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2007-02-09 15:52:09 -06:00
|
|
|
/** Print a function exit debugging message */
|
|
|
|
#define LEAVE(format, args...) do { \
|
|
|
|
if (qof_log_check(log_module, G_LOG_LEVEL_DEBUG)) { \
|
|
|
|
qof_log_dedent(); \
|
|
|
|
g_log (log_module, G_LOG_LEVEL_DEBUG, \
|
|
|
|
"[leave %s()] " format, \
|
|
|
|
PRETTY_FUNC_NAME , ## args); \
|
|
|
|
} \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* -------------------------------------------------------- */
|
2007-02-09 11:35:00 -06:00
|
|
|
|
2006-01-08 11:51:29 -06:00
|
|
|
/** Infrastructure to make timing measurements for critical pieces
|
|
|
|
* of code. Used for only for performance tuning & debugging.
|
|
|
|
*/
|
|
|
|
|
2006-04-07 13:50:08 -05:00
|
|
|
void qof_start_clock (gint clockno, QofLogModule log_module, QofLogLevel log_level,
|
|
|
|
const gchar *function_name, const gchar *format, ...);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2006-04-07 13:50:08 -05:00
|
|
|
void qof_report_clock (gint clockno,
|
2006-01-08 11:51:29 -06:00
|
|
|
QofLogModule log_module,
|
|
|
|
QofLogLevel log_level,
|
2006-04-07 13:50:08 -05:00
|
|
|
const gchar *function_name,
|
|
|
|
const gchar *format, ...);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
2006-04-07 13:50:08 -05:00
|
|
|
void qof_report_clock_total (gint clockno,
|
2006-01-08 11:51:29 -06:00
|
|
|
QofLogModule log_module,
|
|
|
|
QofLogLevel log_level,
|
2006-04-07 13:50:08 -05:00
|
|
|
const gchar *function_name,
|
|
|
|
const gchar *format, ...);
|
2006-01-08 11:51:29 -06:00
|
|
|
|
|
|
|
/** start a particular timer */
|
|
|
|
#define START_CLOCK(clockno,format, args...) do { \
|
2006-03-08 21:48:49 -06:00
|
|
|
if (qof_log_check (log_module, QOF_LOG_INFO)) \
|
|
|
|
qof_start_clock (clockno, log_module, QOF_LOG_INFO, \
|
2006-02-19 16:54:39 -06:00
|
|
|
__FUNCTION__, format , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** report elapsed time since last report on a particular timer */
|
|
|
|
#define REPORT_CLOCK(clockno,format, args...) do { \
|
2006-03-08 21:48:49 -06:00
|
|
|
if (qof_log_check (log_module, QOF_LOG_INFO)) \
|
|
|
|
qof_report_clock (clockno, log_module, QOF_LOG_INFO, \
|
2006-02-19 16:54:39 -06:00
|
|
|
__FUNCTION__, format , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** report total elapsed time since timer started */
|
|
|
|
#define REPORT_CLOCK_TOTAL(clockno,format, args...) do { \
|
2006-03-08 21:48:49 -06:00
|
|
|
if (qof_log_check (log_module, QOF_LOG_INFO)) \
|
|
|
|
qof_report_clock_total (clockno, log_module, QOF_LOG_INFO, \
|
2006-02-19 16:54:39 -06:00
|
|
|
__FUNCTION__, format , ## args); \
|
2006-01-08 11:51:29 -06:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* _QOF_LOG_H */
|
|
|
|
|
|
|
|
/** @} */
|