# HG changeset patch # User Colin Clark # Date 1498393431 -3600 # Node ID 9897069380d9f2d3a86826cd63554d55a6537492 # Parent 9e7284cfd7be7ed0d9abfb33d9806be25eaaf9bb Bug fix: Additional debug features Ensure grep works on entire message line guint/gint compile problem compile with --disable-debug-log (patch by Guillaume Castagnino) diff -r 9e7284cfd7be -r 9897069380d9 src/debug.c --- a/src/debug.c Sat Jun 24 20:47:50 2017 +0100 +++ b/src/debug.c Sun Jun 25 13:23:51 2017 +0100 @@ -32,16 +32,6 @@ */ static gchar *regexp = NULL; -void set_regexp(gchar *cmd_regexp) -{ - regexp = g_strdup(cmd_regexp); -} - -gchar *get_regexp() -{ - return g_strdup(regexp); -} - static gboolean log_msg_cb(gpointer data) { gchar *buf = data; @@ -58,48 +48,72 @@ return FALSE; } +void log_domain_print_message(const gchar *domain, gchar *buf) +{ + gchar *buf_nl; + regex_t regex; + gint ret_comp, ret_exec; + + buf_nl = g_strconcat(buf, "\n", NULL); + + if (regexp && command_line) + { + ret_comp = regcomp(®ex, regexp, 0); + if (!ret_comp) + { + ret_exec = regexec(®ex, buf_nl, 0, NULL, 0); + + if (!ret_exec) + { + print_term(buf_nl); + if (strcmp(domain, DOMAIN_INFO) == 0) + g_idle_add(log_normal_cb, buf_nl); + else + g_idle_add(log_msg_cb, buf_nl); + } + regfree(®ex); + } + } + else + { + print_term(buf_nl); + if (strcmp(domain, DOMAIN_INFO) == 0) + g_idle_add(log_normal_cb, buf_nl); + else + g_idle_add(log_msg_cb, buf_nl); + } + g_free(buf); +} + +void log_domain_print_debug(const gchar *domain, const gchar *file_name, + int line_number, const gchar *format, ...) +{ + va_list ap; + gchar *message; + gchar *location; + gchar *buf; + + va_start(ap, format); + message = g_strdup_vprintf(format, ap); + va_end(ap); + + location = g_strdup_printf("%s:%d:", file_name, line_number); + buf = g_strconcat(location, message, NULL); + log_domain_print_message(domain,buf); + g_free(location); + g_free(message); +} + void log_domain_printf(const gchar *domain, const gchar *format, ...) { va_list ap; gchar *buf; - regex_t regex; - gint ret_comp, ret_exec; - gchar *filtered_buf; va_start(ap, format); buf = g_strdup_vprintf(format, ap); va_end(ap); - if (regexp && command_line && buf) - { - if (g_strcmp0(buf,"\n")) - { - ret_comp = regcomp(®ex, regexp, 0); - if (!ret_comp) - { - ret_exec = regexec(®ex, buf, 0, NULL, 0); - - filtered_buf = g_strconcat(buf, "\n", NULL); - if (!ret_exec) - { - print_term(filtered_buf); - if (strcmp(domain, DOMAIN_INFO) == 0) - g_idle_add(log_normal_cb, filtered_buf); - else - g_idle_add(log_msg_cb, filtered_buf); - } - regfree(®ex); - } - } - } - else - { - print_term(buf); - if (strcmp(domain, DOMAIN_INFO) == 0) - g_idle_add(log_normal_cb, buf); - else - g_idle_add(log_msg_cb, buf); - } + log_domain_print_message(domain, buf); } /* @@ -191,5 +205,15 @@ get_exec_time(); } +void set_regexp(gchar *cmd_regexp) +{ + regexp = g_strdup(cmd_regexp); +} + +gchar *get_regexp(void) +{ + return g_strdup(regexp); +} + #endif /* DEBUG */ /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ diff -r 9e7284cfd7be -r 9897069380d9 src/debug.h --- a/src/debug.h Sat Jun 24 20:47:50 2017 +0100 +++ b/src/debug.h Sun Jun 25 13:23:51 2017 +0100 @@ -27,6 +27,8 @@ #define DOMAIN_INFO "info" void log_domain_printf(const gchar *domain, const gchar *format, ...) G_GNUC_PRINTF(2, 3); +void log_domain_print_debug(const gchar *domain, const gchar *file_name, + int line_number, const gchar *format, ...) G_GNUC_PRINTF(4, 5); #define log_printf(...) log_domain_printf(DOMAIN_INFO, __VA_ARGS__) #ifdef DEBUG @@ -35,7 +37,7 @@ #define DEBUG_LEVEL_MAX 4 void set_regexp(gchar *regexp); -gchar *get_regexp(); +gchar *get_regexp(void); gint get_debug_level(void); void set_debug_level(gint new_level); void debug_level_add(gint delta); @@ -48,14 +50,21 @@ gint debug_level = get_debug_level(); \ if (debug_level >= (n)) \ { \ - if (debug_level != 1) log_domain_printf(DOMAIN_DEBUG, "%s:%d: ", __FILE__, __LINE__); \ - log_domain_printf(DOMAIN_DEBUG, __VA_ARGS__); \ - log_domain_printf(DOMAIN_DEBUG, "\n"); \ + if (debug_level != 1) \ + { \ + log_domain_print_debug(DOMAIN_DEBUG, __FILE__, __LINE__, __VA_ARGS__); \ + } \ + else \ + { \ + log_domain_printf(DOMAIN_DEBUG, __VA_ARGS__); \ + } \ } \ } while (0) #else /* DEBUG */ +#define get_regexp() (0) +#define set_regexp(regexp) do { } while(0) #define get_debug_level() (0) #define set_debug_level(new_level) do { } while(0) #define debug_level_add(delta) do { } while(0) diff -r 9e7284cfd7be -r 9897069380d9 src/options.h --- a/src/options.h Sat Jun 24 20:47:50 2017 +0100 +++ b/src/options.h Sun Jun 25 13:23:51 2017 +0100 @@ -54,7 +54,7 @@ gboolean use_saved_window_positions_for_new_windows; gboolean tools_restore_state; - guint log_window_lines; + gint log_window_lines; /* info sidebar component heights */ struct {