mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Restore enter/leave indentation. Cleanup some deprecated and (nearly-)unused qoflog code. Audit fraction enter/leave pairs. :/
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15539 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -38,10 +38,7 @@ const char * gnc_log_prettify (const char *name)
|
||||
void gnc_start_clock (int a, QofLogModule b, gncLogLevel c, const char *d, const char *e, ...) { }
|
||||
void gnc_report_clock (int a, QofLogModule b, gncLogLevel c, const char *d, const char *e, ...) { }
|
||||
void gnc_report_clock_total (int a, QofLogModule b, gncLogLevel c, const char *d, const char *e, ...) { }
|
||||
gboolean gnc_should_log(QofLogModule log_module, gncLogLevel log_level)
|
||||
{
|
||||
return qof_log_check(log_module, log_level);
|
||||
}
|
||||
|
||||
gint
|
||||
gnc_engine_register_event_handler (GNCEngineEventHandler handler,
|
||||
gpointer user_data)
|
||||
|
||||
@@ -66,21 +66,6 @@ const char * gnc_log_prettify (const char *name);
|
||||
/** \deprecated use qof_log_check instead. */
|
||||
gboolean gnc_should_log(QofLogModule log_module, gncLogLevel log_level);
|
||||
|
||||
/** \deprecated */
|
||||
#define GNC_LOG_FATAL QOF_LOG_FATAL
|
||||
/** \deprecated */
|
||||
#define GNC_LOG_ERROR QOF_LOG_ERROR
|
||||
/** \deprecated */
|
||||
#define GNC_LOG_WARNING QOF_LOG_WARNING
|
||||
/** \deprecated */
|
||||
#define GNC_LOG_INFO QOF_LOG_INFO
|
||||
/** \deprecated */
|
||||
#define GNC_LOG_DEBUG QOF_LOG_DEBUG
|
||||
/** \deprecated */
|
||||
#define GNC_LOG_DETAIL QOF_LOG_DETAIL
|
||||
/** \deprecated */
|
||||
#define GNC_LOG_TRACE QOF_LOG_TRACE
|
||||
|
||||
/** \deprecated use qof_start_clock */
|
||||
void gnc_start_clock (int, QofLogModule, gncLogLevel, const char*, const char*, ...);
|
||||
/** \deprecated use qof_report_clock */
|
||||
|
||||
@@ -57,19 +57,13 @@ static GHashTable *log_table = NULL;
|
||||
static GLogFunc previous_handler = NULL;
|
||||
|
||||
void
|
||||
qof_log_add_indent(void)
|
||||
qof_log_indent(void)
|
||||
{
|
||||
qof_log_num_spaces += QOF_LOG_INDENT_WIDTH;
|
||||
}
|
||||
|
||||
gint
|
||||
qof_log_get_indent(void)
|
||||
{
|
||||
return qof_log_num_spaces;
|
||||
}
|
||||
|
||||
void
|
||||
qof_log_drop_indent(void)
|
||||
qof_log_dedent(void)
|
||||
{
|
||||
qof_log_num_spaces
|
||||
= (qof_log_num_spaces < QOF_LOG_INDENT_WIDTH)
|
||||
@@ -96,48 +90,9 @@ log4glib_handler(const gchar *log_domain,
|
||||
const gchar *message,
|
||||
gpointer user_data)
|
||||
{
|
||||
gboolean debug = FALSE;
|
||||
GHashTable *log_levels = (GHashTable*)user_data;
|
||||
gchar *domain_copy = g_strdup(log_domain == NULL ? "" : log_domain);
|
||||
gchar *dot_pointer = domain_copy;
|
||||
static const QofLogLevel default_log_thresh = QOF_LOG_WARNING;
|
||||
QofLogLevel longest_match_level = default_log_thresh;
|
||||
if (G_LIKELY(!qof_log_check(log_domain, log_level)))
|
||||
return;
|
||||
|
||||
{
|
||||
gpointer match_level;
|
||||
if ((match_level = g_hash_table_lookup(log_levels, "")) != NULL)
|
||||
longest_match_level = (QofLogLevel)GPOINTER_TO_INT(match_level);
|
||||
}
|
||||
|
||||
if (debug) { printf("trying [%s] (%d):", log_domain, g_hash_table_size(log_levels)); }
|
||||
if (log_levels)
|
||||
{
|
||||
// e.g., "a.b.c" -> "a\0b.c" -> "a.b\0c", "a.b.c"
|
||||
gpointer match_level;
|
||||
while ((dot_pointer = g_strstr_len(dot_pointer, strlen(dot_pointer), ".")) != NULL)
|
||||
{
|
||||
*dot_pointer = '\0';
|
||||
if (debug) { printf(" [%s]", domain_copy); }
|
||||
if (g_hash_table_lookup_extended(log_levels, domain_copy, NULL, &match_level))
|
||||
{
|
||||
longest_match_level = (QofLogLevel)GPOINTER_TO_INT(match_level);
|
||||
if (debug) printf("*");
|
||||
}
|
||||
*dot_pointer = '.';
|
||||
dot_pointer++;
|
||||
}
|
||||
|
||||
if (debug) { printf(" [%s]", domain_copy); }
|
||||
if (g_hash_table_lookup_extended(log_levels, domain_copy, NULL, &match_level))
|
||||
{
|
||||
longest_match_level = (QofLogLevel)GPOINTER_TO_INT(match_level);
|
||||
if (debug) { printf("*"); }
|
||||
}
|
||||
}
|
||||
if (debug) { printf(" found [%d]\n", longest_match_level); }
|
||||
g_free(domain_copy);
|
||||
|
||||
if (log_level <= longest_match_level)
|
||||
{
|
||||
gboolean last_char_is_newline;
|
||||
char timestamp_buf[10];
|
||||
@@ -152,7 +107,7 @@ log4glib_handler(const gchar *log_domain,
|
||||
timestamp_buf,
|
||||
5, level_str,
|
||||
(log_domain == NULL ? "" : log_domain),
|
||||
0 /*qof_log_num_spaces*/, "",
|
||||
qof_log_num_spaces, "",
|
||||
message,
|
||||
(g_str_has_suffix(message, "\n") ? "" : "\n"));
|
||||
fflush(fout);
|
||||
@@ -269,13 +224,51 @@ qof_log_prettify (const char *name)
|
||||
}
|
||||
|
||||
gboolean
|
||||
qof_log_check(QofLogModule log_module, QofLogLevel log_level)
|
||||
qof_log_check(QofLogModule log_domain, QofLogLevel log_level)
|
||||
{
|
||||
QofLogLevel level, maximum;
|
||||
if (!log_table || log_module == NULL || log_level < 0) { return FALSE; }
|
||||
maximum = GPOINTER_TO_INT(g_hash_table_lookup(log_table, log_module));
|
||||
if (log_level <= maximum) { return TRUE; }
|
||||
return FALSE;
|
||||
//#define _QLC_DBG(x) x
|
||||
#define _QLC_DBG(x)
|
||||
GHashTable *log_levels = log_table;
|
||||
gchar *domain_copy = g_strdup(log_domain == NULL ? "" : log_domain);
|
||||
gchar *dot_pointer = domain_copy;
|
||||
static const QofLogLevel default_log_thresh = QOF_LOG_WARNING;
|
||||
QofLogLevel longest_match_level = default_log_thresh;
|
||||
|
||||
{
|
||||
gpointer match_level;
|
||||
if ((match_level = g_hash_table_lookup(log_levels, "")) != NULL)
|
||||
longest_match_level = (QofLogLevel)GPOINTER_TO_INT(match_level);
|
||||
}
|
||||
|
||||
_QLC_DBG({ printf("trying [%s] (%d):", log_domain, g_hash_table_size(log_levels)); });
|
||||
if (G_LIKELY(log_levels))
|
||||
{
|
||||
// e.g., "a.b.c" -> "a\0b.c" -> "a.b\0c", "a.b.c"
|
||||
gpointer match_level;
|
||||
while ((dot_pointer = g_strstr_len(dot_pointer, strlen(dot_pointer), ".")) != NULL)
|
||||
{
|
||||
*dot_pointer = '\0';
|
||||
_QLC_DBG({ printf(" [%s]", domain_copy); });
|
||||
if (g_hash_table_lookup_extended(log_levels, domain_copy, NULL, &match_level))
|
||||
{
|
||||
longest_match_level = (QofLogLevel)GPOINTER_TO_INT(match_level);
|
||||
_QLC_DBG(printf("*"););
|
||||
}
|
||||
*dot_pointer = '.';
|
||||
dot_pointer++;
|
||||
}
|
||||
|
||||
_QLC_DBG({ printf(" [%s]", domain_copy); });
|
||||
if (g_hash_table_lookup_extended(log_levels, domain_copy, NULL, &match_level))
|
||||
{
|
||||
longest_match_level = (QofLogLevel)GPOINTER_TO_INT(match_level);
|
||||
_QLC_DBG({ printf("*"); });
|
||||
}
|
||||
}
|
||||
_QLC_DBG({ printf(" found [%d]\n", longest_match_level); });
|
||||
g_free(domain_copy);
|
||||
|
||||
return log_level <= longest_match_level;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -45,26 +45,20 @@
|
||||
_(QOF_LOG_ERROR, = G_LOG_LEVEL_CRITICAL) \
|
||||
_(QOF_LOG_WARNING, = G_LOG_LEVEL_WARNING) \
|
||||
_(QOF_LOG_INFO, = G_LOG_LEVEL_INFO) \
|
||||
_(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG) \
|
||||
_(QOF_LOG_DETAIL, = G_LOG_LEVEL_DEBUG) \
|
||||
_(QOF_LOG_TRACE, = G_LOG_LEVEL_DEBUG)
|
||||
_(QOF_LOG_DEBUG, = G_LOG_LEVEL_DEBUG)
|
||||
|
||||
DEFINE_ENUM (QofLogLevel, LOG_LEVEL_LIST)
|
||||
|
||||
gchar* qof_log_level_to_string(QofLogLevel lvl);
|
||||
QofLogLevel qof_log_level_from_string(gchar *str);
|
||||
|
||||
/** indents once for each ENTER macro */
|
||||
void qof_log_add_indent(void);
|
||||
|
||||
/** gets the running total of the indent */
|
||||
gint qof_log_get_indent(void);
|
||||
/** indents once for each ENTER macro **/
|
||||
void qof_log_indent(void);
|
||||
|
||||
/**
|
||||
* drops back one indent for each LEAVE macro
|
||||
* indent is reset to zero if less than a single indent would exist.
|
||||
* drops back one indent for each LEAVE macro, capped at 0.
|
||||
**/
|
||||
void qof_log_drop_indent(void);
|
||||
void qof_log_dedent(void);
|
||||
|
||||
/**
|
||||
* Initialize the error logging subsystem. Defaults to a level-threshold of
|
||||
@@ -79,14 +73,11 @@ void qof_log_set_level(QofLogModule module, QofLogLevel level);
|
||||
|
||||
/**
|
||||
* Specify an alternate log output, to pipe or file.
|
||||
* Needs to be called \b before qof_log_init()
|
||||
* \deprecated
|
||||
**/
|
||||
void qof_log_set_file (FILE *outfile);
|
||||
|
||||
/**
|
||||
* Specify a filename for log output.
|
||||
* Calls qof_log_init() for you.
|
||||
**/
|
||||
void qof_log_init_filename (const gchar* logfilename);
|
||||
|
||||
@@ -143,30 +134,32 @@ typedef void (*QofLogCB) (QofLogModule log_module, QofLogLevel* log_level,
|
||||
|
||||
/** Print a function entry debugging message */
|
||||
#define ENTER(format, args...) do { \
|
||||
g_log (log_module, G_LOG_LEVEL_DEBUG, \
|
||||
"[enter %s:%s()] " format, __FILE__, \
|
||||
PRETTY_FUNC_NAME , ## args); \
|
||||
qof_log_add_indent(); \
|
||||
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(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define gnc_leave_return_val_if_fail(test, val) do { \
|
||||
if (! (test)) { LEAVE(""); } \
|
||||
g_return_val_if_fail(test, val); \
|
||||
} while (0);
|
||||
|
||||
#define gnc_leave_return_if_fail(test) do { \
|
||||
if (! (test)) { LEAVE(""); } \
|
||||
g_return_if_fail(test); \
|
||||
} while (0);
|
||||
|
||||
/** Print a function exit debugging message */
|
||||
#define LEAVE(format, args...) do { \
|
||||
qof_log_drop_indent(); \
|
||||
g_log (log_module, G_LOG_LEVEL_DEBUG, \
|
||||
"[leave %s()] " format, \
|
||||
PRETTY_FUNC_NAME , ## args); \
|
||||
} while (0)
|
||||
|
||||
/** Print a function trace debugging message */
|
||||
#define TRACE(format, args...) do { \
|
||||
g_log (log_module, G_LOG_LEVEL_DEBUG, \
|
||||
"[trace %s()] " format, PRETTY_FUNC_NAME , ## args); \
|
||||
} while (0)
|
||||
|
||||
#define DEBUGCMD(x) do { \
|
||||
if (qof_log_check (log_module, QOF_LOG_DEBUG)) { \
|
||||
(x); \
|
||||
} \
|
||||
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); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* -------------------------------------------------------- */
|
||||
|
||||
@@ -709,7 +709,8 @@ static GList * qof_query_run_internal (QofQuery *q,
|
||||
}
|
||||
|
||||
/* Maybe log this sucker */
|
||||
if (qof_log_check (log_module, QOF_LOG_DETAIL)) qof_query_print (q);
|
||||
if (qof_log_check (log_module, QOF_LOG_DEBUG))
|
||||
qof_query_print (q);
|
||||
|
||||
/* Now run the query over all the objects and save the results */
|
||||
{
|
||||
|
||||
@@ -884,7 +884,7 @@ qof_sql_query_run (QofSqlQuery *query, const char *str)
|
||||
|
||||
qof_query_set_book (query->qof_query, query->book);
|
||||
/* Maybe log this sucker */
|
||||
if (gnc_should_log (log_module, GNC_LOG_DETAIL))
|
||||
if (qof_should_log (log_module, QOF_LOG_DEBUG))
|
||||
{
|
||||
qof_query_print (query->qof_query);
|
||||
}
|
||||
@@ -911,7 +911,7 @@ qof_sql_query_rerun (QofSqlQuery *query)
|
||||
qof_query_set_book (query->qof_query, query->book);
|
||||
|
||||
/* Maybe log this sucker */
|
||||
if (gnc_should_log (log_module, GNC_LOG_DETAIL))
|
||||
if (qof_should_log (log_module, QOF_LOG_DEBUG))
|
||||
{
|
||||
qof_query_print (query->qof_query);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user