← Back to team overview

ubuntu-multiseat team mailing list archive

[Merge] lp:~ubuntu-multiseat/lightdm/multiseat-logging into lp:lightdm

 

Thomi Richards has proposed merging lp:~ubuntu-multiseat/lightdm/multiseat-logging into lp:lightdm.

Commit message:
Extend logging to make it easier to troubleshoot multiseat setups.

Requested reviews:
  Thomi Richards (thomir)
  PS Jenkins bot (ps-jenkins): continuous-integration
  Robert Ancell (robert-ancell)

For more details, see:
https://code.launchpad.net/~ubuntu-multiseat/lightdm/multiseat-logging/+merge/180753

Extend logging to make it easier to troubleshoot multiseat setups

  * include seat name in Seat log messages
  * include display server name in DisplayServer log messages
  * include PID in Session log messages
  * log the values of the XDG_SEAT and XDG_VTNR PAM variables
-- 
https://code.launchpad.net/~ubuntu-multiseat/lightdm/multiseat-logging/+merge/180753
Your team Ubuntu Multiseat is subscribed to branch lp:~ubuntu-multiseat/lightdm/multiseat-logging.
=== modified file 'src/Makefile.am'
--- src/Makefile.am	2013-07-24 23:53:37 +0000
+++ src/Makefile.am	2013-08-18 23:34:47 +0000
@@ -18,6 +18,8 @@
 	guest-account.c \
 	guest-account.h \
 	lightdm.c \
+	logger.c \
+	logger.h \
 	login1.c \
 	login1.h \
 	mir-server.c \

=== modified file 'src/display-server.c'
--- src/display-server.c	2013-07-26 04:50:35 +0000
+++ src/display-server.c	2013-08-18 23:34:47 +0000
@@ -32,7 +32,11 @@
     gboolean stopped;
 };
 
-G_DEFINE_TYPE (DisplayServer, display_server, G_TYPE_OBJECT);
+static void display_server_logger_iface_init (LoggerInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (DisplayServer, display_server, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (
+                             LOGGER_TYPE, display_server_logger_iface_init));
 
 void
 display_server_set_name (DisplayServer *server, const gchar *name)
@@ -176,3 +180,20 @@
                       NULL,
                       G_TYPE_NONE, 0);
 }
+
+static gint
+display_server_real_logprefix (Logger *self, gchar *buf, gulong buflen)
+{
+    DisplayServer *server = DISPLAY_SERVER (self);
+    const gchar *name = display_server_get_name (server);
+    if (name)
+        return g_snprintf (buf, buflen, "DisplayServer %s: ", name);
+    else
+        return g_snprintf (buf, buflen, "DisplayServer: ");
+}
+
+static void
+display_server_logger_iface_init (LoggerInterface *iface)
+{
+    iface->logprefix = &display_server_real_logprefix;
+}

=== modified file 'src/display-server.h'
--- src/display-server.h	2013-07-26 02:54:55 +0000
+++ src/display-server.h	2013-08-18 23:34:47 +0000
@@ -16,6 +16,7 @@
 
 typedef struct DisplayServer DisplayServer;
 
+#include "logger.h"
 #include "session.h"
 
 G_BEGIN_DECLS

=== modified file 'src/greeter.c'
--- src/greeter.c	2013-07-24 23:53:37 +0000
+++ src/greeter.c	2013-08-18 23:34:47 +0000
@@ -164,7 +164,7 @@
 
     g_io_channel_write_chars (greeter->priv->to_greeter_channel, (gchar *) message, message_length, NULL, &error);
     if (error)
-        g_warning ("Error writing to greeter: %s", error->message);
+        l_warning (greeter, "Error writing to greeter: %s", error->message);
     g_clear_error (&error);
     g_io_channel_flush (greeter->priv->to_greeter_channel, NULL);
 }
@@ -225,7 +225,7 @@
     GHashTableIter iter;
     gpointer key, value;
 
-    g_debug ("Greeter connected version=%s", version);
+    l_debug (greeter, "Greeter connected version=%s", version);
 
     length = string_length (VERSION);
     g_hash_table_iter_init (&iter, greeter->priv->hints);
@@ -260,7 +260,7 @@
     messages_length = session_get_messages_length (session);
 
     /* Respond to d-bus query with messages */
-    g_debug ("Prompt greeter with %d message(s)", messages_length);
+    l_debug (greeter, "Prompt greeter with %d message(s)", messages_length);
     size = int_length () + string_length (session_get_username (session)) + int_length ();
     for (i = 0; i < messages_length; i++)
         size += int_length () + string_length (messages[i].msg);
@@ -308,16 +308,16 @@
 {
     int result;
 
-    g_debug ("Authenticate result for user %s: %s", session_get_username (session), session_get_authentication_result_string (session));
+    l_debug (greeter, "Authenticate result for user %s: %s", session_get_username (session), session_get_authentication_result_string (session));
 
     result = session_get_authentication_result (session);
     if (session_get_is_authenticated (session))
     {
         if (session_get_user (session))
-            g_debug ("User %s authorized", session_get_username (session));
+            l_debug (greeter, "User %s authorized", session_get_username (session));
         else
         {
-            g_debug ("User %s authorized, but no account of that name exists", session_get_username (session));          
+            l_debug (greeter, "User %s authorized, but no account of that name exists", session_get_username (session));
             result = PAM_USER_UNKNOWN;
         }
     }
@@ -349,11 +349,11 @@
 
     if (username[0] == '\0')
     {
-        g_debug ("Greeter start authentication");
+        l_debug (greeter, "Greeter start authentication");
         username = NULL;
     }
     else
-        g_debug ("Greeter start authentication for %s", username);
+        l_debug (greeter, "Greeter start authentication for %s", username);
 
     reset_session (greeter);
 
@@ -392,13 +392,13 @@
 static void
 handle_login_as_guest (Greeter *greeter, guint32 sequence_number)
 {
-    g_debug ("Greeter start authentication for guest account");
+    l_debug (greeter, "Greeter start authentication for guest account");
 
     reset_session (greeter);
 
     if (!greeter->priv->allow_guest)
     {
-        g_debug ("Guest account is disabled");
+        l_debug (greeter, "Guest account is disabled");
         send_end_authentication (greeter, sequence_number, "", PAM_USER_UNKNOWN);
         return;
     }
@@ -449,11 +449,11 @@
 
     if (username[0] == '\0')
     {
-        g_debug ("Greeter start authentication for remote session %s", session_name);
+        l_debug (greeter, "Greeter start authentication for remote session %s", session_name);
         username = NULL;
     }
     else
-        g_debug ("Greeter start authentication for remote session %s as user %s", session_name, username);
+        l_debug (greeter, "Greeter start authentication for remote session %s as user %s", session_name, username);
 
     reset_session (greeter);
 
@@ -518,7 +518,7 @@
         return;
     }
 
-    g_debug ("Continue authentication");
+    l_debug (greeter, "Continue authentication");
 
     /* Build response */
     response = calloc (messages_length, sizeof (struct pam_response));
@@ -548,7 +548,7 @@
     if (greeter->priv->authentication_session == NULL)
         return;
 
-    g_debug ("Cancel authentication");
+    l_debug (greeter, "Cancel authentication");
     reset_session (greeter);
 }
 
@@ -573,15 +573,15 @@
     if (greeter->priv->guest_account_authenticated || session_get_is_authenticated (greeter->priv->authentication_session))
     {
         if (session)
-            g_debug ("Greeter requests session %s", session);
+            l_debug (greeter, "Greeter requests session %s", session);
         else
-            g_debug ("Greeter requests default session");
+            l_debug (greeter, "Greeter requests default session");
         greeter->priv->start_session = TRUE;
         g_signal_emit (greeter, signals[START_SESSION], 0, session_type, session, &result);
     }
     else
     {
-        g_debug ("Ignoring start session request, user is not authorized");
+        l_debug (greeter, "Ignoring start session request, user is not authorized");
         result = FALSE;
     }
 
@@ -597,18 +597,18 @@
 
     if (!greeter->priv->guest_account_authenticated && !session_get_is_authenticated (greeter->priv->authentication_session))
     {
-        g_debug ("Ignoring set language request, user is not authorized");
+        l_debug (greeter, "Ignoring set language request, user is not authorized");
         return;
     }
 
     // FIXME: Could use this
     if (greeter->priv->guest_account_authenticated)
     {
-        g_debug ("Ignoring set language request for guest user");
+        l_debug (greeter, "Ignoring set language request for guest user");
         return;
     }
 
-    g_debug ("Greeter sets language %s", language);
+    l_debug (greeter, "Greeter sets language %s", language);
     user = session_get_user (greeter->priv->authentication_session);
     user_set_language (user, language);
 }
@@ -620,7 +620,7 @@
     guint8 *buffer;
     if (greeter->priv->n_read - *offset < sizeof (guint32))
     {
-        g_warning ("Not enough space for int, need %zu, got %zu", sizeof (guint32), greeter->priv->n_read - *offset);
+        l_warning (greeter, "Not enough space for int, need %zu, got %zu", sizeof (guint32), greeter->priv->n_read - *offset);
         return 0;
     }
     buffer = greeter->priv->read_buffer + *offset;
@@ -640,7 +640,7 @@
 
     if (HEADER_SIZE + payload_length < HEADER_SIZE)
     {
-        g_warning ("Payload length of %u octets too long", payload_length);
+        l_warning (greeter, "Payload length of %u octets too long", payload_length);
         return HEADER_SIZE;
     }
 
@@ -656,7 +656,7 @@
     length = read_int (greeter, offset);
     if (greeter->priv->n_read - *offset < length)
     {
-        g_warning ("Not enough space for string, need %u, got %zu", length, greeter->priv->n_read - *offset);
+        l_warning (greeter, "Not enough space for string, need %u, got %zu", length, greeter->priv->n_read - *offset);
         return g_strdup ("");
     }
 
@@ -697,7 +697,7 @@
 
     if (condition == G_IO_HUP)
     {
-        g_debug ("Greeter closed communication channel");
+        l_debug (greeter, "Greeter closed communication channel");
         return FALSE;
     }
   
@@ -715,7 +715,7 @@
                                       &n_read,
                                       &error);
     if (error)
-        g_warning ("Error reading from greeter: %s", error->message);
+        l_warning (greeter, "Error reading from greeter: %s", error->message);
     g_clear_error (&error);
     if (status != G_IO_STATUS_NORMAL)
         return TRUE;
@@ -767,7 +767,7 @@
         max_secrets = (G_MAXUINT32 - 1) / sizeof (gchar *);
         if (n_secrets > max_secrets)
         {
-            g_warning ("Array length of %u elements too long", n_secrets);
+            l_warning (greeter, "Array length of %u elements too long", n_secrets);
             return FALSE;
         }
         secrets = g_malloc (sizeof (gchar *) * (n_secrets + 1));
@@ -793,7 +793,7 @@
         g_free (language);
         break;
     default:
-        g_warning ("Unknown message from greeter: %d", id);
+        l_warning (greeter, "Unknown message from greeter: %d", id);
         break;
     }
 

=== modified file 'src/lightdm.c'
--- src/lightdm.c	2013-07-24 03:02:30 +0000
+++ src/lightdm.c	2013-08-18 23:34:47 +0000
@@ -1168,8 +1168,9 @@
         gchar *config_section = *i;
         gchar *type;
         Seat *seat;
+        const gchar *const seatpfx = "Seat:";
 
-        if (!g_str_has_prefix (config_section, "Seat:"))
+        if (!g_str_has_prefix (config_section, seatpfx))
             continue;
 
         g_debug ("Loading seat %s", config_section);
@@ -1180,6 +1181,11 @@
         g_free (type);
         if (seat)
         {
+            const gsize seatpfxlen = strlen(seatpfx);
+            gchar *seatname = config_section + seatpfxlen;
+
+            seat_set_property (seat, "seat-name", seatname);
+
             set_seat_properties (seat, config_section);
             display_manager_add_seat (display_manager, seat);
             g_object_unref (seat);

=== added file 'src/logger.c'
--- src/logger.c	1970-01-01 00:00:00 +0000
+++ src/logger.c	2013-08-18 23:34:47 +0000
@@ -0,0 +1,81 @@
+#include "logger.h"
+
+G_DEFINE_INTERFACE (Logger, logger, G_TYPE_INVALID);
+
+static void
+logger_logv_default (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap);
+
+static void
+logger_default_init (LoggerInterface *iface)
+{
+    iface->logv = &logger_logv_default;
+}
+
+gint
+logger_logprefix (Logger *self, gchar *buf, gulong buflen)
+{
+    g_return_val_if_fail (IS_LOGGER (self), -1);
+    return LOGGER_GET_INTERFACE (self)->logprefix (self, buf, buflen);
+}
+
+void
+logger_logv (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap)
+{
+    g_return_if_fail (IS_LOGGER (self));
+    LOGGER_GET_INTERFACE (self)->logv (self, log_level, format, ap);
+}
+
+void
+logger_logv_default (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap)
+{
+    va_list ap_copy;
+    gint tmp;
+
+    /* figure out how long the prefix is */
+    tmp = logger_logprefix (self, NULL, 0);
+    if (tmp < 0)
+    {
+        g_error ("failed to get log prefix");
+        return;
+    }
+
+    /* print the prefix to a variable length array (to avoid malloc) */
+    gchar pfx[tmp + 1];
+    tmp = logger_logprefix (self, pfx, sizeof(pfx));
+    if (tmp < 0)
+    {
+        g_error ("failed to get log prefix");
+        return;
+    }
+
+    /* figure out how long the formatted message is */
+    va_copy (ap_copy, ap);
+    tmp = g_vsnprintf (NULL, 0, format, ap_copy);
+    va_end (ap_copy);
+    if (tmp < 0)
+    {
+        g_error ("failed to format log message");
+        return;
+    }
+
+    /* print the message to a variable length array (to avoid malloc) */
+    gchar msg[tmp+1];
+    tmp = g_vsnprintf (msg, sizeof(msg), format, ap);
+    if (tmp < 0)
+    {
+        g_error ("failed to format log message");
+        return;
+    }
+
+    /* log the message with the prefix */
+    g_log (G_LOG_DOMAIN, log_level, "%s%s", pfx, msg);
+}
+
+void
+logger_log (Logger *self, GLogLevelFlags log_level, const gchar *format, ...)
+{
+    va_list ap;
+    va_start (ap, format);
+    logger_logv (self, log_level, format, ap);
+    va_end (ap);
+}

=== added file 'src/logger.h'
--- src/logger.h	1970-01-01 00:00:00 +0000
+++ src/logger.h	2013-08-18 23:34:47 +0000
@@ -0,0 +1,60 @@
+#ifndef LOGGER_H_
+#define LOGGER_H_
+
+#include <glib-object.h>
+
+#ifdef __cplusplus
+#include <cstdarg>  /* for va_list */
+#else
+#include <stdarg.h>  /* for va_list */
+#endif
+
+G_BEGIN_DECLS
+
+#define LOGGER_TYPE (logger_get_type ())
+#define LOGGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LOGGER_TYPE, Logger))
+#define IS_LOGGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LOGGER_TYPE))
+#define LOGGER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), LOGGER_TYPE, LoggerInterface))
+
+typedef struct Logger Logger;
+
+typedef struct {
+    GTypeInterface parent;
+
+    gint (*logprefix) (Logger *self, gchar *buf, gulong buflen);
+    void (*logv) (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap);
+} LoggerInterface;
+
+GType logger_get_type (void);
+
+/*!
+ * \brief instruct \c self to generate a log message prefix
+ *
+ * the semantics of the \c buf and \c buflen arguments and the return
+ * value are the same as g_snprintf()
+ *
+ * there is no default implementation
+ */
+gint logger_logprefix (Logger *self, gchar *buf, gulong buflen);
+
+/*!
+ * \brief instruct \c self to log the given message
+ *
+ * the default implementation prefixes the log message with the
+ * output of logger_logprefix() and then passes the result to
+ * g_log()
+ */
+void logger_logv (Logger *self, GLogLevelFlags log_level, const gchar *format, va_list ap);
+
+/*! \brief convenience wrapper around \c logger_logv() */
+void logger_log (Logger *self, GLogLevelFlags log_level, const gchar *format, ...);
+
+/* convenience wrappers around logger_log() */
+#define l_debug(self, ...) \
+    logger_log (LOGGER (self), G_LOG_LEVEL_DEBUG, __VA_ARGS__)
+#define l_warning(self, ...) \
+    logger_log (LOGGER (self), G_LOG_LEVEL_WARNING, __VA_ARGS__)
+
+G_END_DECLS
+
+#endif /* !LOGGER_H_ */

=== modified file 'src/seat-unity.c'
--- src/seat-unity.c	2013-08-14 20:14:01 +0000
+++ src/seat-unity.c	2013-08-18 23:34:47 +0000
@@ -108,13 +108,13 @@
     /* If stopped before it was ready, then revert to VT mode */
     if (!seat->priv->compositor_ready)
     {
-        g_debug ("Compositor failed to start, switching to VT mode");
+        l_debug (seat, "Compositor failed to start, switching to VT mode");
         seat->priv->use_vt_switching = TRUE;
         SEAT_CLASS (seat_unity_parent_class)->start (SEAT (seat));
         return;
     }
 
-    g_debug ("Stopping Unity seat, compositor terminated");
+    l_debug (seat, "Stopping Unity seat, compositor terminated");
 
     seat_stop (SEAT (seat));
 }
@@ -136,7 +136,7 @@
 
          fd = g_open (seat->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
          if (fd < 0)
-             g_warning ("Failed to open log file %s: %s", seat->priv->log_file, g_strerror (errno));
+             l_warning (seat, "Failed to open log file %s: %s", seat->priv->log_file, g_strerror (errno));
          else
          {
              dup2 (fd, STDOUT_FILENO);
@@ -161,7 +161,7 @@
 
     errno = 0;
     if (write (seat->priv->to_compositor_pipe[1], data, data_length) != data_length)
-        g_warning ("Failed to write to compositor: %s", strerror (errno));
+        l_warning (seat, "Failed to write to compositor: %s", strerror (errno));
 }
 
 static gboolean
@@ -174,7 +174,7 @@
   
     if (condition == G_IO_HUP)
     {
-        g_debug ("Compositor closed communication channel");
+        l_debug (seat, "Compositor closed communication channel");
         return FALSE;
     }
 
@@ -204,7 +204,7 @@
                                           &n_read,
                                           &error);
         if (error)
-            g_warning ("Failed to read from compositor: %s", error->message);
+            l_warning (seat, "Failed to read from compositor: %s", error->message);
         if (status != G_IO_STATUS_NORMAL)
             return TRUE;
         g_clear_error (&error);
@@ -225,28 +225,28 @@
     switch (id)
     {
     case USC_MESSAGE_PING:
-        g_debug ("PING!");
+        l_debug (seat, "PING!");
         write_message (seat, USC_MESSAGE_PONG, NULL, 0);
         break;
     case USC_MESSAGE_PONG:
-        g_debug ("PONG!");
+        l_debug (seat, "PONG!");
         break;
     case USC_MESSAGE_READY:
-        g_debug ("READY");
+        l_debug (seat, "READY");
         if (!seat->priv->compositor_ready)
         {
             seat->priv->compositor_ready = TRUE;
-            g_debug ("Compositor ready");
+            l_debug (seat, "Compositor ready");
             g_source_remove (seat->priv->compositor_timeout);
             seat->priv->compositor_timeout = 0;
             SEAT_CLASS (seat_unity_parent_class)->start (SEAT (seat));
         }
         break;
     case USC_MESSAGE_SESSION_CONNECTED:
-        g_debug ("SESSION CONNECTED");
+        l_debug (seat, "SESSION CONNECTED");
         break;
     default:
-        g_warning ("Ingoring unknown message %d with %d octets from system compositor", id, payload_length);
+        l_warning (seat, "Ignoring unknown message %d with %d octets from system compositor", id, payload_length);
         break;
     }
 
@@ -310,7 +310,7 @@
             plymouth_quit (TRUE);
         }
         else
-            g_debug ("Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
+            l_debug (seat, "Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
     }
     if (plymouth_get_is_active ())
         plymouth_quit (FALSE);
@@ -318,7 +318,7 @@
         SEAT_UNITY (seat)->priv->vt = vt_get_unused ();
     if (SEAT_UNITY (seat)->priv->vt < 0)
     {
-        g_debug ("Failed to get a VT to run on");
+        l_debug (seat, "Failed to get a VT to run on");
         return FALSE;
     }
     vt_ref (SEAT_UNITY (seat)->priv->vt);
@@ -326,7 +326,7 @@
     /* Create pipes to talk to compositor */
     if (pipe (SEAT_UNITY (seat)->priv->to_compositor_pipe) < 0 || pipe (SEAT_UNITY (seat)->priv->from_compositor_pipe) < 0)
     {
-        g_debug ("Failed to create compositor pipes: %s", g_strerror (errno));
+        l_debug (seat, "Failed to create compositor pipes: %s", g_strerror (errno));
         return FALSE;
     }
 
@@ -341,7 +341,7 @@
     /* Setup logging */
     dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
     SEAT_UNITY (seat)->priv->log_file = g_build_filename (dir, "unity-system-compositor.log", NULL);
-    g_debug ("Logging to %s", SEAT_UNITY (seat)->priv->log_file);
+    l_debug (seat, "Logging to %s", SEAT_UNITY (seat)->priv->log_file);
     g_free (dir);
 
     SEAT_UNITY (seat)->priv->mir_socket_filename = g_strdup ("/tmp/mir_socket"); // FIXME: Use this socket by default as XMir is hardcoded to this
@@ -372,7 +372,7 @@
     timeout = seat_get_integer_property (seat, "unity-compositor-timeout");
     if (timeout <= 0)
         timeout = 60;
-    g_debug ("Waiting for system compositor for %ds", timeout);
+    l_debug (seat, "Waiting for system compositor for %ds", timeout);
     SEAT_UNITY (seat)->priv->compositor_timeout = g_timeout_add (timeout * 1000, compositor_timeout_cb, seat);
 
     return TRUE;
@@ -386,7 +386,7 @@
     gboolean allow_tcp;
     gint port = 0;
 
-    g_debug ("Starting X server on Unity compositor");
+    l_debug (seat, "Starting X server on Unity compositor");
 
     x_server = x_server_local_new ();
 
@@ -441,7 +441,7 @@
         keys = g_key_file_new ();
         result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
         if (error)
-            g_debug ("Error getting key %s", error->message);
+            l_debug (seat, "Error getting key %s", error->message);
         g_clear_error (&error);
 
         if (result)
@@ -451,7 +451,7 @@
             if (g_key_file_has_key (keys, "keyring", key_name, NULL))
                 key = g_key_file_get_string (keys, "keyring", key_name, NULL);
             else
-                g_debug ("Key %s not defined", key_name);
+                l_debug (seat, "Key %s not defined", key_name);
 
             if (key)
                 x_server_local_set_xdmcp_key (x_server, key);
@@ -498,7 +498,7 @@
         return create_mir_server (seat);
     else
     {
-        g_warning ("Can't create unsupported display server '%s'", session_type);
+        l_warning (seat, "Can't create unsupported display server '%s'", session_type);
         return NULL;
     }
 }
@@ -507,15 +507,21 @@
 seat_unity_create_greeter_session (Seat *seat)
 {
     Greeter *greeter_session;
+    const gchar *xdg_seat;
 
     greeter_session = SEAT_CLASS (seat_unity_parent_class)->create_greeter_session (seat);
-    session_set_env (SESSION (greeter_session), "XDG_SEAT", "seat0");
+    xdg_seat = "seat0";
+    l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
+    session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat);
     if (!SEAT_UNITY (seat)->priv->use_vt_switching)
     {
         gchar *value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt);
+        l_debug (seat, "Setting XDG_VTNR=%s", value);
         session_set_env (SESSION (greeter_session), "XDG_VTNR", value);
         g_free (value);
     }
+    else
+        l_debug (seat, "Not setting XDG_VTNR");
 
     return greeter_session;
 }
@@ -524,15 +530,21 @@
 seat_unity_create_session (Seat *seat)
 {
     Session *session;
+    const gchar *xdg_seat;
 
     session = SEAT_CLASS (seat_unity_parent_class)->create_session (seat);
-    session_set_env (session, "XDG_SEAT", "seat0");
+    xdg_seat = "seat0";
+    l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
+    session_set_env (session, "XDG_SEAT", xdg_seat);
     if (!SEAT_UNITY (seat)->priv->use_vt_switching)
     {
         gchar *value = g_strdup_printf ("%d", SEAT_UNITY (seat)->priv->vt);
+        l_debug (seat, "Setting XDG_VTNR=%s", value);
         session_set_env (SESSION (session), "XDG_VTNR", value);
         g_free (value);
     }
+    else
+        l_debug (seat, "Not setting XDG_VTNR");
 
     return session;
 }
@@ -571,11 +583,11 @@
 
         if (id)
         {
-            g_debug ("Switching to Mir session %s", id);
+            l_debug (seat, "Switching to Mir session %s", id);
             write_message (SEAT_UNITY (seat), USC_MESSAGE_SET_ACTIVE_SESSION, (const guint8 *) id, strlen (id));
         }
         else
-            g_warning ("Failed to work out session ID");
+            l_warning (seat, "Failed to work out session ID");
     }
 
     SEAT_CLASS (seat_unity_parent_class)->set_active_session (seat, session);

=== modified file 'src/seat-xlocal.c'
--- src/seat-xlocal.c	2013-07-26 04:52:07 +0000
+++ src/seat-xlocal.c	2013-08-18 23:34:47 +0000
@@ -69,9 +69,9 @@
     gint vt = -1, port = 0;
 
     if (vt > 0)
-        g_debug ("Starting local X display on VT %d", vt);
+        l_debug (seat, "Starting local X display on VT %d", vt);
     else
-        g_debug ("Starting local X display");
+        l_debug (seat, "Starting local X display");
   
     x_server = x_server_local_new ();
 
@@ -95,7 +95,7 @@
             plymouth_deactivate ();
         }
         else
-            g_debug ("Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
+            l_debug (seat, "Plymouth is running on VT %d, but this is less than the configured minimum of %d so not replacing it", active_vt, vt_get_min ());
     }
     if (plymouth_get_is_active ())
         plymouth_quit (FALSE);
@@ -138,7 +138,7 @@
         keys = g_key_file_new ();
         result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
         if (error)
-            g_debug ("Error getting key %s", error->message);
+            l_debug (seat, "Error getting key %s", error->message);
         g_clear_error (&error);      
 
         if (result)
@@ -148,7 +148,7 @@
             if (g_key_file_has_key (keys, "keyring", key_name, NULL))
                 key = g_key_file_get_string (keys, "keyring", key_name, NULL);
             else
-                g_debug ("Key %s not defined", key_name);
+                l_debug (seat, "Key %s not defined", key_name);
 
             if (key)
                 x_server_local_set_xdmcp_key (x_server, key);
@@ -166,9 +166,12 @@
 seat_xlocal_create_greeter_session (Seat *seat)
 {
     Greeter *greeter_session;
+    const gchar *xdg_seat;
 
     greeter_session = SEAT_CLASS (seat_xlocal_parent_class)->create_greeter_session (seat);
-    session_set_env (SESSION (greeter_session), "XDG_SEAT", "seat0");
+    xdg_seat = "seat0";
+    l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
+    session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat);
 
     return greeter_session;
 }
@@ -177,9 +180,12 @@
 seat_xlocal_create_session (Seat *seat)
 {
     Session *session;
+    const gchar *xdg_seat;
 
     session = SEAT_CLASS (seat_xlocal_parent_class)->create_session (seat);
-    session_set_env (SESSION (session), "XDG_SEAT", "seat0");
+    xdg_seat = "seat0";
+    l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
+    session_set_env (SESSION (session), "XDG_SEAT", xdg_seat);
 
     return session;
 }

=== modified file 'src/seat-xremote.c'
--- src/seat-xremote.c	2013-07-24 23:53:37 +0000
+++ src/seat-xremote.c	2013-08-18 23:34:47 +0000
@@ -33,7 +33,7 @@
 
     if (strcmp (session_type, "x") != 0)
     {
-        g_warning ("X remote seat only supports X display servers, not '%s'", session_type);
+        l_warning (seat, "X remote seat only supports X display servers, not '%s'", session_type);
         return NULL;
     }
 
@@ -42,7 +42,7 @@
         hostname = "localhost";
     number = seat_get_integer_property (seat, "xserver-display-number");
 
-    g_debug ("Starting remote X display %s:%d", hostname, number);
+    l_debug (seat, "Starting remote X display %s:%d", hostname, number);
 
     x_server = x_server_remote_new (hostname, number, NULL);
 
@@ -53,9 +53,12 @@
 seat_xremote_create_greeter_session (Seat *seat)
 {
     Greeter *greeter_session;
+    const gchar *xdg_seat;
 
     greeter_session = SEAT_CLASS (seat_xremote_parent_class)->create_greeter_session (seat);
-    session_set_env (SESSION (greeter_session), "XDG_SEAT", "seat0");
+    xdg_seat = "seat0";
+    l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
+    session_set_env (SESSION (greeter_session), "XDG_SEAT", xdg_seat);
 
     return greeter_session;
 }
@@ -64,9 +67,12 @@
 seat_xremote_create_session (Seat *seat)
 {
     Session *session;
+    const gchar *xdg_seat;
 
     session = SEAT_CLASS (seat_xremote_parent_class)->create_session (seat);
-    session_set_env (SESSION (session), "XDG_SEAT", "seat0");
+    xdg_seat = "seat0";
+    l_debug (seat, "Setting XDG_SEAT=%s", xdg_seat);
+    session_set_env (SESSION (session), "XDG_SEAT", xdg_seat);
 
     return session;
 }

=== modified file 'src/seat.c'
--- src/seat.c	2013-08-08 10:10:19 +0000
+++ src/seat.c	2013-08-18 23:34:47 +0000
@@ -66,7 +66,11 @@
 #define USER_SERVICE      "lightdm"
 #define AUTOLOGIN_SERVICE "lightdm-autologin"
 
-G_DEFINE_TYPE (Seat, seat, G_TYPE_OBJECT);
+static void seat_logger_iface_init (LoggerInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (Seat, seat, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (
+                             LOGGER_TYPE, seat_logger_iface_init));
 
 typedef struct
 {
@@ -198,7 +202,7 @@
 
         if (IS_GREETER (s))
         {
-            g_debug ("Stopping greeter");
+            l_debug (seat, "Stopping greeter");
             session_stop (s);
         }
     }
@@ -277,7 +281,7 @@
         exit_status = process_get_exit_status (script);
         if (WIFEXITED (exit_status))
         {
-            g_debug ("Exit status of %s: %d", script_name, WEXITSTATUS (exit_status));
+            l_debug (seat, "Exit status of %s: %d", script_name, WEXITSTATUS (exit_status));
             result = WEXITSTATUS (exit_status) == EXIT_SUCCESS;
         }
     }
@@ -315,7 +319,7 @@
         g_list_length (seat->priv->sessions) == 0)
     {
         seat->priv->stopped = TRUE;
-        g_debug ("Seat stopped");
+        l_debug (seat, "Stopped");
         g_signal_emit (seat, signals[STOPPED], 0);
     }
 }
@@ -332,7 +336,7 @@
     GList *list, *link;
     Session *active_session;
 
-    g_debug ("Display server stopped");
+    l_debug (seat, "Display server stopped");
 
     g_signal_handlers_disconnect_matched (display_server, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
     seat->priv->display_servers = g_list_remove (seat->priv->display_servers, display_server);
@@ -360,11 +364,11 @@
             !session_get_is_started (session) &&
             g_list_length (seat->priv->display_servers) == 0)
         {
-            g_debug ("Stopping seat, greeter display server failed to start");
+            l_debug (seat, "Stopping; greeter display server failed to start");
             seat_stop (seat);
         }
 
-        g_debug ("Stopping session");
+        l_debug (seat, "Stopping session");
         session_stop (session);
     }
     g_list_free_full (list, g_object_unref);
@@ -375,7 +379,7 @@
         active_session = seat_get_active_session (seat);
         if (!active_session || session_get_display_server (active_session) == display_server)
         {
-            g_debug ("Active display server stopped, starting greeter");
+            l_debug (seat, "Active display server stopped, starting greeter");
             seat_switch_to_greeter (seat);
         }
     }
@@ -412,7 +416,7 @@
         display_server = create_display_server (seat, session_get_session_type (session));
         if (!display_server_start (display_server))
         {
-            g_debug ("Failed to start display server for greeter");
+            l_debug (seat, "Failed to start display server for greeter");
             seat_stop (seat);
         }
 
@@ -447,12 +451,12 @@
 
     if (IS_GREETER (session))
     {
-        g_debug ("Failed to start greeter");
+        l_debug (seat, "Failed to start greeter");
         display_server_stop (session_get_display_server (session));
         return;
     }
 
-    g_debug ("Failed to start session, starting greeter");
+    l_debug (seat, "Failed to start session, starting greeter");
     switch_to_greeter_from_failed_session (seat, session);
 }
 
@@ -467,7 +471,7 @@
         script = seat_get_string_property (seat, "session-setup-script");
     if (script && !run_script (seat, session_get_display_server (session), script, NULL))
     {
-        g_debug ("Switching to greeter due to failed setup script");
+        l_debug (seat, "Switching to greeter due to failed setup script");
         switch_to_greeter_from_failed_session (seat, session);
         return;
     }
@@ -495,17 +499,17 @@
 {
     if (session_get_is_authenticated (session))
     {
-        g_debug ("Session authenticated, running command");
+        l_debug (seat, "Session authenticated, running command");
         run_session (seat, session);
     }
     else if (!IS_GREETER (session))
     {
-        g_debug ("Switching to greeter due to failed authentication");
+        l_debug (seat, "Switching to greeter due to failed authentication");
         switch_to_greeter_from_failed_session (seat, session);
     }
     else
     {
-        g_debug ("Stopping session that failed authentication");
+        l_debug (seat, "Stopping session that failed authentication");
         session_stop (session);
     }
 }
@@ -515,7 +519,7 @@
 {
     DisplayServer *display_server;
 
-    g_debug ("Session stopped");
+    l_debug (seat, "Session stopped");
 
     g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
     seat->priv->sessions = g_list_remove (seat->priv->sessions, session);
@@ -578,12 +582,12 @@
 
             if (session_get_is_authenticated (s))
             {
-                g_debug ("Greeter stopped, running session");
+                l_debug (seat, "Greeter stopped, running session");
                 run_session (seat, s);
             }
             else
             {
-                g_debug ("Greeter stopped, starting session authentication");
+                l_debug (seat, "Greeter stopped, starting session authentication");
                 start_session (seat, s);
             }
             break;
@@ -595,13 +599,13 @@
         g_list_length (seat->priv->display_servers) == 1 &&
         g_list_nth_data (seat->priv->display_servers, 0) == display_server)
     {
-        g_debug ("Stopping seat, failed to start a greeter");
+        l_debug (seat, "Stopping; failed to start a greeter");
         seat_stop (seat);
     }
     /* If we were the active session, switch to a greeter */
     else if (!IS_GREETER (session) && session == seat_get_active_session (seat))
     {
-        g_debug ("Active session stopped, starting greeter");
+        l_debug (seat, "Active session stopped, starting greeter");
         seat_switch_to_greeter (seat);
     }
 
@@ -621,7 +625,7 @@
         }
         if (n_sessions == 0)
         {
-            g_debug ("Stopping display server, no sessions require it");
+            l_debug (seat, "Stopping display server, no sessions require it");
             display_server_stop (display_server);
         }
     }
@@ -678,7 +682,7 @@
 }
 
 static gchar **
-get_session_argv (SessionConfig *session_config, const gchar *session_wrapper)
+get_session_argv (Seat *seat, SessionConfig *session_config, const gchar *session_wrapper)
 {
     gboolean result;
     int argc;
@@ -699,7 +703,7 @@
     /* Split command into an array listing and make command absolute */
     result = g_shell_parse_argv (session_config_get_command (session_config), &argc, &argv, &error);
     if (error)
-        g_debug ("Invalid session command '%s': %s", session_config_get_command (session_config), error->message);
+        l_debug (seat, "Invalid session command '%s': %s", session_config_get_command (session_config), error->message);
     g_clear_error (&error);
     if (!result)
         return NULL;
@@ -714,7 +718,7 @@
 }
 
 static SessionConfig *
-find_session_config (const gchar *sessions_dir, const gchar *session_name)
+find_session_config (Seat *seat, const gchar *sessions_dir, const gchar *session_name)
 {
     gchar **dirs;
     SessionConfig *session_config = NULL;
@@ -738,7 +742,7 @@
             break;
 
         if (dirs[i+1] == NULL)
-            g_debug ("Failed to find session configuration %s", session_name);
+            l_debug (seat, "Failed to find session configuration %s", session_name);
         g_clear_error (&error);
     }
     g_strfreev (dirs);
@@ -755,13 +759,13 @@
     SessionConfig *session_config;
     Session *session = NULL;
 
-    g_debug ("Creating user session");
+    l_debug (seat, "Creating user session");
 
     /* Load user preferences */
     user = accounts_get_user_by_name (username);
     if (!user)
     {
-        g_debug ("Can't login unknown user '%s'", username);
+        l_debug (seat, "Can't login unknown user '%s'", username);
         return NULL;
     }
     session_name = user_get_xsession (user);
@@ -770,7 +774,7 @@
     if (!session_name)
         session_name = seat_get_string_property (seat, "user-session");
     sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
-    session_config = find_session_config (sessions_dir, session_name);
+    session_config = find_session_config (seat, sessions_dir, session_name);
     g_free (sessions_dir);
     if (session_config)
     {
@@ -788,14 +792,14 @@
         session_set_pam_service (session, AUTOLOGIN_SERVICE);
         session_set_username (session, username);
         session_set_do_authenticate (session, TRUE);
-        argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
+        argv = get_session_argv (seat, session_config, seat_get_string_property (seat, "session-wrapper"));
         session_set_argv (session, argv);
         g_strfreev (argv);
 
         g_object_unref (session_config);
     }
     else
-        g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
+        l_debug (seat, "Can't find session '%s'", seat_get_string_property (seat, "user-session"));
 
 
     g_object_unref (user);
@@ -811,11 +815,11 @@
     Session *session;
 
     sessions_dir = config_get_string (config_get_instance (), "LightDM", "sessions-directory");
-    session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "user-session"));
+    session_config = find_session_config (seat, sessions_dir, seat_get_string_property (seat, "user-session"));
     g_free (sessions_dir);
     if (!session_config)
     {
-        g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
+        l_debug (seat, "Can't find session '%s'", seat_get_string_property (seat, "user-session"));
         return NULL;
     }
 
@@ -823,7 +827,7 @@
     session_set_session_type (session, session_config_get_session_type (session_config));
     session_set_do_authenticate (session, TRUE);
     session_set_is_guest (session, TRUE);
-    argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
+    argv = get_session_argv (seat, session_config, seat_get_string_property (seat, "session-wrapper"));
     g_object_unref (session_config);
     session_set_argv (session, argv);
     g_strfreev (argv);
@@ -911,7 +915,7 @@
     existing_session = find_user_session (seat, username);
     if (existing_session && session != existing_session)
     {
-        g_debug ("Returning to existing user session %s", username);
+        l_debug (seat, "Returning to existing user session %s", username);
         session_stop (session);
         seat_set_active_session (seat, existing_session);
         return TRUE;
@@ -942,16 +946,16 @@
     if (user)
         user_set_xsession (session_get_user (session), session_name);
 
-    session_config = find_session_config (sessions_dir, session_name);
+    session_config = find_session_config (seat, sessions_dir, session_name);
     g_free (sessions_dir);
     if (!session_config)
     {
-        g_debug ("Can't find session '%s'", seat_get_string_property (seat, "user-session"));
+        l_debug (seat, "Can't find session '%s'", seat_get_string_property (seat, "user-session"));
         return FALSE;
     }
 
     session_set_session_type (session, session_config_get_session_type (session_config));
-    argv = get_session_argv (session_config, seat_get_string_property (seat, "session-wrapper"));
+    argv = get_session_argv (seat, session_config, seat_get_string_property (seat, "session-wrapper"));
     session_set_argv (session, argv);
     g_strfreev (argv);
     session_set_env (session, "DESKTOP_SESSION", session_name);
@@ -969,7 +973,7 @@
     if (can_share_display_server (seat, display_server) &&
         strcmp (display_server_get_session_type (display_server), session_get_session_type (session)) == 0)
     {
-        g_debug ("Stopping greeter; display server will be re-used for user session");
+        l_debug (seat, "Stopping greeter; display server will be re-used for user session");
 
         /* Run on the same display server after the greeter has stopped */
         session_set_display_server (session, display_server);
@@ -986,7 +990,7 @@
         session_set_display_server (session, display_server);
         if (!display_server_start (display_server))
         {
-            g_debug ("Failed to start display server for new session");
+            l_debug (seat, "Failed to start display server for new session");
             return FALSE;
         }
 
@@ -1003,15 +1007,15 @@
     gchar *greeter_user;
     const gchar *greeter_wrapper;
 
-    g_debug ("Creating greeter session");
+    l_debug (seat, "Creating greeter session");
 
     sessions_dir = config_get_string (config_get_instance (), "LightDM", "greeters-directory");
-    session_config = find_session_config (sessions_dir, seat_get_string_property (seat, "greeter-session"));
+    session_config = find_session_config (seat, sessions_dir, seat_get_string_property (seat, "greeter-session"));
     g_free (sessions_dir);
     if (!session_config)
         return NULL;
 
-    argv = get_session_argv (session_config, NULL);
+    argv = get_session_argv (seat, session_config, NULL);
     greeter_wrapper = seat_get_string_property (seat, "greeter-wrapper");
     if (greeter_wrapper)
     {
@@ -1078,7 +1082,7 @@
     script = seat_get_string_property (seat, "display-setup-script");
     if (script && !run_script (seat, display_server, script, NULL))
     {
-        g_debug ("Stopping display server due to failed setup script");
+        l_debug (seat, "Stopping display server due to failed setup script");
         display_server_stop (display_server);
         return;
     }
@@ -1095,18 +1099,18 @@
     {
         if (session_get_is_authenticated (session))
         {
-            g_debug ("Display server ready, running session");
+            l_debug (seat, "Display server ready, running session");
             run_session (seat, session);
         }
         else
         {
-            g_debug ("Display server ready, starting session authentication");
+            l_debug (seat, "Display server ready, starting session authentication");
             start_session (seat, session);
         }
     }
     else
     {
-        g_debug ("Stopping not required display server");
+        l_debug (seat, "Stopping not required display server");
         display_server_stop (display_server);
     }
 }
@@ -1116,7 +1120,7 @@
 {
     DisplayServer *display_server;
 
-    g_debug ("Creating display server of type %s", session_type);
+    l_debug (seat, "Creating display server of type %s", session_type);
 
     display_server = SEAT_GET_CLASS (seat)->create_display_server (seat, session_type);
     if (!display_server)
@@ -1159,7 +1163,7 @@
     greeter_session = find_greeter_session (seat);
     if (greeter_session)
     {
-        g_debug ("Switching to existing greeter");
+        l_debug (seat, "Switching to existing greeter");
         seat_set_active_session (seat, SESSION (greeter_session));
         return TRUE;
     }
@@ -1189,12 +1193,12 @@
     if (!seat->priv->can_switch)
         return FALSE;
 
-    g_debug ("Switching to user %s", username);
+    l_debug (seat, "Switching to user %s", username);
 
     session = find_user_session (seat, username);
     if (session)
     {
-        g_debug ("Switching to existing user session %s", username);
+        l_debug (seat, "Switching to existing user session %s", username);
         seat_set_active_session (seat, session);
         return TRUE;
     }
@@ -1245,7 +1249,7 @@
     session = find_guest_session (seat);
     if (session)
     {
-        g_debug ("Switching to existing guest account %s", session_get_username (session));
+        l_debug (seat, "Switching to existing guest account %s", session_get_username (session));
         seat_set_active_session (seat, session);
         return TRUE;
     }
@@ -1278,13 +1282,13 @@
     if (!seat->priv->can_switch)
         return FALSE;
 
-    g_debug ("Locking seat");
+    l_debug (seat, "Locking");
 
     /* Switch to greeter if one open (shouldn't be though) */
     greeter_session = find_greeter_session (seat);
     if (greeter_session)
     {
-        g_debug ("Switching to existing greeter");
+        l_debug (seat, "Switching to existing greeter");
         seat_set_active_session (seat, SESSION (greeter_session));
         return TRUE;
     }
@@ -1316,7 +1320,7 @@
     if (seat->priv->stopping)
         return;
 
-    g_debug ("Stopping seat");
+    l_debug (seat, "Stopping");
     seat->priv->stopping = TRUE;
     SEAT_GET_CLASS (seat)->stop (seat);
 }
@@ -1348,7 +1352,7 @@
     gboolean autologin_in_background;
     Session *session = NULL, *background_session = NULL;
 
-    g_debug ("Starting seat");
+    l_debug (seat, "Starting");
 
     /* If this display server doesn't have a session running on it, just start it */
     if (!get_start_local_sessions (seat))
@@ -1396,7 +1400,7 @@
             session_set_display_server (session, display_server);
             if (!display_server || !display_server_start (display_server))
             {
-                g_debug ("Can't create display server for automatic login");
+                l_debug (seat, "Can't create display server for automatic login");
                 session_stop (session);
                 if (display_server)
                     display_server_stop (display_server);
@@ -1414,7 +1418,7 @@
         greeter_session = create_greeter_session (seat);
         if (!greeter_session)
         {
-            g_debug ("Failed to create greeter session");
+            l_debug (seat, "Failed to create greeter session");
             return FALSE;
         }
 
@@ -1440,7 +1444,7 @@
         session_set_display_server (session, display_server);
         if (!display_server || !display_server_start (display_server))
         {
-            g_debug ("Can't create display server for greeter");
+            l_debug (seat, "Can't create display server for greeter");
             session_stop (session);
             if (display_server)
                 display_server_stop (display_server);
@@ -1463,7 +1467,7 @@
         background_display_server = create_display_server (seat, session_get_session_type (background_session));
         session_set_display_server (background_session, background_display_server);
         if (!display_server_start (background_display_server))
-            g_warning ("Failed to start display server for background session");
+            l_warning (seat, "Failed to start display server for background session");
     }
 
     seat->priv->started = TRUE;
@@ -1512,7 +1516,7 @@
         DisplayServer *display_server = link->data;
         if (!display_server_get_is_stopping (display_server))
         {
-            g_debug ("Stopping display server");
+            l_debug (seat, "Stopping display server");
             display_server_stop (display_server);
         }
     }
@@ -1525,7 +1529,7 @@
         Session *session = link->data;
         if (!session_get_is_stopping (session))
         {
-            g_debug ("Stopping session");
+            l_debug (seat, "Stopping session");
             session_stop (session);
         }
     }
@@ -1621,3 +1625,20 @@
                       NULL,
                       G_TYPE_NONE, 0);
 }
+
+static gint
+seat_real_logprefix (Logger *self, gchar *buf, gulong buflen)
+{
+    Seat *seat = SEAT (self);
+    const gchar *name = seat_get_string_property (seat, "seat-name");
+    if (name)
+        return g_snprintf (buf, buflen, "Seat %s: ", name);
+    else
+        return g_snprintf (buf, buflen, "Seat: ");
+}
+
+static void
+seat_logger_iface_init (LoggerInterface *iface)
+{
+    iface->logprefix = &seat_real_logprefix;
+}

=== modified file 'src/seat.h'
--- src/seat.h	2013-07-25 23:40:02 +0000
+++ src/seat.h	2013-08-18 23:34:47 +0000
@@ -17,6 +17,7 @@
 #include "greeter.h"
 #include "session.h"
 #include "process.h"
+#include "logger.h"
 
 G_BEGIN_DECLS
 

=== modified file 'src/session.c'
--- src/session.c	2013-08-08 10:10:19 +0000
+++ src/session.c	2013-08-18 23:34:47 +0000
@@ -120,7 +120,11 @@
 /* Maximum length of a string to pass between daemon and session */
 #define MAX_STRING_LENGTH 65535
 
-G_DEFINE_TYPE (Session, session, G_TYPE_OBJECT);
+static void session_logger_iface_init (LoggerInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (Session, session, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (
+                             LOGGER_TYPE, session_logger_iface_init));
 
 Session *
 session_new (void)
@@ -338,7 +342,7 @@
 write_data (Session *session, const void *buf, size_t count)
 {
     if (write (session->priv->to_child_input, buf, count) != count)
-        g_warning ("Error writing to session: %s", strerror (errno));
+        l_warning (session, "Error writing to session: %s", strerror (errno));
 }
 
 static void
@@ -382,7 +386,7 @@
     ssize_t n_read;
     n_read = read (session->priv->from_child_output, buf, count);
     if (n_read < 0)
-        g_warning ("Error reading from session: %s", strerror (errno));
+        l_warning (session, "Error reading from session: %s", strerror (errno));
     return n_read;
 }
 
@@ -398,7 +402,7 @@
         return NULL;
     if (length > MAX_STRING_LENGTH)
     {
-        g_warning ("Invalid string length %d from child", length);
+        l_warning (session, "Invalid string length %d from child", length);
         return NULL;
     }
 
@@ -414,17 +418,18 @@
 {
     Session *session = data;
 
-    session->priv->pid = 0;
-
     if (WIFEXITED (status))
-        g_debug ("Session %d exited with return value %d", pid, WEXITSTATUS (status));
+        l_debug (session, "Exited with return value %d", WEXITSTATUS (status));
     else if (WIFSIGNALED (status))
-        g_debug ("Session %d terminated with signal %d", pid, WTERMSIG (status));
+        l_debug (session, "Terminated with signal %d", WTERMSIG (status));
+
+    /* do this as late as possible for log messages prefix */
+    session->priv->pid = 0;
 
     /* If failed during authentication then report this as an authentication failure */
     if (session->priv->authentication_started && !session->priv->authentication_complete)
     {
-        g_debug ("Session %d failed during authentication", pid);
+        l_debug (session, "Failed during authentication");
         session->priv->authentication_complete = TRUE;
         session->priv->authentication_result = PAM_CONV_ERR;
         g_free (session->priv->authentication_result_string);
@@ -473,7 +478,7 @@
     /* Check if authentication completed */
     n_read = read_from_child (session, &auth_complete, sizeof (auth_complete));
     if (n_read < 0)
-        g_debug ("Error reading from child: %s", strerror (errno));
+        l_debug (session, "Error reading from child: %s", strerror (errno));
     if (n_read <= 0)
     {
         session->priv->from_child_watch = 0;
@@ -487,7 +492,7 @@
         g_free (session->priv->authentication_result_string);
         session->priv->authentication_result_string = read_string_from_child (session);
 
-        g_debug ("Session %d authentication complete with return value %d: %s", session->priv->pid, session->priv->authentication_result, session->priv->authentication_result_string);
+        l_debug (session, "Authentication complete with return value %d: %s", session->priv->authentication_result, session->priv->authentication_result_string);
 
         /* No longer expect any more messages */
         session->priv->from_child_watch = 0;
@@ -510,7 +515,7 @@
             m->msg = read_string_from_child (session);
         }
 
-        g_debug ("Session %d got %d message(s) from PAM", session->priv->pid, session->priv->messages_length);
+        l_debug (session, "Got %d message(s) from PAM", session->priv->messages_length);
 
         g_signal_emit (G_OBJECT (session), signals[GOT_MESSAGES], 0);
     }
@@ -616,7 +621,7 @@
     write_string (session, session->priv->xdisplay);
     write_xauth (session, session->priv->x_authority);
 
-    g_debug ("Started session %d with service '%s', username '%s'", session->priv->pid, session->priv->pam_service, session->priv->username);
+    l_debug (session, "Started with service '%s', username '%s'", session->priv->pam_service, session->priv->username);
 
     return TRUE;
 }
@@ -727,7 +732,7 @@
     session->priv->command_run = TRUE;
 
     command = g_strjoinv (" ", session->priv->argv);
-    g_debug ("Session %d running command %s", session->priv->pid, command);
+    l_debug (session, "Running command %s", command);
     g_free (command);
 
     /* Create authority location */
@@ -740,11 +745,11 @@
         g_free (run_dir);
 
         if (g_mkdir_with_parents (dir, S_IRWXU) < 0)
-            g_warning ("Failed to set create system authority dir %s: %s", dir, strerror (errno));          
+            l_warning (session, "Failed to set create system authority dir %s: %s", dir, strerror (errno));
         if (getuid () == 0)
         {
             if (chown (dir, user_get_uid (session_get_user (session)), user_get_gid (session_get_user (session))) < 0)
-                g_warning ("Failed to set ownership of user authority dir: %s", strerror (errno));
+                l_warning (session, "Failed to set ownership of user authority dir: %s", strerror (errno));
         }
 
         x_authority_filename = g_build_filename (dir, "xauthority", NULL);
@@ -819,7 +824,7 @@
 
     if (session->priv->pid > 0)
     {
-        g_debug ("Session %d: Sending SIGTERM", session->priv->pid);
+        l_debug (session, "Sending SIGTERM");
         kill (session->priv->pid, SIGTERM);
         // FIXME: Handle timeout
     }
@@ -920,3 +925,19 @@
                       NULL,
                       G_TYPE_NONE, 0);
 }
+
+static gint
+session_real_logprefix (Logger *self, gchar *buf, gulong buflen)
+{
+    Session *session = SESSION (self);
+    if (session->priv->pid != 0)
+        return g_snprintf (buf, buflen, "Session pid=%d: ", session->priv->pid);
+    else
+        return g_snprintf (buf, buflen, "Session: ");
+}
+
+static void
+session_logger_iface_init (LoggerInterface *iface)
+{
+    iface->logprefix = &session_real_logprefix;
+}

=== modified file 'src/session.h'
--- src/session.h	2013-07-26 02:27:41 +0000
+++ src/session.h	2013-08-18 23:34:47 +0000
@@ -21,6 +21,7 @@
 #include "display-server.h"
 #include "accounts.h"
 #include "x-authority.h"
+#include "logger.h"
 
 G_BEGIN_DECLS
 

=== modified file 'src/x-server-local.c'
--- src/x-server-local.c	2013-07-26 01:23:05 +0000
+++ src/x-server-local.c	2013-08-18 23:34:47 +0000
@@ -333,7 +333,7 @@
 
          fd = g_open (server->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
          if (fd < 0)
-             g_warning ("Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno));
+             l_warning (server, "Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno));
          else
          {
              dup2 (fd, STDOUT_FILENO);
@@ -352,7 +352,7 @@
     if (signum == SIGUSR1 && !server->priv->got_signal)
     {
         server->priv->got_signal = TRUE;
-        g_debug ("Got signal from X server :%d", x_server_get_display_number (X_SERVER (server)));
+        l_debug (server, "Got signal from X server :%d", x_server_get_display_number (X_SERVER (server)));
 
         // FIXME: Check return value
         DISPLAY_SERVER_CLASS (x_server_local_parent_class)->start (DISPLAY_SERVER (server));
@@ -362,7 +362,7 @@
 static void
 stopped_cb (Process *process, XServerLocal *server)
 {
-    g_debug ("X server stopped");
+    l_debug (server, "X server stopped");
 
     /* Release VT and display number for re-use */
     if (server->priv->have_vt_ref)
@@ -374,7 +374,7 @@
   
     if (x_server_get_authority (X_SERVER (server)) && server->priv->authority_file)
     {
-        g_debug ("Removing X server authority %s", server->priv->authority_file);
+        l_debug (server, "Removing X server authority %s", server->priv->authority_file);
 
         g_unlink (server->priv->authority_file);
 
@@ -404,17 +404,17 @@
         dir = g_build_filename (run_dir, "root", NULL);
         g_free (run_dir);
         if (g_mkdir_with_parents (dir, S_IRWXU) < 0)
-            g_warning ("Failed to make authority directory %s: %s", dir, strerror (errno));
+            l_warning (server, "Failed to make authority directory %s: %s", dir, strerror (errno));
 
         server->priv->authority_file = g_build_filename (dir, x_server_get_address (X_SERVER (server)), NULL);
         g_free (dir);
     }
 
-    g_debug ("Writing X server authority to %s", server->priv->authority_file);
+    l_debug (server, "Writing X server authority to %s", server->priv->authority_file);
 
     x_authority_write (authority, XAUTH_WRITE_MODE_REPLACE, server->priv->authority_file, &error);
     if (error)
-        g_warning ("Failed to write authority: %s", error->message);
+        l_warning (server, "Failed to write authority: %s", error->message);
     g_clear_error (&error);
 }
 
@@ -442,14 +442,14 @@
     filename = g_strdup_printf ("%s.log", display_server_get_name (display_server));
     dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
     server->priv->log_file = g_build_filename (dir, filename, NULL);
-    g_debug ("Logging to %s", server->priv->log_file);
+    l_debug (display_server, "Logging to %s", server->priv->log_file);
     g_free (filename);
     g_free (dir);
 
     absolute_command = get_absolute_command (server->priv->command);
     if (!absolute_command)
     {
-        g_debug ("Can't launch X server %s, not found in path", server->priv->command);
+        l_debug (display_server, "Can't launch X server %s, not found in path", server->priv->command);
         stopped_cb (server->priv->x_server_process, X_SERVER_LOCAL (server));
         return FALSE;
     }
@@ -496,7 +496,7 @@
     process_set_command (server->priv->x_server_process, command->str);
     g_string_free (command, TRUE);
 
-    g_debug ("Launching X Server");
+    l_debug (display_server, "Launching X Server");
 
     /* If running inside another display then pass through those variables */
     if (g_getenv ("DISPLAY"))
@@ -524,7 +524,7 @@
     result = process_start (server->priv->x_server_process, FALSE);
 
     if (result)
-        g_debug ("Waiting for ready signal from X server :%d", x_server_get_display_number (X_SERVER (server)));
+        l_debug (display_server, "Waiting for ready signal from X server :%d", x_server_get_display_number (X_SERVER (server)));
 
     if (!result)
         stopped_cb (server->priv->x_server_process, X_SERVER_LOCAL (server));

=== modified file 'src/x-server-xvnc.c'
--- src/x-server-xvnc.c	2013-07-26 02:27:41 +0000
+++ src/x-server-xvnc.c	2013-08-18 23:34:47 +0000
@@ -144,7 +144,7 @@
 
          fd = g_open (server->priv->log_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
          if (fd < 0)
-             g_warning ("Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno));
+             l_warning (server, "Failed to open log file %s: %s", server->priv->log_file, g_strerror (errno));
          else
          {
              dup2 (fd, STDERR_FILENO);
@@ -162,7 +162,7 @@
     if (signum == SIGUSR1 && !server->priv->got_signal)
     {
         server->priv->got_signal = TRUE;
-        g_debug ("Got signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server)));
+        l_debug (server, "Got signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server)));
 
         // FIXME: Check return value
         DISPLAY_SERVER_CLASS (x_server_xvnc_parent_class)->start (DISPLAY_SERVER (server));
@@ -172,14 +172,14 @@
 static void
 stopped_cb (Process *process, XServerXVNC *server)
 {
-    g_debug ("Xvnc server stopped");
+    l_debug (server, "Xvnc server stopped");
 
     g_object_unref (server->priv->x_server_process);
     server->priv->x_server_process = NULL;
 
     x_server_local_release_display_number (x_server_get_display_number (X_SERVER (server)));
 
-    g_debug ("Removing X server authority %s", server->priv->authority_file);
+    l_debug (server, "Removing X server authority %s", server->priv->authority_file);
 
     g_unlink (server->priv->authority_file);
     g_free (server->priv->authority_file);
@@ -219,14 +219,14 @@
     filename = g_strdup_printf ("%s.log", display_server_get_name (display_server));
     dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
     server->priv->log_file = g_build_filename (dir, filename, NULL);
-    g_debug ("Logging to %s", server->priv->log_file);
+    l_debug (display_server, "Logging to %s", server->priv->log_file);
     g_free (filename);
     g_free (dir);
 
     absolute_command = get_absolute_command (server->priv->command);
     if (!absolute_command)
     {
-        g_debug ("Can't launch X server %s, not found in path", server->priv->command);
+        l_debug (display_server, "Can't launch X server %s, not found in path", server->priv->command);
         stopped_cb (server->priv->x_server_process, X_SERVER_XVNC (server));
         return FALSE;
     }
@@ -241,16 +241,16 @@
     dir = g_build_filename (run_dir, "root", NULL);
     g_free (run_dir);
     if (g_mkdir_with_parents (dir, S_IRWXU) < 0)
-        g_warning ("Failed to make authority directory %s: %s", dir, strerror (errno));
+        l_warning (display_server, "Failed to make authority directory %s: %s", dir, strerror (errno));
 
     server->priv->authority_file = g_build_filename (dir, x_server_get_address (X_SERVER (server)), NULL);
     g_free (dir);
 
-    g_debug ("Writing X server authority to %s", server->priv->authority_file);
+    l_debug (display_server, "Writing X server authority to %s", server->priv->authority_file);
 
     x_authority_write (authority, XAUTH_WRITE_MODE_REPLACE, server->priv->authority_file, &error);
     if (error)
-        g_warning ("Failed to write authority: %s", error->message);
+        l_warning (display_server, "Failed to write authority: %s", error->message);
     g_clear_error (&error);
   
     command = g_string_new (absolute_command);
@@ -267,7 +267,7 @@
     process_set_command (server->priv->x_server_process, command->str);
     g_string_free (command, TRUE);
 
-    g_debug ("Launching Xvnc server");
+    l_debug (display_server, "Launching Xvnc server");
 
     /* Variable required for regression tests */
     if (g_getenv ("LIGHTDM_TEST_ROOT"))
@@ -279,7 +279,7 @@
     result = process_start (server->priv->x_server_process, FALSE);
 
     if (result)
-        g_debug ("Waiting for ready signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server)));
+        l_debug (display_server, "Waiting for ready signal from Xvnc server :%d", x_server_get_display_number (X_SERVER (server)));
 
     if (!result)
         stopped_cb (server->priv->x_server_process, X_SERVER_XVNC (server));

=== modified file 'src/x-server.c'
--- src/x-server.c	2013-07-30 15:56:44 +0000
+++ src/x-server.c	2013-08-18 23:34:47 +0000
@@ -133,11 +133,11 @@
     }
 
     /* Open connection */  
-    g_debug ("Connecting to XServer %s", x_server_get_address (server));
+    l_debug (server, "Connecting to XServer %s", x_server_get_address (server));
     server->priv->connection = xcb_connect_to_display_with_auth_info (x_server_get_address (server), auth, NULL);
     if (xcb_connection_has_error (server->priv->connection))
     {
-        g_debug ("Error connecting to XServer %s", x_server_get_address (server));
+        l_debug (server, "Error connecting to XServer %s", x_server_get_address (server));
         return FALSE;
     }
 
@@ -161,9 +161,12 @@
         g_free (t);
 
         t = g_strdup_printf ("%d", vt);
+        l_debug (session, "Setting XDG_VTNR=%s", t);
         session_set_env (session, "XDG_VTNR", t);
         g_free (t);
     }
+    else
+        l_debug (session, "Not setting XDG_VTNR");
 
     session_set_env (session, "DISPLAY", x_server_get_address (X_SERVER (display_server)));
     session_set_tty (session, x_server_get_address (X_SERVER (display_server)));


References