Expand logging for User class methods
authorJeremy Stanley <fungi@yuggoth.org>
Sun, 2 Sep 2018 00:36:22 +0000 (00:36 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Sun, 2 Sep 2018 00:36:22 +0000 (00:36 +0000)
Increase logging detail so that client connection/disconnection,
account login/logout, avatar activation/deactivation and
creation/deletion can be clearly associated and followed for ease of
troubleshooting.

mudpy/misc.py

index 4e43353..6b24e1b 100644 (file)
@@ -507,15 +507,10 @@ class User:
     def quit(self):
         """Log, close the connection and remove."""
         if self.account:
-            name = self.account.get("name")
+            name = self.account.get("name", self)
         else:
-            name = ""
-        if name:
-            message = "User " + name
-        else:
-            message = "An unnamed user"
-        message += " logged out."
-        log(message, 2)
+            name = self
+        log("Logging out %s" % name, 2)
         self.deactivate_avatar()
         self.connection.close()
         self.remove()
@@ -648,8 +643,8 @@ class User:
                 log("Administrator %s authenticated." %
                     self.account.get("name"), 2)
             else:
-                # log("User %s authenticated." % self.account.get("name"), 2)
-                log("User %s authenticated." % self.account.subkey, 2)
+                log("User %s authenticated for account %s." % (
+                        self, self.account.subkey), 2)
 
     def show_menu(self):
         """Send the user their current menu."""
@@ -677,6 +672,7 @@ class User:
 
     def remove(self):
         """Remove a user from the list of connected users."""
+        log("Disconnecting account %s." % self, 0)
         universe.userlist.remove(self)
 
     def send(
@@ -908,11 +904,15 @@ class User:
             universe)
         self.avatar.append("inherit", "archetype.avatar")
         self.account.append("avatars", self.avatar.key)
+        log("Created new avatar %s for user %s." % (
+                self.avatar.key, self.account.get("name")), 0)
 
     def delete_avatar(self, avatar):
         """Remove an avatar from the world and from the user's list."""
         if self.avatar is universe.contents[avatar]:
             self.avatar = None
+        log("Deleting avatar %s for user %s." % (
+                avatar, self.account.get("name")), 0)
         universe.contents[avatar].destroy()
         avatars = self.account.get("avatars")
         avatars.remove(avatar)
@@ -924,11 +924,16 @@ class User:
             self.account.get("avatars")[index]]
         self.avatar.owner = self
         self.state = "active"
+        log("Activated avatar %s (%s)." % (
+                self.avatar.get("name"), self.avatar.key), 0)
         self.avatar.go_home()
 
     def deactivate_avatar(self):
         """Have the active avatar leave the world."""
         if self.avatar:
+            log("Deactivating avatar %s (%s) for user %s." % (
+                    self.avatar.get("name"), self.avatar.key,
+                    self.account.get("name")), 0)
             current = self.avatar.get("location")
             if current:
                 self.avatar.set("default_location", current)
@@ -946,6 +951,8 @@ class User:
         """Destroy the user and associated avatars."""
         for avatar in self.account.get("avatars"):
             self.delete_avatar(avatar)
+        log("Destroying account %s for user %s." % (
+                self.account.get("name"), self), 0)
         self.account.destroy()
 
     def list_avatar_names(self):
@@ -1417,13 +1424,14 @@ def check_for_connection(listening_socket):
         return None
 
     # note that we got one
-    log("Connection from " + address[0], 2)
+    log("New connection from %s." % address[0], 2)
 
     # disable blocking so we can proceed whether or not we can send/receive
     connection.setblocking(0)
 
     # create a new user object
     user = User()
+    log("Instantiated %s for %s." % (user, address[0]), 0)
 
     # associate this connection with it
     user.connection = connection