[Box Backup-commit] COMMIT r3172 - box/trunk/lib/server

subversion at boxbackup.org subversion at boxbackup.org
Thu Aug 22 00:44:13 BST 2013


Author: chris
Date: 2013-08-22 00:44:12 +0100 (Thu, 22 Aug 2013)
New Revision: 3172

Modified:
   box/trunk/lib/server/makeprotocol.pl.in
Log:
Add a ToString() method on protocol objects, to help with debugging them.

Modified: box/trunk/lib/server/makeprotocol.pl.in
===================================================================
--- box/trunk/lib/server/makeprotocol.pl.in	2013-08-21 22:45:36 UTC (rev 3171)
+++ box/trunk/lib/server/makeprotocol.pl.in	2013-08-21 23:44:12 UTC (rev 3172)
@@ -342,6 +342,7 @@
 	
 	print H "\tvirtual void LogSysLog(const char *Action) const;\n";
 	print H "\tvirtual void LogFile(const char *Action, FILE *file) const;\n";
+	print H "\tvirtual std::string ToString() const;\n";
 	
 	# write member variables and setup for cpp file
 	my @def_constructor_list;
@@ -467,31 +468,34 @@
 
 	my ($log) = make_log_strings_framework($cmd);
 	print CPP <<__E;
-void $cmd_class\::LogSysLog(const char *Action) const
+std::string $cmd_class\::ToString() const
 {
+	std::ostringstream oss;
 	try
 	{
-		BOX_TRACE($log);
+		oss << $log;
 	}
 	catch(std::exception &e)
 	{
-		BOX_WARNING("Failed to log command: " << Action << ": " <<
-			e.what());
+		oss << "Failed to log command: " << e.what();
 	}
+	return oss.str();
 }
-void $cmd_class\::LogFile(const char *Action, FILE *File) const
+void $cmd_class\::LogSysLog(const char *Action) const
 {
-	std::ostringstream oss;
 	try
 	{
-		oss << $log;
+		BOX_TRACE(Action << " " << $log);
 	}
 	catch(std::exception &e)
 	{
-		oss << "Failed to log command: " << Action << ": " <<
-			e.what();
+		BOX_WARNING("Failed to log command: " << Action << ": " <<
+			e.what());
 	}
-	::fprintf(File, "%s\\n", oss.str().c_str());
+}
+void $cmd_class\::LogFile(const char *Action, FILE *File) const
+{
+	::fprintf(File, "%s %s\\n", Action, ToString().c_str());
 	::fflush(File);
 }
 __E
@@ -1184,7 +1188,7 @@
 		}
 	}
 
-	my $log_cmd = "Action << \" $cmd(\" ";
+	my $log_cmd = '"'.$cmd.'(" ';
 	foreach my $arg (@args)
 	{
 		$arg = "<< $arg ";




More information about the Boxbackup-commit mailing list