+ def log(self, fault_code, runtime, *args):
+ """
+ Log the transaction
+ """
+
+ # Do not log system or Get calls
+ if self.name.startswith('system') or self.name.startswith('Get'):
+ return False
+
+ # Create a new event
+ event = Event(self.api)
+ event['fault_code'] = fault_code
+ event['runtime'] = runtime
+
+ # Redact passwords and sessions
+ if args and isinstance(args[0], dict):
+ for password in 'AuthString', 'session':
+ if args[0].has_key(password):
+ auth = args[0].copy()
+ auth[password] = "Removed by API"
+ args = (auth,) + args[1:]
+
+ # Log call representation
+ # XXX Truncate to avoid DoS
+ event['call'] = self.name + pprint.saferepr(args)
+ event['call_name'] = self.name
+
+ # Both users and nodes can call some methods
+ if isinstance(self.caller, Person):
+ event['person_id'] = self.caller['person_id']
+ elif isinstance(self.caller, Node):
+ event['node_id'] = self.caller['node_id']
+
+ event.sync(commit = False)
+
+ if hasattr(self, 'object_ids'):
+ for object_id in self.object_ids:
+ event.add_object(object_id, commit = False)
+
+ # Set the message for this event
+ if hasattr(self, 'message'):
+ event['message'] = self.message
+
+ if hasattr(self, 'object_type'):
+ event['object_type'] = self.object_type
+
+ # Commit
+ event.sync()
+