[gnome-online-accounts] httpclient, souplogger: Split the logger into a separate class
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] httpclient, souplogger: Split the logger into a separate class
- Date: Fri, 4 Aug 2017 15:04:48 +0000 (UTC)
commit 2b3e38c73c3c5a70ad25c1dc45e714565255d7c2
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Aug 3 17:56:14 2017 +0200
httpclient, souplogger: Split the logger into a separate class
This can now be used to log the RestProxies too.
src/goabackend/Makefile.am | 1 +
src/goabackend/goahttpclient.c | 20 +----------
src/goabackend/goasouplogger.c | 68 ++++++++++++++++++++++++++++++++++++++++
src/goabackend/goasouplogger.h | 38 ++++++++++++++++++++++
4 files changed, 109 insertions(+), 18 deletions(-)
---
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 40b76dc..d54eb37 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -77,6 +77,7 @@ libgoa_backend_1_0_la_SOURCES = \
goamailauth.h goamailauth.c \
goaimapauthlogin.h goaimapauthlogin.c \
goasmtpauth.h goasmtpauth.c \
+ goasouplogger.h goasouplogger.c \
goamailclient.h goamailclient.c \
goaexchangeprovider.h goaexchangeprovider.c \
goaoauthprovider.h goaoauthprovider.c \
diff --git a/src/goabackend/goahttpclient.c b/src/goabackend/goahttpclient.c
index 1522725..4c6c6bc 100644
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -21,6 +21,7 @@
#include <libsoup/soup.h>
#include "goahttpclient.h"
+#include "goasouplogger.h"
#include "goautils.h"
struct _GoaHttpClient
@@ -52,22 +53,6 @@ goa_http_client_new (void)
/* ---------------------------------------------------------------------------------------------------- */
-static void
-http_client_log_printer (SoupLogger *logger,
- SoupLoggerLogLevel level,
- gchar direction,
- const gchar *data,
- gpointer user_data)
-{
- gchar *message;
-
- message = g_strdup_printf ("%c %s", direction, data);
- g_log_default_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message, NULL);
- g_free (message);
-}
-
-/* ---------------------------------------------------------------------------------------------------- */
-
typedef struct
{
GCancellable *cancellable;
@@ -225,8 +210,7 @@ goa_http_client_check (GoaHttpClient *self,
data->session = soup_session_new_with_options (SOUP_SESSION_SSL_STRICT, FALSE,
NULL);
- logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1);
- soup_logger_set_printer (logger, http_client_log_printer, NULL, NULL);
+ logger = goa_soup_logger_new (SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature (data->session, SOUP_SESSION_FEATURE (logger));
g_object_unref (logger);
diff --git a/src/goabackend/goasouplogger.c b/src/goabackend/goasouplogger.c
new file mode 100644
index 0000000..9b0a53d
--- /dev/null
+++ b/src/goabackend/goasouplogger.c
@@ -0,0 +1,68 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "goasouplogger.h"
+
+struct _GoaSoupLogger
+{
+ SoupLogger parent_instance;
+};
+
+G_DEFINE_TYPE (GoaSoupLogger, goa_soup_logger, SOUP_TYPE_LOGGER);
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+goa_soup_logger_printer (SoupLogger *logger,
+ SoupLoggerLogLevel level,
+ gchar direction,
+ const gchar *data,
+ gpointer user_data)
+{
+ gchar *message;
+
+ message = g_strdup_printf ("%c %s", direction, data);
+ g_log_default_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message, NULL);
+ g_free (message);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+goa_soup_logger_init (GoaSoupLogger *self)
+{
+ soup_logger_set_printer (SOUP_LOGGER (self), goa_soup_logger_printer, NULL, NULL);
+}
+
+static void
+goa_soup_logger_class_init (GoaSoupLoggerClass *klass)
+{
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+SoupLogger *
+goa_soup_logger_new (SoupLoggerLogLevel level,
+ gint max_body_size)
+{
+ return g_object_new (GOA_TYPE_SOUP_LOGGER, "level", level, "max-body-size", max_body_size, NULL);
+}
diff --git a/src/goabackend/goasouplogger.h b/src/goabackend/goasouplogger.h
new file mode 100644
index 0000000..4a99785
--- /dev/null
+++ b/src/goabackend/goasouplogger.h
@@ -0,0 +1,38 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION)
+#error "Only <goabackend/goabackend.h> can be included directly."
+#endif
+
+#ifndef __GOA_SOUP_LOGGER_H__
+#define __GOA_SOUP_LOGGER_H__
+
+#include <libsoup/soup.h>
+
+G_BEGIN_DECLS
+
+#define GOA_TYPE_SOUP_LOGGER (goa_soup_logger_get_type ())
+G_DECLARE_FINAL_TYPE (GoaSoupLogger, goa_soup_logger, GOA, SOUP_LOGGER, SoupLogger);
+
+SoupLogger *goa_soup_logger_new (SoupLoggerLogLevel level,
+ gint max_body_size);
+
+G_END_DECLS
+
+#endif /* __GOA_SOUP_LOGGER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]