From 06bc4acf3adc14a69eb9bad4402a40c81aab3fd6 Mon Sep 17 00:00:00 2001 From: Daniel Teichmann Date: Wed, 25 Aug 2021 14:38:40 +0200 Subject: Add _remmina_{info, message, debug, warning, error, critical} log functions; Add REMMINA_PLUGIN_{..., ...} defines. GLib oriented log functions printing both to Remmina's own debug window and to stdout. Newline are always added and can't be turned off. Thats a GLib flaw. !!! Calling g_error (_remmina_error) crashes Remmina purposefully with a trap signal !!! --- src/remmina_log.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 2 deletions(-) (limited to 'src/remmina_log.c') diff --git a/src/remmina_log.c b/src/remmina_log.c index 5aa105d1e..f208338e3 100644 --- a/src/remmina_log.c +++ b/src/remmina_log.c @@ -178,6 +178,8 @@ static gboolean remmina_log_print_real(gpointer data) return FALSE; } +// Only prints into Remmina's own debug window. (Not stdout!) +// See _remmina_{debug, info, error, critical, warning} void remmina_log_print(const gchar *text) { TRACE_CALL(__func__); @@ -187,6 +189,54 @@ void remmina_log_print(const gchar *text) IDLE_ADD(remmina_log_print_real, g_strdup(text)); } +void _remmina_info(const gchar *fmt, ...) +{ + TRACE_CALL(__func__); + + va_list args; + g_autofree gchar *text; + va_start(args, fmt); + text = g_strdup_vprintf(fmt, args); + va_end(args); + + // always appends newline + g_info ("%s", text); + + g_autofree gchar *buf_tmp = g_strconcat(text, "\n", NULL); + /* freed in remmina_log_print_real */ + gchar *bufn = g_strconcat("(INFO) - ", buf_tmp, NULL); + + if (!log_window) { + free(bufn); + return; + } + IDLE_ADD(remmina_log_print_real, bufn); +} + +void _remmina_message(const gchar *fmt, ...) +{ + TRACE_CALL(__func__); + + va_list args; + g_autofree gchar *text; + va_start(args, fmt); + text = g_strdup_vprintf(fmt, args); + va_end(args); + + // always appends newline + g_message ("%s", text); + + g_autofree gchar *buf_tmp = g_strconcat(text, "\n", NULL); + /* freed in remmina_log_print_real */ + gchar *bufn = g_strconcat("(MESSAGE) - ", buf_tmp, NULL); + + if (!log_window) { + free(bufn); + return; + } + IDLE_ADD(remmina_log_print_real, bufn); +} + /** * Print a string in the Remmina Debug Windows and in the terminal. * The string will be visible in the terminal if G_MESSAGES_DEBUG=all @@ -205,10 +255,12 @@ void _remmina_debug(const gchar *fun, const gchar *fmt, ...) g_autofree gchar *buf = g_strconcat("(", fun, ") - ", text, NULL); g_free(text); + // always appends newline g_debug ("%s", buf); + g_autofree gchar *buf_tmp = g_strconcat(buf, "\n", NULL); /* freed in remmina_log_print_real */ - gchar *bufn = g_strconcat(buf, "\n", NULL); + gchar *bufn = g_strconcat("(DEBUG) - ", buf_tmp, NULL); if (!log_window) { free(bufn); @@ -217,6 +269,91 @@ void _remmina_debug(const gchar *fun, const gchar *fmt, ...) IDLE_ADD(remmina_log_print_real, bufn); } +void _remmina_warning(const gchar *fun, const gchar *fmt, ...) +{ + TRACE_CALL(__func__); + + va_list args; + gchar *text; + va_start(args, fmt); + text = g_strdup_vprintf(fmt, args); + va_end(args); + + g_autofree gchar *buf = g_strconcat("(", fun, ") - ", text, NULL); + g_free(text); + + // always appends newline + g_warning ("%s", buf); + + g_autofree gchar *buf_tmp = g_strconcat(buf, "\n", NULL); + /* freed in remmina_log_print_real */ + gchar *bufn = g_strconcat("(WARN) - ", buf_tmp, NULL); + + if (!log_window) { + free(bufn); + return; + } + IDLE_ADD(remmina_log_print_real, bufn); +} + +// !!! Calling this function will crash Remmina !!! +// !!! purposefully and send a trap signal !!! +void _remmina_error(const gchar *fun, const gchar *fmt, ...) +{ + TRACE_CALL(__func__); + + va_list args; + gchar *text; + va_start(args, fmt); + text = g_strdup_vprintf(fmt, args); + va_end(args); + + g_autofree gchar *buf = g_strconcat("(", fun, ") - ", text, NULL); + g_free(text); + + // always appends newline + g_error ("%s", buf); + + g_autofree gchar *buf_tmp = g_strconcat(buf, "\n", NULL); + /* freed in remmina_log_print_real */ + gchar *bufn = g_strconcat("(ERROR) - ", buf_tmp, NULL); + + if (!log_window) { + free(bufn); + return; + } + IDLE_ADD(remmina_log_print_real, bufn); +} + +void _remmina_critical(const gchar *fun, const gchar *fmt, ...) +{ + TRACE_CALL(__func__); + + va_list args; + gchar *text; + va_start(args, fmt); + text = g_strdup_vprintf(fmt, args); + va_end(args); + + g_autofree gchar *buf = g_strconcat("(", fun, ") - ", text, NULL); + g_free(text); + + // always appends newline + g_critical ("%s", buf); + + g_autofree gchar *buf_tmp = g_strconcat(buf, "\n", NULL); + /* freed in remmina_log_print_real */ + gchar *bufn = g_strconcat("(CRIT) - ", buf_tmp, NULL); + + if (!log_window) { + free(bufn); + return; + } + IDLE_ADD(remmina_log_print_real, bufn); +} + +// Only prints into Remmina's own debug window. (Not stdout!) +// See _remmina_{debug, info, error, critical, warning} void remmina_log_printf(const gchar *fmt, ...) { TRACE_CALL(__func__); @@ -231,4 +368,3 @@ void remmina_log_printf(const gchar *fmt, ...) IDLE_ADD(remmina_log_print_real, text); } - -- cgit v1.2.3