diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2020-03-28 08:06:41 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2020-04-08 16:35:08 +0200 |
commit | 9bcadea172cfba9317c55a9265012ff2f739cc96 (patch) | |
tree | dc4c517162fca0d06c01d1d1476d09abb80f4d8d | |
parent | faccb3b2b434d33936d4b7f1bc6bbeab8a14538f (diff) |
log: new object logging support
So that we can provide the specific object id in every log associated
to a given object.
30 files changed, 203 insertions, 47 deletions
diff --git a/plugins/cinterion/tests/test-modem-helpers-cinterion.c b/plugins/cinterion/tests/test-modem-helpers-cinterion.c index 78adf30a..f1d6cddb 100644 --- a/plugins/cinterion/tests/test-modem-helpers-cinterion.c +++ b/plugins/cinterion/tests/test-modem-helpers-cinterion.c @@ -859,7 +859,8 @@ test_ctzu_urc_full (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c index b37c0b16..4f83f49c 100644 --- a/plugins/huawei/tests/test-modem-helpers-huawei.c +++ b/plugins/huawei/tests/test-modem-helpers-huawei.c @@ -1268,7 +1268,8 @@ test_hcsq (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/icera/tests/test-modem-helpers-icera.c b/plugins/icera/tests/test-modem-helpers-icera.c index 592b8b24..ef9d62cc 100644 --- a/plugins/icera/tests/test-modem-helpers-icera.c +++ b/plugins/icera/tests/test-modem-helpers-icera.c @@ -176,7 +176,8 @@ test_ipdpaddr (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/linktop/tests/test-modem-helpers-linktop.c b/plugins/linktop/tests/test-modem-helpers-linktop.c index 827d044f..396abaae 100644 --- a/plugins/linktop/tests/test-modem-helpers-linktop.c +++ b/plugins/linktop/tests/test-modem-helpers-linktop.c @@ -60,7 +60,8 @@ test_cfun_query_current_modes (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/mbm/tests/test-modem-helpers-mbm.c b/plugins/mbm/tests/test-modem-helpers-mbm.c index cca121b0..e64b25c2 100644 --- a/plugins/mbm/tests/test-modem-helpers-mbm.c +++ b/plugins/mbm/tests/test-modem-helpers-mbm.c @@ -254,7 +254,8 @@ test_cfun_query_current_modes (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/sierra/tests/test-modem-helpers-sierra.c b/plugins/sierra/tests/test-modem-helpers-sierra.c index 629572e4..ad25ec9b 100644 --- a/plugins/sierra/tests/test-modem-helpers-sierra.c +++ b/plugins/sierra/tests/test-modem-helpers-sierra.c @@ -116,7 +116,8 @@ test_scact_read_response_multiple (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/simtech/tests/test-modem-helpers-simtech.c b/plugins/simtech/tests/test-modem-helpers-simtech.c index 78a8a590..af93b7ba 100644 --- a/plugins/simtech/tests/test-modem-helpers-simtech.c +++ b/plugins/simtech/tests/test-modem-helpers-simtech.c @@ -318,7 +318,8 @@ test_rxdtmf_urc_one_cr (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/telit/tests/test-mm-modem-helpers-telit.c b/plugins/telit/tests/test-mm-modem-helpers-telit.c index e6bff0bc..7561dac2 100644 --- a/plugins/telit/tests/test-mm-modem-helpers-telit.c +++ b/plugins/telit/tests/test-mm-modem-helpers-telit.c @@ -571,7 +571,8 @@ test_telit_parse_qss_query (void) /******************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/tests/test-keyfiles.c b/plugins/tests/test-keyfiles.c index 35ec4b46..173893be 100644 --- a/plugins/tests/test-keyfiles.c +++ b/plugins/tests/test-keyfiles.c @@ -65,7 +65,8 @@ test_foxconn_t77w968 (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/tests/test-udev-rules.c b/plugins/tests/test-udev-rules.c index 83ba95ba..e12f07ac 100644 --- a/plugins/tests/test-udev-rules.c +++ b/plugins/tests/test-udev-rules.c @@ -163,7 +163,8 @@ test_fibocom (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c index dcd4ab24..a3e5f65f 100644 --- a/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c +++ b/plugins/thuraya/tests/test-mm-modem-helpers-thuraya.c @@ -86,7 +86,8 @@ test_cpms_response_thuraya (void *f, gpointer d) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/ublox/tests/test-modem-helpers-ublox.c b/plugins/ublox/tests/test-modem-helpers-ublox.c index 17a46417..8f2f3664 100644 --- a/plugins/ublox/tests/test-modem-helpers-ublox.c +++ b/plugins/ublox/tests/test-modem-helpers-ublox.c @@ -980,7 +980,8 @@ test_ugcntrd_response (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/plugins/xmm/tests/test-modem-helpers-xmm.c b/plugins/xmm/tests/test-modem-helpers-xmm.c index b4a8b2b5..0e65c7cc 100644 --- a/plugins/xmm/tests/test-modem-helpers-xmm.c +++ b/plugins/xmm/tests/test-modem-helpers-xmm.c @@ -754,7 +754,8 @@ test_xlcsslp_queries (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/Makefile.am b/src/Makefile.am index 84c810d6..cb50d2b8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -97,6 +97,10 @@ mm-helper-enums-types.c: Makefile.am $(top_srcdir)/build-aux/mm-enums-template.c $(HELPER_ENUMS_INPUTS) > $@ libhelpers_la_SOURCES = \ + mm-log-object.h \ + mm-log-object.c \ + mm-log.c \ + mm-log.h \ mm-error-helpers.c \ mm-error-helpers.h \ mm-modem-helpers.c \ @@ -131,7 +135,6 @@ endif BUILT_SOURCES += $(HELPER_ENUMS_GENERATED) CLEANFILES += $(HELPER_ENUMS_GENERATED) - ################################################################################ # kerneldevice library ################################################################################ @@ -160,6 +163,7 @@ endif libkerneldevice_la_LIBADD = \ $(top_builddir)/libmm-glib/libmm-glib.la \ + $(builddir)/libhelpers.la \ $(NULL) ################################################################################ @@ -225,7 +229,6 @@ endif libport_la_LIBADD = \ $(top_builddir)/libqcdm/src/libqcdm.la \ $(top_builddir)/libmm-glib/libmm-glib.la \ - $(builddir)/libhelpers.la \ $(builddir)/libkerneldevice.la \ $(NULL) @@ -283,8 +286,6 @@ ModemManager_SOURCES = \ main.c \ mm-context.h \ mm-context.c \ - mm-log.c \ - mm-log.h \ mm-utils.h \ mm-private-boxed-types.h \ mm-private-boxed-types.c \ diff --git a/src/mm-log-object.c b/src/mm-log-object.c new file mode 100644 index 00000000..ed41355f --- /dev/null +++ b/src/mm-log-object.c @@ -0,0 +1,89 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado <aleksander@aleksander.es> + */ + +#include "mm-log-object.h" + +G_DEFINE_INTERFACE (MMLogObject, mm_log_object, G_TYPE_OBJECT) + +/*****************************************************************************/ +/* Private data context */ + +#define PRIVATE_TAG "log-object" +static GQuark private_quark; + +typedef struct { + gchar *owner_id; + gchar *id; +} Private; + +static void +private_free (Private *priv) +{ + g_free (priv->owner_id); + g_free (priv->id); + g_slice_free (Private, priv); +} + +static Private * +get_private (MMLogObject *self) +{ + Private *priv; + + if (G_UNLIKELY (!private_quark)) + private_quark = g_quark_from_static_string (PRIVATE_TAG); + + priv = g_object_get_qdata (G_OBJECT (self), private_quark); + if (!priv) { + priv = g_slice_new0 (Private); + g_object_set_qdata_full (G_OBJECT (self), private_quark, priv, (GDestroyNotify)private_free); + } + + return priv; +} + +const gchar * +mm_log_object_get_id (MMLogObject *self) +{ + Private *priv; + + priv = get_private (self); + if (!priv->id) { + gchar *self_id; + + self_id = MM_LOG_OBJECT_GET_IFACE (self)->build_id (self); + if (priv->owner_id) { + priv->id = g_strdup_printf ("%s/%s", priv->owner_id, self_id); + g_free (self_id); + } else + priv->id = self_id; + } + return priv->id; +} + +void +mm_log_object_set_owner_id (MMLogObject *self, + const gchar *owner_id) +{ + Private *priv; + + priv = get_private (self); + g_free (priv->owner_id); + priv->owner_id = g_strdup (owner_id); +} + +static void +mm_log_object_default_init (MMLogObjectInterface *iface) +{ +} diff --git a/src/mm-log-object.h b/src/mm-log-object.h new file mode 100644 index 00000000..21ffc05e --- /dev/null +++ b/src/mm-log-object.h @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details: + * + * Copyright (C) 2020 Aleksander Morgado <aleksander@aleksander.es> + */ + +#ifndef MM_LOG_OBJECT_H +#define MM_LOG_OBJECT_H + +#include <glib.h> +#include <glib-object.h> + +#include "mm-log.h" + +#define MM_TYPE_LOG_OBJECT mm_log_object_get_type () +G_DECLARE_INTERFACE (MMLogObject, mm_log_object, MM, LOG_OBJECT, GObject) + +struct _MMLogObjectInterface +{ + GTypeInterface g_iface; + + gchar * (* build_id) (MMLogObject *self); +}; + +const gchar *mm_log_object_get_id (MMLogObject *self); +void mm_log_object_set_owner_id (MMLogObject *self, + const gchar *owner_id); + +#endif /* MM_LOG_OBJECT_H */ diff --git a/src/mm-log.c b/src/mm-log.c index 470f1881..f15ce5c9 100644 --- a/src/mm-log.c +++ b/src/mm-log.c @@ -10,7 +10,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2011-2020 Red Hat, Inc. + * Copyright (C) 2020 Aleksander Morgado <aleksander@aleksander.es> */ #define _GNU_SOURCE @@ -41,6 +42,7 @@ #endif #include "mm-log.h" +#include "mm-log-object.h" enum { TS_FLAG_NONE = 0, @@ -200,7 +202,8 @@ log_backend_systemd_journal (const char *loc, #endif void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, MMLogLevel level, const char *fmt, @@ -243,6 +246,9 @@ _mm_log (const char *loc, g_string_append_printf (msgbuf, "[%s] %s(): ", loc, func); #endif + if (obj) + g_string_append_printf (msgbuf, "[%s] ", mm_log_object_get_id (MM_LOG_OBJECT (obj))); + va_start (args, fmt); g_string_append_vprintf (msgbuf, fmt, args); va_end (args); diff --git a/src/mm-log.h b/src/mm-log.h index d9f11f27..934b41c2 100644 --- a/src/mm-log.h +++ b/src/mm-log.h @@ -10,7 +10,8 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details: * - * Copyright (C) 2011 Red Hat, Inc. + * Copyright (C) 2011-2020 Red Hat, Inc. + * Copyright (C) 2020 Aleksander Morgado <aleksander@aleksander.es> */ #ifndef MM_LOG_H @@ -26,26 +27,22 @@ typedef enum { MM_LOG_LEVEL_DEBUG = 0x00000008 } MMLogLevel; -#define mm_err(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_ERR, ## __VA_ARGS__ ) +#define mm_obj_err(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_ERR, ## __VA_ARGS__ ) +#define mm_obj_warn(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_WARN, ## __VA_ARGS__ ) +#define mm_obj_info(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_INFO, ## __VA_ARGS__ ) +#define mm_obj_dbg(obj, ...) _mm_log (obj, G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_DEBUG, ## __VA_ARGS__ ) -#define mm_warn(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_WARN, ## __VA_ARGS__ ) +#define mm_err(...) mm_obj_err (NULL, ## __VA_ARGS__ ) +#define mm_warn(...) mm_obj_warn (NULL, ## __VA_ARGS__ ) +#define mm_info(...) mm_obj_info (NULL, ## __VA_ARGS__ ) +#define mm_dbg(...) mm_obj_dbg (NULL, ## __VA_ARGS__ ) -#define mm_info(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_INFO, ## __VA_ARGS__ ) - -#define mm_dbg(...) \ - _mm_log (G_STRLOC, G_STRFUNC, MM_LOG_LEVEL_DEBUG, ## __VA_ARGS__ ) - -#define mm_log(level, ...) \ - _mm_log (G_STRLOC, G_STRFUNC, level, ## __VA_ARGS__ ) - -void _mm_log (const char *loc, +void _mm_log (gpointer obj, + const char *loc, const char *func, MMLogLevel level, const char *fmt, - ...) __attribute__((__format__ (__printf__, 4, 5))); + ...) __attribute__((__format__ (__printf__, 5, 6))); gboolean mm_log_set_level (const char *level, GError **error); diff --git a/src/tests/test-at-serial-port.c b/src/tests/test-at-serial-port.c index c864701f..2d57d30e 100644 --- a/src/tests/test-at-serial-port.c +++ b/src/tests/test-at-serial-port.c @@ -65,7 +65,8 @@ at_serial_echo_removal (void) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c index 01a5b7a7..b8a92575 100644 --- a/src/tests/test-charsets.c +++ b/src/tests/test-charsets.c @@ -409,7 +409,8 @@ test_charset_can_covert_to (void) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-error-helpers.c b/src/tests/test-error-helpers.c index 228dfc02..ff67ed80 100644 --- a/src/tests/test-error-helpers.c +++ b/src/tests/test-error-helpers.c @@ -53,7 +53,8 @@ TEST_ERROR_HELPER (MESSAGE_ERROR, message_error, MessageError) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-modem-helpers-qmi.c b/src/tests/test-modem-helpers-qmi.c index d6b491c5..e14a2282 100644 --- a/src/tests/test-modem-helpers-qmi.c +++ b/src/tests/test-modem-helpers-qmi.c @@ -310,7 +310,8 @@ test_gobi3k_cdma (void) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index bd747448..551603df 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -4502,7 +4502,8 @@ test_bcd_to_string (void *f, gpointer d) /*****************************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-qcdm-serial-port.c b/src/tests/test-qcdm-serial-port.c index c5233f9c..db20f9aa 100644 --- a/src/tests/test-qcdm-serial-port.c +++ b/src/tests/test-qcdm-serial-port.c @@ -438,7 +438,8 @@ test_pty_cleanup (TestData *d) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-sms-part-3gpp.c b/src/tests/test-sms-part-3gpp.c index d9152405..a2ad304e 100644 --- a/src/tests/test-sms-part-3gpp.c +++ b/src/tests/test-sms-part-3gpp.c @@ -841,7 +841,8 @@ test_text_split_two_pdu_ucs2 (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-sms-part-cdma.c b/src/tests/test-sms-part-cdma.c index e1559261..b1900fa8 100644 --- a/src/tests/test-sms-part-cdma.c +++ b/src/tests/test-sms-part-cdma.c @@ -505,7 +505,8 @@ test_create_pdu_text_unicode_encoding (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/src/tests/test-udev-rules.c b/src/tests/test-udev-rules.c index 3398e419..cc594918 100644 --- a/src/tests/test-udev-rules.c +++ b/src/tests/test-udev-rules.c @@ -44,7 +44,8 @@ test_load_cleanup_core (void) /************************************************************/ void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/test/mmrules.c b/test/mmrules.c index 17976d25..29b32fba 100644 --- a/test/mmrules.c +++ b/test/mmrules.c @@ -51,7 +51,8 @@ static GOptionEntry main_entries[] = { }; void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/test/mmsmspdu.c b/test/mmsmspdu.c index c5e9693d..787f98f5 100644 --- a/test/mmsmspdu.c +++ b/test/mmsmspdu.c @@ -164,7 +164,8 @@ show_part_info (MMSmsPart *part) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, diff --git a/test/mmtty.c b/test/mmtty.c index 966225c7..f7852cd4 100644 --- a/test/mmtty.c +++ b/test/mmtty.c @@ -84,7 +84,8 @@ signals_handler (int signum) } void -_mm_log (const char *loc, +_mm_log (gpointer obj, + const char *loc, const char *func, guint32 level, const char *fmt, |