]> git.draconx.ca Git - upkg.git/commitdiff
uobject: Make logging more generic.
authorNick Bowler <nbowler@draconx.ca>
Sun, 20 May 2012 19:54:24 +0000 (15:54 -0400)
committerNick Bowler <nbowler@draconx.ca>
Sun, 20 May 2012 19:54:24 +0000 (15:54 -0400)
The logging functions can now be used on any GObject, not just UObject
subclasses.  In particular, it should be possible to call it on UPkg
instances which do not derive from UObject.

src/uobject/uobject.c

index 331b8ae096a487673e48da8ac66ed9808ececeda..360dd31d2614e586b96d0250983a1b196b9f3fe7 100644 (file)
@@ -612,18 +612,20 @@ static char *prepend_fmt(const char *prefix, const char *fmt)
 /* Logging helpers that automatically prepend the UObject class information. */
 void u_vlog_full(GObject *o, GLogLevelFlags level, const char *fmt, va_list ap)
 {
-       g_return_if_fail(IS_U_OBJECT(o));
-       UObject *uo = U_OBJECT(o);
-       char *new_fmt = NULL;
-
-       if (uo->pkg_name) {
-               new_fmt = prepend_fmt(uo->pkg_name, fmt);
-               if (!new_fmt) {
-                       g_log(G_OBJECT_TYPE_NAME(o), level, "%s",
-                             uo->pkg_file->name);
-               } else {
+       char *new_fmt = NULL, *obj_prefix = NULL;
+
+       if (IS_U_OBJECT(o)) {
+               obj_prefix = U_OBJECT(o)->pkg_name;
+       } else if (G_IS_TYPE_MODULE(o)) {
+               obj_prefix = G_TYPE_MODULE(o)->name;
+       }
+
+       if (obj_prefix) {
+               new_fmt = prepend_fmt(obj_prefix, fmt);
+               if (!new_fmt)
+                       g_log(G_OBJECT_TYPE_NAME(o), level, "%s", obj_prefix);
+               else
                        fmt = new_fmt;
-               }
        }
 
        g_logv(G_OBJECT_TYPE_NAME(o), level, fmt, ap);