log: new object logging support

So that we can provide the specific object id in every log associated
to a given object.
This commit is contained in:
Aleksander Morgado
2020-03-28 08:06:41 +01:00
parent faccb3b2b4
commit 9bcadea172
30 changed files with 203 additions and 47 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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 \

89
src/mm-log-object.c Normal file
View File

@@ -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)
{
}

38
src/mm-log-object.h Normal file
View File

@@ -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 */

View File

@@ -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);

View File

@@ -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);

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,