[glib-networking/nacho/logging-define] tlslog: add a define to log at debug level
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib-networking/nacho/logging-define] tlslog: add a define to log at debug level
- Date: Fri, 13 May 2022 13:21:02 +0000 (UTC)
commit 1508e0ead4e1e1a7d4f52060020d16e68796347b
Author: Ignacio Casal Quinteiro <qignacio amazon com>
Date: Fri May 13 15:20:09 2022 +0200
tlslog: add a define to log at debug level
Otherwise this becomes expensive when doing lots of read/writes
and endups consuming quite a bit of CPU.
Partially fixes #188
tls/base/gtlslog.c | 68 +++++++++++++++++++++++++++++-------------------------
1 file changed, 37 insertions(+), 31 deletions(-)
---
diff --git a/tls/base/gtlslog.c b/tls/base/gtlslog.c
index cf3ab054..c67d4b7d 100644
--- a/tls/base/gtlslog.c
+++ b/tls/base/gtlslog.c
@@ -31,6 +31,9 @@
#include "gtlslog.h"
+// Change this define to 1 if you want to enable debug logs
+#define ENABLE_DEBUG_LOGGING 0
+
void g_tls_log (GLogLevelFlags level,
gpointer conn,
const gchar *file,
@@ -39,40 +42,43 @@ void g_tls_log (GLogLevelFlags level,
const gchar *format,
...)
{
- gchar *header = NULL;
- gchar *message = NULL;
- gchar *thread = NULL;
- va_list args;
- int ret;
+ if ((level & G_LOG_LEVEL_MASK) < G_LOG_LEVEL_DEBUG || ENABLE_DEBUG_LOGGING)
+ {
+ gchar *header = NULL;
+ gchar *message = NULL;
+ gchar *thread = NULL;
+ va_list args;
+ int ret;
- va_start (args, format);
- ret = g_vasprintf (&message, format, args);
- va_end (args);
+ va_start (args, format);
+ ret = g_vasprintf (&message, format, args);
+ va_end (args);
- if (ret <= 0)
- goto out;
+ if (ret <= 0)
+ goto out;
- if (conn && G_IS_TLS_CONNECTION (conn)) {
- if (G_IS_TLS_CLIENT_CONNECTION (conn))
- header = g_strdup_printf ("CLIENT[%p]: ", conn);
- else if (G_IS_TLS_SERVER_CONNECTION (conn))
- header = g_strdup_printf ("SERVER[%p]: ", conn);
- else
- g_assert_not_reached ();
- } else {
- header = g_strdup ("");
- }
+ if (conn && G_IS_TLS_CONNECTION (conn)) {
+ if (G_IS_TLS_CLIENT_CONNECTION (conn))
+ header = g_strdup_printf ("CLIENT[%p]: ", conn);
+ else if (G_IS_TLS_SERVER_CONNECTION (conn))
+ header = g_strdup_printf ("SERVER[%p]: ", conn);
+ else
+ g_assert_not_reached ();
+ } else {
+ header = g_strdup ("");
+ }
- thread = g_strdup_printf ("%p", g_thread_self ());
- g_log_structured (G_LOG_DOMAIN, level,
- "GLIB_NET_THREAD", thread,
- "CODE_FILE", file,
- "CODE_LINE", line,
- "CODE_FUNC", func,
- "MESSAGE", "%s%s", header, message);
+ thread = g_strdup_printf ("%p", g_thread_self ());
+ g_log_structured (G_LOG_DOMAIN, level,
+ "GLIB_NET_THREAD", thread,
+ "CODE_FILE", file,
+ "CODE_LINE", line,
+ "CODE_FUNC", func,
+ "MESSAGE", "%s%s", header, message);
-out:
- g_free (header);
- g_free (message);
- g_free (thread);
+ out:
+ g_free (header);
+ g_free (message);
+ g_free (thread);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]