[libsoup] soup-logger: Allow logger to be effectively used by bindings
- From: Jonh Wendell <jwendell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] soup-logger: Allow logger to be effectively used by bindings
- Date: Wed, 13 Jul 2016 00:43:41 +0000 (UTC)
commit 2ac4f2790cbcd415855546a0c26e9d9f6c0df7e4
Author: Jonh Wendell <jonh wendell redhat com>
Date: Tue Jul 12 21:39:13 2016 -0300
soup-logger: Allow logger to be effectively used by bindings
By creating the properties level and max-body-size.
Closes #768053.
libsoup/soup-logger.c | 115 ++++++++++++++++++++++++++++++++++++++++++++----
libsoup/soup-logger.h | 3 +
2 files changed, 108 insertions(+), 10 deletions(-)
---
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index 87e8a0a..b7ce19e 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -122,6 +122,15 @@ typedef struct {
} SoupLoggerPrivate;
#define SOUP_LOGGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_LOGGER, SoupLoggerPrivate))
+enum {
+ PROP_0,
+
+ PROP_LEVEL,
+ PROP_MAX_BODY_SIZE,
+
+ LAST_PROP
+};
+
static void
soup_logger_init (SoupLogger *logger)
{
@@ -152,6 +161,46 @@ soup_logger_finalize (GObject *object)
}
static void
+soup_logger_set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ SoupLogger *logger = SOUP_LOGGER (object);
+ SoupLoggerPrivate *priv = SOUP_LOGGER_GET_PRIVATE (logger);
+
+ switch (prop_id) {
+ case PROP_LEVEL:
+ priv->level = g_value_get_enum (value);
+ break;
+ case PROP_MAX_BODY_SIZE:
+ priv->max_body_size = g_value_get_int (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+soup_logger_get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ SoupLogger *logger = SOUP_LOGGER (object);
+ SoupLoggerPrivate *priv = SOUP_LOGGER_GET_PRIVATE (logger);
+
+ switch (prop_id) {
+ case PROP_LEVEL:
+ g_value_set_enum (value, priv->level);
+ break;
+ case PROP_MAX_BODY_SIZE:
+ g_value_set_int (value, priv->max_body_size);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
soup_logger_class_init (SoupLoggerClass *logger_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (logger_class);
@@ -159,6 +208,58 @@ soup_logger_class_init (SoupLoggerClass *logger_class)
g_type_class_add_private (logger_class, sizeof (SoupLoggerPrivate));
object_class->finalize = soup_logger_finalize;
+ object_class->set_property = soup_logger_set_property;
+ object_class->get_property = soup_logger_get_property;
+
+ /* properties */
+ /**
+ * SoupLogger:level:
+ *
+ * The level of logging output
+ *
+ * Since: 2.56
+ */
+ /**
+ * SOUP_LOGGER_LEVEL:
+ *
+ * Alias for the #SoupLogger:level property, qv.
+ *
+ * Since: 2.56
+ **/
+ g_object_class_install_property (
+ object_class, PROP_LEVEL,
+ g_param_spec_enum (SOUP_LOGGER_LEVEL,
+ "Level",
+ "The level of logging output",
+ SOUP_TYPE_LOGGER_LOG_LEVEL,
+ SOUP_LOGGER_LOG_MINIMAL,
+ G_PARAM_READWRITE));
+
+ /**
+ * SoupLogger:max-body-size:
+ *
+ * If #SoupLogger:level is %SOUP_LOGGER_LOG_BODY, this gives
+ * the maximum number of bytes of the body that will be logged.
+ * (-1 means "no limit".)
+ *
+ * Since: 2.56
+ */
+ /**
+ * SOUP_LOGGER_MAX_BODY_SIZE:
+ *
+ * Alias for the #SoupLogger:max-body-size property, qv.
+ *
+ * Since: 2.56
+ **/
+ g_object_class_install_property (
+ object_class, PROP_MAX_BODY_SIZE,
+ g_param_spec_int (SOUP_LOGGER_MAX_BODY_SIZE,
+ "Max Body Size",
+ "The maximum body size to output",
+ -1,
+ G_MAXINT,
+ -1,
+ G_PARAM_READWRITE));
}
/**
@@ -191,16 +292,10 @@ soup_logger_class_init (SoupLoggerClass *logger_class)
SoupLogger *
soup_logger_new (SoupLoggerLogLevel level, int max_body_size)
{
- SoupLogger *logger;
- SoupLoggerPrivate *priv;
-
- logger = g_object_new (SOUP_TYPE_LOGGER, NULL);
-
- priv = SOUP_LOGGER_GET_PRIVATE (logger);
- priv->level = level;
- priv->max_body_size = max_body_size;
-
- return logger;
+ return g_object_new (SOUP_TYPE_LOGGER,
+ SOUP_LOGGER_LEVEL, level,
+ SOUP_LOGGER_MAX_BODY_SIZE, max_body_size,
+ NULL);
}
/**
diff --git a/libsoup/soup-logger.h b/libsoup/soup-logger.h
index ef9172d..df4a347 100644
--- a/libsoup/soup-logger.h
+++ b/libsoup/soup-logger.h
@@ -52,6 +52,9 @@ typedef void (*SoupLoggerPrinter) (SoupLogger *logger,
SOUP_AVAILABLE_IN_2_4
GType soup_logger_get_type (void);
+#define SOUP_LOGGER_LEVEL "level"
+#define SOUP_LOGGER_MAX_BODY_SIZE "max-body-size"
+
SOUP_AVAILABLE_IN_2_4
SoupLogger *soup_logger_new (SoupLoggerLogLevel level,
int max_body_size);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]