From cfbe4027bcbafe4715bbba1b36799002c719a81e Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Sat, 15 Apr 2017 11:58:49 +0200 Subject: [PATCH] Consolidate logging Signed-off-by: Quentin Glidic --- source/dialogs/combi.c | 7 ++-- source/dialogs/dmenu.c | 7 ++-- source/dialogs/drun.c | 17 +++++----- source/dialogs/run.c | 14 ++++---- source/dialogs/script.c | 8 +++-- source/dialogs/ssh.c | 19 +++++------ source/dialogs/window.c | 6 ++-- source/helper.c | 18 +++++----- source/history.c | 18 +++++----- source/rofi.c | 67 +++++++++++++++++++------------------- source/theme.c | 7 ++-- source/view.c | 23 +++++++------ source/widgets/box.c | 5 ++- source/widgets/container.c | 5 ++- source/x11-helper.c | 15 ++++----- source/xrmoptions.c | 8 ++--- 16 files changed, 121 insertions(+), 123 deletions(-) diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index f1e041c3..dd0cfb67 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -24,6 +24,9 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ + +#define G_LOG_DOMAIN "Dialogs.Combi" + #include #include #include @@ -85,7 +88,7 @@ static void combi_mode_parse_switchers ( Mode *sw ) } else { // Report error, don't continue. - fprintf ( stderr, "Invalid script switcher: %s\n", token ); + g_warning ( "Invalid script switcher: %s", token ); token = NULL; } } @@ -240,7 +243,7 @@ static char * combi_get_completion ( const Mode *sw, unsigned int index ) } } // Should never get here. - g_error ( "Failure, could not resolve sub-switcher." ); + g_assert_not_reached (); return NULL; } diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index be9b4be1..255fd720 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -25,6 +25,8 @@ * */ +#define G_LOG_DOMAIN "Dialogs.DMenu" + #include #include #include @@ -47,9 +49,6 @@ #include "xrmoptions.h" #include "view.h" -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "Dialogs.DMenu" - struct range_pair { unsigned int start; @@ -444,7 +443,7 @@ static int dmenu_mode_init ( Mode *sw ) char *estr = rofi_expand_path ( str ); fd = open ( str, O_RDONLY ); if ( fd < 0 ) { - char *msg = g_markup_printf_escaped ( "Failed to open file: %s:\n\t%s", estr, strerror ( errno ) ); + char *msg = g_markup_printf_escaped ( "Failed to open file: %s:\n\t%s", estr, g_strerror ( errno ) ); rofi_view_error_dialog ( msg, TRUE ); g_free ( msg ); g_free ( estr ); diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 062617c0..c16c6f2b 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -24,6 +24,9 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ + +#define G_LOG_DOMAIN "Dialogs.DRun" + #include #ifdef ENABLE_DRUN #include @@ -48,8 +51,6 @@ #include "dialogs/drun.h" #define DRUN_CACHE_FILE "rofi2.druncache" -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "Dialogs.DRun" #define GET_CAT_PARSE_TIME @@ -147,24 +148,24 @@ static void exec_cmd_entry ( DRunModeEntry *e ) GError *error = NULL; GRegex *reg = g_regex_new ( "%[a-zA-Z]", 0, 0, &error ); if ( error != NULL ) { - fprintf ( stderr, "Internal error, failed to create regex: %s.\n", error->message ); + g_warning ( "Internal error, failed to create regex: %s.", error->message ); g_error_free ( error ); return; } struct RegexEvalArg earg = { .e = e, .success = TRUE }; char *str = g_regex_replace_eval ( reg, e->exec, -1, 0, 0, drun_helper_eval_cb, &earg, &error ); if ( error != NULL ) { - fprintf ( stderr, "Internal error, failed replace field codes: %s.\n", error->message ); + g_warning ( "Internal error, failed replace field codes: %s.", error->message ); g_error_free ( error ); return; } g_regex_unref ( reg ); if ( earg.success == FALSE ) { - fprintf ( stderr, "Invalid field code in Exec line: %s.\n", e->exec );; + g_warning ( "Invalid field code in Exec line: %s.", e->exec );; return; } if ( str == NULL ) { - fprintf ( stderr, "Nothing to execute after processing: %s.\n", e->exec );; + g_warning ( "Nothing to execute after processing: %s.", e->exec );; return; } gchar *fp = rofi_expand_path ( g_strstrip ( str ) ); @@ -237,7 +238,7 @@ static gboolean read_desktop_file ( DRunModePrivateData *pd, const char *root, c // Name key is required. if ( !g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) { - g_debug ( "Invalid DesktopFile: '%s', no 'Name' key present.\n", path ); + g_debug ( "Invalid DesktopFile: '%s', no 'Name' key present.", path ); g_key_file_free ( kf ); return FALSE; } @@ -258,7 +259,7 @@ static gboolean read_desktop_file ( DRunModePrivateData *pd, const char *root, c } // We need Exec, don't support DBusActivatable if ( !g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) { - g_debug ( "Unsupported DesktopFile: '%s', no 'Exec' key present.\n", path ); + g_debug ( "Unsupported DesktopFile: '%s', no 'Exec' key present.", path ); g_key_file_free ( kf ); return FALSE; } diff --git a/source/dialogs/run.c b/source/dialogs/run.c index b8534095..62e55150 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -29,6 +29,10 @@ * \ingroup RUNMode * @{ */ + +/** The log domain of this dialog. */ +#define G_LOG_DOMAIN "Dialogs.Run" + #include #include #include @@ -56,10 +60,6 @@ */ #define RUN_CACHE_FILE "rofi-3.runcache" -/** The log domain of this dialog. */ -#undef G_LOG_DOMAIN -#define G_LOG_DOMAIN "Dialogs.Run" - /** * The internal data structure holding the private data of the Run Mode. */ @@ -86,7 +86,7 @@ static void exec_cmd ( const char *cmd, int run_in_term ) gsize lf_cmd_size = 0; gchar *lf_cmd = g_locale_from_utf8 ( cmd, -1, NULL, &lf_cmd_size, &error ); if ( error != NULL ) { - fprintf ( stderr, "Failed to convert command to locale encoding: %s\n", error->message ); + g_warning ( "Failed to convert command to locale encoding: %s", error->message ); g_error_free ( error ); return; } @@ -188,8 +188,8 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i free ( buffer ); } if ( fclose ( inp ) != 0 ) { - fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n", - strerror ( errno ) ); + g_warning ( "Failed to close stdout off executor script: '%s'", + g_strerror ( errno ) ); } } } diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 72594a67..52cc1a03 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -25,6 +25,8 @@ * */ +#define G_LOG_DOMAIN "Dialogs.Script" + #include #include #include @@ -66,8 +68,8 @@ static char **get_script_output ( const char *command, unsigned int *length ) free ( buffer ); } if ( fclose ( inp ) != 0 ) { - fprintf ( stderr, "Failed to close stdout off executor script: '%s'\n", - strerror ( errno ) ); + g_warning ( "Failed to close stdout off executor script: '%s'", + g_strerror ( errno ) ); } } } @@ -201,7 +203,7 @@ Mode *script_switcher_parse_setup ( const char *str ) return sw; } - fprintf ( stderr, "The script command '%s' has %u options, but needs 2: :