[Box Backup-commit] COMMIT r1790 - in box/chris/general: bin/bbackupctl bin/bbackupquery bin/bbstoreaccounts lib/backupclient lib/backupstore lib/common lib/crypto lib/raidfile lib/server test/bbackupd/testfiles

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Fri Aug 3 00:29:31 BST 2007


Author: chris
Date: 2007-08-03 00:29:31 +0100 (Fri, 03 Aug 2007)
New Revision: 1790

Modified:
   box/chris/general/bin/bbackupctl/bbackupctl.cpp
   box/chris/general/bin/bbackupquery/BackupQueries.cpp
   box/chris/general/bin/bbackupquery/bbackupquery.cpp
   box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp
   box/chris/general/lib/backupclient/BackupClientRestore.cpp
   box/chris/general/lib/backupstore/BackupStoreCheck.cpp
   box/chris/general/lib/backupstore/BackupStoreCheck2.cpp
   box/chris/general/lib/common/DebugMemLeakFinder.cpp
   box/chris/general/lib/common/Logging.cpp
   box/chris/general/lib/crypto/Random.cpp
   box/chris/general/lib/raidfile/RaidFileController.cpp
   box/chris/general/lib/server/SSLLib.cpp
   box/chris/general/test/bbackupd/testfiles/extcheck1.pl.in
   box/chris/general/test/bbackupd/testfiles/extcheck2.pl.in
Log:
Convert most printf() and fprintf() calls to use logging framework
instead. (merges [1789])


Modified: box/chris/general/bin/bbackupctl/bbackupctl.cpp
===================================================================
--- box/chris/general/bin/bbackupctl/bbackupctl.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/bin/bbackupctl/bbackupctl.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -109,8 +109,7 @@
 	}
 
 	// Read in the configuration file
-	if(!quiet) printf("Using configuration file %s\n", 
-		configFilename.c_str());
+	if(!quiet) BOX_NOTICE("Using configuration file " << configFilename);
 
 	std::string errs;
 	std::auto_ptr<Configuration> config(
@@ -119,7 +118,7 @@
 
 	if(config.get() == 0 || !errs.empty())
 	{
-		printf("Invalid configuration file:\n%s", errs.c_str());
+		BOX_ERROR("Invalid configuration file: " << errs);
 		return 1;
 	}
 	// Easier coding
@@ -128,10 +127,10 @@
 	// Check there's a socket defined in the config file
 	if(!conf.KeyExists("CommandSocket"))
 	{
-		printf("Daemon isn't using a control socket, "
+		BOX_ERROR("Daemon isn't using a control socket, "
 			"could not execute command.\n"
 			"Add a CommandSocket declaration to the "
-			"bbackupd.conf file.\n");
+			"bbackupd.conf file.");
 		return 1;
 	}
 	
@@ -153,18 +152,14 @@
 	}
 	catch(...)
 	{
-		printf("Failed to connect to daemon control socket.\n"
+		BOX_ERROR("Failed to connect to daemon control socket.\n"
 			"Possible causes:\n"
 			"  * Daemon not running\n"
 			"  * Daemon busy syncing with store server\n"
 			"  * Another bbackupctl process is communicating with the daemon\n"
-			"  * Daemon is waiting to recover from an error\n"
+			"  * Daemon is waiting to recover from an error"
 		);
 
-#if defined WIN32 && ! defined NDEBUG
-		BOX_ERROR("Failed to connect to the command socket");
-#endif
-
 		return 1;
 	}
 	
@@ -193,19 +188,19 @@
 	if(::sscanf(configSummary.c_str(), "bbackupd: %d %d %d %d", &autoBackup,
 			&updateStoreInterval, &minimumFileAge, &maxUploadWait) != 4)
 	{
-		printf("Config summary didn't decode\n");
+		BOX_ERROR("Config summary didn't decode.");
 		return 1;
 	}
 	// Print summary?
 	if(!quiet)
 	{
-		printf("Daemon configuration summary:\n"
-			"  AutomaticBackup = %s\n"
-			"  UpdateStoreInterval = %d seconds\n"
-			"  MinimumFileAge = %d seconds\n"
-			"  MaxUploadWait = %d seconds\n",
-			autoBackup?"true":"false", updateStoreInterval, 
-			minimumFileAge, maxUploadWait);
+		BOX_INFO("Daemon configuration summary:\n"
+			"  AutomaticBackup = " << 
+			(autoBackup?"true":"false") << "\n"
+			"  UpdateStoreInterval = " << updateStoreInterval << 
+			" seconds\n"
+			"  MinimumFileAge = " << minimumFileAge << " seconds\n"
+			"  MaxUploadWait = " << maxUploadWait << " seconds\n");
 	}
 
 	std::string stateLine;
@@ -266,8 +261,8 @@
 
 			if (currentState != 0)
 			{
-				printf("Waiting for current sync/error state "
-					"to finish...\n");
+				BOX_INFO("Waiting for current sync/error state "
+					"to finish...");
 			}
 		}
 		break;
@@ -310,14 +305,14 @@
 			{
 				if(line == "start-sync")
 				{
-					if (!quiet) printf("Sync started...\n");
+					if (!quiet) BOX_INFO("Sync started...");
 					syncIsRunning = true;
 				}
 				else if(line == "finish-sync")
 				{
 					if (syncIsRunning)
 					{
-						if (!quiet) printf("Sync finished.\n");
+						if (!quiet) BOX_INFO("Sync finished.\n");
 						// Send a quit command to finish nicely
 						connection.Write("quit\n", 5);
 					
@@ -326,7 +321,7 @@
 					}
 					else
 					{
-						if (!quiet) printf("Previous sync finished.\n");
+						if (!quiet) BOX_INFO("Previous sync finished.");
 					}
 					// daemon must still be busy
 				}
@@ -340,13 +335,13 @@
 				{
 					if(!quiet)
 					{
-						printf("Succeeded.\n");
+						BOX_INFO("Succeeded.\n");
 					}
 					finished = true;
 				}
 				else if(line == "error")
 				{
-					printf("ERROR. (Check command spelling)\n");
+					BOX_ERROR("Check command spelling");
 					returnCode = 1;
 					finished = true;
 				}

Modified: box/chris/general/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/BackupQueries.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/bin/bbackupquery/BackupQueries.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -181,7 +181,7 @@
 			if (!ConvertEncoding(*i, CP_ACP, converted, 
 				GetConsoleCP()))
 			{
-				printf("Failed to convert encoding");
+				BOX_ERROR("Failed to convert encoding");
 				return;
 			}
 			*i = converted;
@@ -255,7 +255,7 @@
 		// No such command
 		if(alias[a] == 0)
 		{
-			printf("Unrecognised command: %s\n", Command);
+			BOX_ERROR("Unrecognised command: " << Command);
 			return;
 		}
 	}
@@ -275,8 +275,8 @@
 			// Valid option?
 			if(::strchr(commands[cmd].opts, *c) == NULL)
 			{
-				printf("Invalid option '%c' for command %s\n", 
-					*c, commands[cmd].name);
+				BOX_ERROR("Invalid option '" << *c << "' for "
+					"command " << commands[cmd].name);
 				return;
 			}
 			opts[(int)*c] = true;
@@ -305,9 +305,8 @@
 	case COMMAND_pwd:
 		{
 			// Simple implementation, so do it here
-			printf("%s (%08llx)\n", 
-				GetCurrentDirectoryName().c_str(), 
-				(long long)GetCurrentDirectoryID());
+			BOX_INFO(GetCurrentDirectoryName() << " (" <<
+				BOX_FORMAT_OBJECTID(GetCurrentDirectoryID()));
 		}
 		break;
 
@@ -320,7 +319,7 @@
 		break;
 		
 	case COMMAND_sh:
-		printf("The command to run must be specified as an argument.\n");
+		BOX_ERROR("The command to run must be specified as an argument.");
 		break;
 		
 	case COMMAND_GetObject:
@@ -401,8 +400,8 @@
 
 		if(rootDir == 0)
 		{
-			printf("Directory '%s' not found on store\n",
-				args[0].c_str());
+			BOX_ERROR("Directory '" << args[0] << "' not found "
+				"on store.");
 			return;
 		}
 	}
@@ -747,7 +746,7 @@
 {
 	if(args.size() != 1 || args[0].size() == 0)
 	{
-		printf("Incorrect usage.\ncd [-o] [-d] <directory>\n");
+		BOX_ERROR("Incorrect usage. cd [-o] [-d] <directory>");
 		return;
 	}
 
@@ -764,7 +763,7 @@
 	
 	if(id == 0)
 	{
-		printf("Directory '%s' not found\n", args[0].c_str());
+		BOX_ERROR("Directory '" << args[0] << "' not found.");
 		return;
 	}
 	
@@ -785,7 +784,7 @@
 {
 	if(args.size() != 1 || args[0].size() == 0)
 	{
-		printf("Incorrect usage.\nlcd <local-directory>\n");
+		BOX_ERROR("Incorrect usage. lcd <local-directory>");
 		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
@@ -795,7 +794,7 @@
 	std::string dirName;
 	if(!ConvertConsoleToUtf8(args[0].c_str(), dirName))
 	{
-		printf("Failed to convert path from console encoding.\n");
+		BOX_ERROR("Failed to convert path from console encoding.");
 		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
@@ -805,8 +804,16 @@
 #endif
 	if(result != 0)
 	{
-		printf((errno == ENOENT || errno == ENOTDIR)?"Directory '%s' does not exist\n":"Error changing dir to '%s'\n",
-			args[0].c_str());
+		if(errno == ENOENT || errno == ENOTDIR)
+		{
+			BOX_ERROR("Directory '" << args[0] << "' does not exist.");
+		}
+		else
+		{
+			BOX_ERROR("Error changing to directory '" <<
+				args[0] << ": " << strerror(errno));
+		}
+
 		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
@@ -815,7 +822,8 @@
 	char wd[PATH_MAX];
 	if(::getcwd(wd, PATH_MAX) == 0)
 	{
-		printf("Error getting current directory\n");
+		BOX_ERROR("Error getting current directory: " <<
+			strerror(errno));
 		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
@@ -823,13 +831,13 @@
 #ifdef WIN32
 	if(!ConvertUtf8ToConsole(wd, dirName))
 	{
-		printf("Failed to convert new path from console encoding.\n");
+		BOX_ERROR("Failed to convert new path from console encoding.");
 		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
-	printf("Local current directory is now '%s'\n", dirName.c_str());
+	BOX_INFO("Local current directory is now '" << dirName << "'.");
 #else
-	printf("Local current directory is now '%s'\n", wd);
+	BOX_INFO("Local current directory is now '" << wd << "'.");
 #endif
 }
 
@@ -847,14 +855,15 @@
 	// Check args
 	if(args.size() != 2)
 	{
-		printf("Incorrect usage.\ngetobject <object-id> <local-filename>\n");
+		BOX_ERROR("Incorrect usage. getobject <object-id> "
+			"<local-filename>");
 		return;
 	}
 	
 	int64_t id = ::strtoll(args[0].c_str(), 0, 16);
 	if(id == std::numeric_limits<long long>::min() || id == std::numeric_limits<long long>::max() || id == 0)
 	{
-		printf("Not a valid object ID (specified in hex)\n");
+		BOX_ERROR("Not a valid object ID (specified in hex).");
 		return;
 	}
 	
@@ -862,7 +871,7 @@
 	struct stat st;
 	if(::stat(args[1].c_str(), &st) == 0 || errno != ENOENT)
 	{
-		printf("The local file %s already exists\n", args[1].c_str());
+		BOX_ERROR("The local file '" << args[1] << " already exists.");
 		return;
 	}
 	
@@ -880,18 +889,20 @@
 			std::auto_ptr<IOStream> objectStream(mrConnection.ReceiveStream());
 			objectStream->CopyStreamTo(out);
 			
-			printf("Object ID %08llx fetched successfully.\n", id);
+			BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(id) <<
+				" fetched successfully.");
 		}
 		else
 		{
-			printf("Object does not exist on store.\n");
+			BOX_ERROR("Object ID " << BOX_FORMAT_OBJECTID(id) <<
+				" does not exist on store.");
 			::unlink(args[1].c_str());
 		}
 	}
 	catch(...)
 	{
 		::unlink(args[1].c_str());
-		printf("Error occured fetching object.\n");
+		BOX_ERROR("Error occured fetching object.");
 	}
 }
 
@@ -911,9 +922,9 @@
 	// Check args
 	if(args.size() < 1 || (opts['i'] && args.size() != 2) || args.size() > 2)
 	{
-		printf("Incorrect usage.\n"
+		BOX_ERROR("Incorrect usage.\n"
 			"get <remote-filename> [<local-filename>] or\n"
-			"get -i <object-id> <local-filename>\n");
+			"get -i <object-id> <local-filename>");
 		return;
 	}
 
@@ -931,7 +942,7 @@
 			std::string out;
 			if(!ConvertConsoleToUtf8(i->c_str(), out))
 			{
-				fprintf(stderr, "failed to convert encoding\n");
+				BOX_ERROR("Failed to convert encoding.");
 				return;
 			}
 			*i = out;
@@ -952,8 +963,8 @@
 				dirId = FindDirectoryObjectID(dirName);
 				if(dirId == 0)
 				{
-					printf("Directory '%s' not found\n", 
-						dirName.c_str());
+					BOX_ERROR("Directory '" << dirName <<
+						"' not found.");
 					return;
 				}
 			}
@@ -981,18 +992,19 @@
 				fileId == std::numeric_limits<long long>::max() || 
 				fileId == 0)
 			{
-				printf("Not a valid object ID (specified in hex)\n");
+				BOX_ERROR("Not a valid object ID (specified in hex).");
 				return;
 			}
 			
 			// Check that the item is actually in the directory
 			if(dir.FindEntryByID(fileId) == 0)
 			{
-				printf("ID '%08llx' not found in current "
+				BOX_ERROR("File ID " << 
+					BOX_FORMAT_OBJECTID(fileId) <<
+					" not found in current "
 					"directory on store.\n"
-					"(You can only download objects by ID "
-					"from the current directory.)\n", 
-					fileId);
+					"(You can only download files by ID "
+					"from the current directory.)");
 				return;
 			}
 			
@@ -1007,10 +1019,11 @@
 			
 			if(en == 0)
 			{
-				printf("Filename '%s' not found in current "
+				BOX_ERROR("Filename '" << args[0] << "' "
+					"not found in current "
 					"directory on store.\n"
 					"(Subdirectories in path not "
-					"searched.)\n", args[0].c_str());
+					"searched.)");
 				return;
 			}
 			
@@ -1027,8 +1040,8 @@
 	struct stat st;
 	if(::stat(localName.c_str(), &st) == 0 || errno != ENOENT)
 	{
-		printf("The local file %s already exists, will not "
-			"overwrite it.\n", localName.c_str());
+		BOX_ERROR("The local file " << localName << " already exists, "
+			"will not overwrite it.");
 		SetReturnCode(COMMAND_RETURN_ERROR);
 		return;
 	}
@@ -1046,7 +1059,8 @@
 		BackupStoreFile::DecodeFile(*objectStream, localName.c_str(), mrConnection.GetTimeout());
 
 		// Done.
-		printf("Object ID %08llx fetched sucessfully.\n", fileId);
+		BOX_INFO("Object ID " << BOX_FORMAT_OBJECTID(fileId) <<
+			" fetched successfully.");
 	}
 	catch (BoxException &e)
 	{
@@ -1160,14 +1174,16 @@
 		}
 		else
 		{
-			printf("Warning: couldn't determine the time of the last synchronisation -- checks not performed.\n");
+			BOX_WARNING("Failed to determine the time of the last "
+				"synchronisation -- checks not performed.");
 		}
 	}
 
 	// Quick compare?
 	if(params.mQuickCompare)
 	{
-		printf("WARNING: Quick compare used -- file attributes are not checked.\n");
+		BOX_WARNING("Quick compare used -- file attributes are not "
+			"checked.");
 	}
 	
 	if(!opts['l'] && opts['a'] && args.size() == 0)
@@ -1192,7 +1208,7 @@
 		// Can't be bothered to do all the hard work to work out which location it's on, and hence which exclude list
 		if(!params.mIgnoreExcludes)
 		{
-			printf("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes\n");
+			BOX_ERROR("Cannot use excludes on directory to directory comparison -- use -E flag to specify ignored excludes.");
 			return;
 		}
 		else
@@ -1203,22 +1219,22 @@
 	}
 	else
 	{
-		printf("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>\n");
+		BOX_ERROR("Incorrect usage.\ncompare -a\n or compare -l <location-name>\n or compare <store-dir-name> <local-dir-name>");
 		return;
 	}
 
 	if (!params.mQuietCompare)
 	{	
-		printf("\n[ %d (of %d) differences probably due to file "
-			"modifications after the last upload ]\n",
-			params.mDifferencesExplainedByModTime, 
-			params.mDifferences);
+		BOX_INFO("[ " <<
+			params.mDifferencesExplainedByModTime << " (of " <<
+			params.mDifferences << ") differences probably "
+			"due to file modifications after the last upload ]");
 	}
 
-	printf("Differences: %d (%d dirs excluded, %d files excluded, "
-		"%d files not checked)\n",
-		params.mDifferences, params.mExcludedDirs, 
-		params.mExcludedFiles, params.mUncheckedFiles);
+	BOX_INFO("Differences: " << params.mDifferences << " (" <<
+		params.mExcludedDirs   << " dirs excluded, " <<
+		params.mExcludedFiles  << " files excluded, " <<
+		params.mUncheckedFiles << " files not checked)");
 	
 	// Set return code?
 	if(opts['c'])
@@ -1253,7 +1269,7 @@
 	const Configuration &locations(mrConfiguration.GetSubConfiguration("BackupLocations"));
 	if(!locations.SubConfigurationExists(rLocation.c_str()))
 	{
-		printf("Location %s does not exist.\n", rLocation.c_str());
+		BOX_ERROR("Location " << rLocation << " does not exist.");
 		return;
 	}
 	const Configuration &loc(locations.GetSubConfiguration(rLocation.c_str()));
@@ -1264,9 +1280,9 @@
 		if (path.size() > 0 && path[path.size()-1] == 
 			DIRECTORY_SEPARATOR_ASCHAR)
 		{
-			fprintf(stderr, "Warning: location '%s' path ends "
-				"with '%s', compare may fail!",
-				rLocation.c_str(), DIRECTORY_SEPARATOR);
+			BOX_WARNING("Location '" << rLocation << "' path ends "
+				"with '" DIRECTORY_SEPARATOR "', "
+				"compare may fail!");
 		}
 	}
 	#endif
@@ -1319,9 +1335,9 @@
 	// Found?
 	if(dirID == 0)
 	{
-		printf("Local directory '%s' exists, but "
-			"server directory '%s' does not exist\n", 
-			rLocalDir.c_str(), rStoreDir.c_str());		
+		BOX_WARNING("Local directory '" << rLocalDir << "' exists, "
+			"but server directory '" << rStoreDir << "' does not "
+			"exist.");
 		rParams.mDifferences ++;
 		return;
 	}
@@ -1369,24 +1385,23 @@
 		// What kind of error?
 		if(errno == ENOTDIR)
 		{
-			printf("Local object '%s' is a file, "
-				"server object '%s' is a directory\n", 
-				localDirDisplay.c_str(), 
-				storeDirDisplay.c_str());
+			BOX_WARNING("Local object '" << localDirDisplay << "' "
+				"is a file, server object '" << 
+				storeDirDisplay << "' is a directory.");
 			rParams.mDifferences ++;
 		}
 		else if(errno == ENOENT)
 		{
-			printf("Local directory '%s' does not exist "
-				"(compared to server directory '%s')\n",
-				localDirDisplay.c_str(), 
-				storeDirDisplay.c_str());
+			BOX_WARNING("Local directory '" << localDirDisplay <<
+				"' does not exist (compared to server "
+				"directory '" << storeDirDisplay << "').");
 			rParams.mDifferences ++;
 		}
 		else
 		{
-			printf("ERROR: stat on local dir '%s'\n", 
-				localDirDisplay.c_str());
+			BOX_WARNING("Failed to access local directory '" <<
+				localDirDisplay << ": " << strerror(errno) <<
+				"'.");
 			rParams.mUncheckedFiles ++;
 		}
 		return;
@@ -1407,8 +1422,8 @@
 	// Test out the attributes
 	if(!dir.HasAttributes())
 	{
-		printf("Store directory '%s' doesn't have attributes.\n", 
-			storeDirDisplay.c_str());
+		BOX_WARNING("Store directory '" << storeDirDisplay << "' "
+			"doesn't have attributes.");
 	}
 	else
 	{
@@ -1423,10 +1438,9 @@
 
 		if(!(attr.Compare(localAttr, true, true /* ignore modification times */)))
 		{
-			printf("Local directory '%s' has different attributes "
-				"to store directory '%s'.\n",
-				localDirDisplay.c_str(), 
-				storeDirDisplay.c_str());
+			BOX_WARNING("Local directory '" << localDirDisplay <<
+				"' has different attributes to store "
+				"directory '" << storeDirDisplay << "'.");
 			rParams.mDifferences ++;
 		}
 	}
@@ -1435,8 +1449,8 @@
 	DIR *dirhandle = ::opendir(rLocalDir.c_str());
 	if(dirhandle == 0)
 	{
-		printf("ERROR: opendir on local dir '%s'\n", 
-			localDirDisplay.c_str());
+		BOX_WARNING("Failed to open local directory '" << 
+			localDirDisplay << "': " << strerror(errno));
 		rParams.mUncheckedFiles ++;
 		return;
 	}
@@ -1457,9 +1471,9 @@
 #ifdef HAVE_VALID_DIRENT_D_TYPE
 				if (localDirEn->d_type != DT_DIR)
 				{
-					fprintf(stderr, "ERROR: d_type does "
-						"not really work on your "
-						"platform. Reconfigure Box!\n");
+					BOX_ERROR("d_type does not really "
+						"work on your platform. "
+						"Reconfigure Box!");
 					return;
 				}
 #endif
@@ -1504,8 +1518,8 @@
 		// Close directory
 		if(::closedir(dirhandle) != 0)
 		{
-			printf("ERROR: closedir on local dir '%s'\n", 
-				localDirDisplay.c_str());
+			BOX_ERROR("Failed to close local directory '" <<
+				localDirDisplay << "': " << strerror(errno));
 		}
 		dirhandle = 0;
 	
@@ -1565,10 +1579,10 @@
 			if(local == localFiles.end())
 			{
 				// Not found -- report
-				printf("Local file '%s' does not exist, "
-					"but store file '%s' does.\n",
-					localPathDisplay.c_str(),
-					storePathDisplay.c_str());
+				BOX_WARNING("Local file '" << 
+					localDirDisplay << "' does not exist, "
+					"but store file '" <<
+					storePathDisplay << "' does.");
 				rParams.mDifferences ++;
 			}
 			else
@@ -1643,20 +1657,21 @@
 								ignoreAttrModTime,
 								fileOnServerStream->IsSymLink() /* ignore modification time if it's a symlink */))
 						{
-							printf("Local file '%s' "
-								"has different attributes "
-								"to store file '%s'.\n",
-								localPathDisplay.c_str(), 
-								storePathDisplay.c_str());						
+							BOX_WARNING("Local file '" <<
+								localPathDisplay <<
+								"' has different attributes "
+								"to store file '" <<
+								storePathDisplay <<
+								"'.");
 							rParams.mDifferences ++;
 							if(modifiedAfterLastSync)
 							{
 								rParams.mDifferencesExplainedByModTime ++;
-								printf("(the file above was modified after the last sync time -- might be reason for difference)\n");
+								BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)");
 							}
 							else if(i->second->HasAttributes())
 							{
-								printf("(the file above has had new attributes applied)\n");
+								BOX_INFO("(the file above has had new attributes applied)\n");
 							}
 						}
 	
@@ -1722,20 +1737,21 @@
 					// Report if not equal.
 					if(!equal)
 					{
-						printf("Local file '%s' "
+						BOX_WARNING("Local file '" <<
+							localPathDisplay << "' "
 							"has different contents "
-							"to store file '%s'.\n",
-							localPathDisplay.c_str(), 
-							storePathDisplay.c_str());
+							"to store file '" <<
+							storePathDisplay <<
+							"'.");
 						rParams.mDifferences ++;
 						if(modifiedAfterLastSync)
 						{
 							rParams.mDifferencesExplainedByModTime ++;
-							printf("(the file above was modified after the last sync time -- might be reason for difference)\n");
+							BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)");
 						}
 						else if(i->second->HasAttributes())
 						{
-							printf("(the file above has had new attributes applied)\n");
+							BOX_INFO("(the file above has had new attributes applied)\n");
 						}
 					}
 				}
@@ -1794,11 +1810,11 @@
 			if(rParams.mpExcludeFiles == 0 || 
 				!(rParams.mpExcludeFiles->IsExcluded(localPath)))
 			{
-				printf("Local file '%s' exists, "
-					"but store file '%s' "
-					"does not exist.\n",
-					localPathDisplay.c_str(),
-					storePathDisplay.c_str());
+				BOX_WARNING("Local file '" << 
+					localPathDisplay <<
+					"' exists, but store file '" <<
+					storePathDisplay <<
+					"' does not.");
 				rParams.mDifferences ++;
 				
 				// Check the file modification time
@@ -1809,7 +1825,7 @@
 						if(FileModificationTime(st) > rParams.mLatestFileUploadTime)
 						{
 							rParams.mDifferencesExplainedByModTime ++;
-							printf("(the file above was modified after the last sync time -- might be reason for difference)\n");
+							BOX_INFO("(the file above was modified after the last sync time -- might be reason for difference)");
 						}
 					}
 				}
@@ -1852,19 +1868,19 @@
 				rParams.mpExcludeDirs->IsExcluded(localPath))
 			{
 				// Not found -- report
-				printf("Local directory '%s' is excluded, but "
-					"store directory '%s' still exists.\n",
-					localPathDisplay.c_str(),
-					storePathDisplay.c_str());
+				BOX_WARNING("Local directory '" <<
+					localPathDisplay << "' is excluded, "
+					"but store directory '" <<
+					storePathDisplay << "' still exists.");
 				rParams.mDifferences ++;
 			}
 			else if(local == localDirs.end())
 			{
 				// Not found -- report
-				printf("Local directory '%s' does not exist, "
-					"but store directory '%s' does.\n",
-					localPathDisplay.c_str(),
-					storePathDisplay.c_str());
+				BOX_WARNING("Local directory '" <<
+					localPathDisplay << "' does not exist, "
+					"but store directory '" <<
+					storePathDisplay << "' does.");
 				rParams.mDifferences ++;
 			}
 			else if(rParams.mpExcludeDirs != NULL && 
@@ -1908,10 +1924,10 @@
 			// Should this be ignored (ie is excluded)?
 			if(rParams.mpExcludeDirs == 0 || !(rParams.mpExcludeDirs->IsExcluded(localPath)))
 			{
-				printf("Local directory '%s' exists, but "
-					"store directory '%s' does not exist.\n",
-					localPathDisplay.c_str(),
-					storePathDisplay.c_str());
+				BOX_WARNING("Local directory '" <<
+					localPathDisplay << "' exists, but "
+					"store directory '" <<
+					storePathDisplay << "' does not.");
 				rParams.mDifferences ++;
 			}
 			else
@@ -1944,7 +1960,7 @@
 	// Check arguments
 	if(args.size() != 2)
 	{
-		printf("Incorrect usage.\nrestore [-d] [-r] [-i] <directory-name> <local-directory-name>\n");
+		BOX_ERROR("Incorrect usage. restore [-d] [-r] [-i] <remote-name> <local-name>");
 		return;
 	}
 
@@ -1959,7 +1975,7 @@
 		dirID = ::strtoll(args[0].c_str(), 0, 16);
 		if(dirID == std::numeric_limits<long long>::min() || dirID == std::numeric_limits<long long>::max() || dirID == 0)
 		{
-			printf("Not a valid object ID (specified in hex)\n");
+			BOX_ERROR("Not a valid object ID (specified in hex)");
 			return;
 		}
 	}
@@ -1982,12 +1998,12 @@
 	// Allowable?
 	if(dirID == 0)
 	{
-		printf("Directory '%s' not found on server\n", args[0].c_str());
+		BOX_ERROR("Directory '" << args[0] << "' not found on server");
 		return;
 	}
 	if(dirID == BackupProtocolClientListDirectory::RootDirectory)
 	{
-		printf("Cannot restore the root directory -- restore locations individually.\n");
+		BOX_ERROR("Cannot restore the root directory -- restore locations individually.");
 		return;
 	}
 	
@@ -2023,31 +2039,31 @@
 	switch(result)
 	{
 	case Restore_Complete:
-		printf("Restore complete\n");
+		BOX_INFO("Restore complete.");
 		break;
 	
 	case Restore_ResumePossible:
-		printf("Resume possible -- repeat command with -r flag to resume\n");
+		BOX_ERROR("Resume possible -- repeat command with -r flag to resume");
 		break;
 	
 	case Restore_TargetExists:
-		printf("The target directory exists. You cannot restore over an existing directory.\n");
+		BOX_ERROR("The target directory exists. You cannot restore over an existing directory.");
 		break;
 		
 	#ifdef WIN32
 	case Restore_TargetPathNotFound:
-		printf("The target directory path does not exist.\n"
+		BOX_ERROR("The target directory path does not exist.\n"
 			"To restore to a directory whose parent "
-			"does not exist, create the parent first.\n");
+			"does not exist, create the parent first.");
 		break;
 	#endif
 
 	case Restore_UnknownError:
-		printf("Unknown error during restore.\n");
+		BOX_ERROR("Unknown error during restore.");
 		break;
 
 	default:
-		printf("ERROR: Unknown restore result %d.\n", result);
+		BOX_ERROR("Unknown restore result " << result << ".");
 		break;
 	}
 }
@@ -2167,7 +2183,7 @@
 	// Check arguments
 	if(args.size() != 1)
 	{
-		printf("Incorrect usage.\nundelete <directory-name>\n");
+		BOX_ERROR("Incorrect usage. undelete <directory-name>");
 		return;
 	}
 
@@ -2185,12 +2201,12 @@
 	// Allowable?
 	if(dirID == 0)
 	{
-		printf("Directory '%s' not found on server\n", args[0].c_str());
+		BOX_ERROR("Directory '" << args[0] << "' not found on server.");
 		return;
 	}
 	if(dirID == BackupProtocolClientListDirectory::RootDirectory)
 	{
-		printf("Cannot undelete the root directory.\n");
+		BOX_ERROR("Cannot undelete the root directory.");
 		return;
 	}
 

Modified: box/chris/general/bin/bbackupquery/bbackupquery.cpp
===================================================================
--- box/chris/general/bin/bbackupquery/bbackupquery.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/bin/bbackupquery/bbackupquery.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -12,8 +12,14 @@
 #ifdef HAVE_UNISTD_H
 	#include <unistd.h>
 #endif
+
+#include <errno.h>
 #include <stdio.h>
-#include <sys/types.h>
+
+#ifdef HAVE_SYS_TYPES_H
+	#include <sys/types.h>
+#endif
+
 #ifdef HAVE_LIBREADLINE
 	#ifdef HAVE_READLINE_READLINE_H
 		#include <readline/readline.h>
@@ -168,7 +174,8 @@
 			logFile = ::fopen(optarg, "w");
 			if(logFile == 0)
 			{
-				printf("Can't open log file '%s'\n", optarg);
+				BOX_ERROR("Failed to open log file '" <<
+					optarg << "': " << strerror(errno));
 			}
 			break;
 
@@ -201,14 +208,14 @@
 	{
 		if (!SetConsoleCP(CP_UTF8))
 		{
-			fprintf(stderr, "Failed to set input codepage: "
-				"error %d\n", GetLastError());
+			BOX_ERROR("Failed to set input codepage: " <<
+				GetErrorMessage(GetLastError()));
 		}
 
 		if (!SetConsoleOutputCP(CP_UTF8))
 		{
-			fprintf(stderr, "Failed to set output codepage: "
-				"error %d\n", GetLastError());
+			BOX_ERROR("Failed to set output codepage: " <<
+				GetErrorMessage(GetLastError()));
 		}
 
 		// enable input of Unicode characters
@@ -222,8 +229,7 @@
 #endif // WIN32
 
 	// Read in the configuration file
-	if(!quiet) printf("Using configuration file %s\n", 
-		configFilename.c_str());
+	if(!quiet) BOX_INFO("Using configuration file " << configFilename);
 
 	std::string errs;
 	std::auto_ptr<Configuration> config(
@@ -232,7 +238,7 @@
 
 	if(config.get() == 0 || !errs.empty())
 	{
-		printf("Invalid configuration file:\n%s", errs.c_str());
+		BOX_FATAL("Invalid configuration file: " << errs);
 		return 1;
 	}
 	// Easier coding
@@ -252,12 +258,12 @@
 	BackupClientCryptoKeys_Setup(conf.GetKeyValue("KeysFile").c_str());
 
 	// 2. Connect to server
-	if(!quiet) printf("Connecting to store...\n");
+	if(!quiet) BOX_INFO("Connecting to store...");
 	SocketStreamTLS socket;
 	socket.Open(tlsContext, Socket::TypeINET, conf.GetKeyValue("StoreHostname").c_str(), BOX_PORT_BBSTORED);
 	
 	// 3. Make a protocol, and handshake
-	if(!quiet) printf("Handshake with store...\n");
+	if(!quiet) BOX_INFO("Handshake with store...");
 	BackupProtocolClient connection(socket);
 	connection.Handshake();
 	
@@ -268,7 +274,7 @@
 	}
 	
 	// 4. Log in to server
-	if(!quiet) printf("Login to store...\n");
+	if(!quiet) BOX_INFO("Login to store...");
 	// Check the version of the server
 	{
 		std::auto_ptr<BackupProtocolClientVersion> serverVersion(connection.QueryVersion(BACKUP_STORE_SERVER_VERSION));
@@ -345,9 +351,9 @@
 #endif
 	
 	// Done... stop nicely
-	if(!quiet) printf("Logging off...\n");
+	if(!quiet) BOX_INFO("Logging off...");
 	connection.QueryFinished();
-	if(!quiet) printf("Session finished.\n");
+	if(!quiet) BOX_INFO("Session finished.");
 	
 	// Return code
 	returnCode = context.GetReturnCode();

Modified: box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp
===================================================================
--- box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/bin/bbstoreaccounts/bbstoreaccounts.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -37,12 +37,13 @@
 {
 	if(SoftLimit >= HardLimit)
 	{
-		printf("ERROR: Soft limit must be less than the hard limit.\n");
+		BOX_FATAL("Soft limit must be less than the hard limit.");
 		exit(1);
 	}
 	if(SoftLimit > ((HardLimit * MAX_SOFT_LIMIT_SIZE) / 100))
 	{
-		printf("ERROR: Soft limit must be no more than %d%% of the hard limit.\n", MAX_SOFT_LIMIT_SIZE);
+		BOX_FATAL("Soft limit must be no more than " << 
+			MAX_SOFT_LIMIT_SIZE << "% of the hard limit.");
 		exit(1);
 	}
 }
@@ -53,7 +54,7 @@
 	RaidFileController &controller(RaidFileController::GetController());
 	if(DiscSet < 0 || DiscSet >= controller.GetNumDiscSets())
 	{
-		printf("Disc set %d does not exist\n", DiscSet);
+		BOX_FATAL("Disc set " << DiscSet << " does not exist.");
 		exit(1);
 	}
 	
@@ -89,7 +90,7 @@
 	int64_t number = strtol(string, &endptr, 0);
 	if(endptr == string || number == LONG_MIN || number == LONG_MAX)
 	{
-		printf("%s is an invalid number\n", string);
+		BOX_FATAL("'" << string << "' is not a valid number.");
 		exit(1);
 	}
 	
@@ -116,7 +117,8 @@
 		break;
 	
 	default:
-		printf("%s has an invalid units specifier\nUse B for blocks, M for Mb, G for Gb, eg 2Gb\n", string);
+		BOX_FATAL(string << " has an invalid units specifier "
+			"(use B for blocks, M for Mb, G for Gb, eg 2Gb)");
 		exit(1);
 		break;		
 	}
@@ -143,7 +145,8 @@
 	if(!gotLock)
 	{
 		// Couldn't lock the account -- just stop now
-		printf("Couldn't lock the account -- did not change the limits\nTry again later.\n");
+		BOX_ERROR("Failed to lock the account, did not change limits. "
+			"Try again later.");
 		return 1;
 	}
 
@@ -168,7 +171,8 @@
 	// Already exists?
 	if(!db->EntryExists(ID))
 	{
-		printf("Account %x does not exist\n", ID);
+		BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) << 
+			" does not exist.");
 		return 1;
 	}
 	
@@ -198,7 +202,9 @@
 	// Save
 	info->Save();
 
-	printf("Limits on account 0x%08x changed to %lld soft, %lld hard\n", ID, softlimit, hardlimit);
+	BOX_NOTICE("Limits on account " << BOX_FORMAT_ACCOUNT(ID) <<
+		" changed to " << softlimit << " soft, " <<
+		hardlimit << " hard.");
 
 	return 0;
 }
@@ -211,7 +217,8 @@
 	// Exists?
 	if(!db->EntryExists(ID))
 	{
-		printf("Account %x does not exist\n", ID);
+		BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) << 
+			" does not exist.");
 		return 1;
 	}
 	
@@ -241,11 +248,12 @@
 	// Check user really wants to do this
 	if(AskForConfirmation)
 	{
-		::printf("Really delete account %08x?\n(type 'yes' to confirm)\n", ID);
+		BOX_WARNING("Really delete account " << 
+			BOX_FORMAT_ACCOUNT(ID) << "? (type 'yes' to confirm)");
 		char response[256];
 		if(::fgets(response, sizeof(response), stdin) == 0 || ::strcmp(response, "yes\n") != 0)
 		{
-			printf("Deletion cancelled\n");
+			BOX_NOTICE("Deletion cancelled.");
 			return 0;
 		}
 	}
@@ -256,7 +264,8 @@
 	// Exists?
 	if(!db->EntryExists(ID))
 	{
-		printf("Account %x does not exist\n", ID);
+		BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) << 
+			" does not exist.");
 		return 1;
 	}
 	
@@ -318,24 +327,27 @@
 			toDelete.push_back((*i) + DIRECTORY_SEPARATOR + rootDir);
 		}
 	}
-	
+
+	int retcode = 0;
+
 	// Thirdly, delete the directories...
 	for(std::vector<std::string>::const_iterator d(toDelete.begin()); d != toDelete.end(); ++d)
 	{
-		::printf("Deleting store directory %s...\n", (*d).c_str());
+		BOX_NOTICE("Deleting store directory " << (*d) << "...");
 		// Just use the rm command to delete the files
 		std::string cmd("rm -rf ");
 		cmd += *d;
 		// Run command
 		if(::system(cmd.c_str()) != 0)
 		{
-			::printf("ERROR: Deletion of %s failed.\n(when cleaning up, remember to delete all raid directories)\n", (*d).c_str());
-			return 1;
+			BOX_ERROR("Failed to delete files in " << (*d) <<
+				", delete them manually.");
+			retcode = 1;
 		}
 	}
 	
 	// Success!
-	return 0;
+	return retcode;
 }
 
 int CheckAccount(Configuration &rConfig, const std::string &rUsername, int32_t ID, bool FixErrors, bool Quiet)
@@ -346,7 +358,8 @@
 	// Exists?
 	if(!db->EntryExists(ID))
 	{
-		printf("Account %x does not exist\n", ID);
+		BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) << 
+			" does not exist.");
 		return 1;
 	}
 	
@@ -381,7 +394,8 @@
 	// Already exists?
 	if(db->EntryExists(ID))
 	{
-		printf("Account %x already exists\n", ID);
+		BOX_ERROR("Account " << BOX_FORMAT_ACCOUNT(ID) << 
+			" already exists.");
 		return 1;
 	}
 	
@@ -389,7 +403,7 @@
 	BackupStoreAccounts acc(*db);
 	acc.Create(ID, DiscNumber, SoftLimit, HardLimit, rUsername);
 	
-	printf("Account %x created\n", ID);
+	BOX_NOTICE("Account " << BOX_FORMAT_ACCOUNT(ID) << " created.");
 
 	return 0;
 }
@@ -444,7 +458,8 @@
 
 	if(config.get() == 0 || !errs.empty())
 	{
-		printf("Invalid configuration file:\n%s", errs.c_str());
+		BOX_ERROR("Invalid configuration file " << configFilename <<
+			":" << errs);
 	}
 	
 	// Get the user under which the daemon runs
@@ -484,7 +499,8 @@
 		if(argc < 5
 			|| ::sscanf(argv[2], "%d", &discnum) != 1)
 		{
-			printf("create requires raid file disc number, soft and hard limits\n");
+			BOX_ERROR("create requires raid file disc number, "
+				"soft and hard limits.");
 			return 1;
 		}
 		
@@ -506,7 +522,7 @@
 		// Change the limits on this account
 		if(argc < 4)
 		{
-			printf("setlimit requires soft and hard limits\n");
+			BOX_ERROR("setlimit requires soft and hard limits.");
 			return 1;
 		}
 		
@@ -540,7 +556,7 @@
 			}
 			else
 			{
-				::printf("Unknown option %s.\n", argv[o]);
+				BOX_ERROR("Unknown option " << argv[o] << ".");
 				return 2;
 			}
 		}
@@ -550,7 +566,7 @@
 	}
 	else
 	{
-		printf("Unknown command '%s'\n", argv[0]);
+		BOX_ERROR("Unknown command '" << argv[0] << "'.");
 		return 1;
 	}
 

Modified: box/chris/general/lib/backupclient/BackupClientRestore.cpp
===================================================================
--- box/chris/general/lib/backupclient/BackupClientRestore.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/backupclient/BackupClientRestore.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -260,7 +260,11 @@
 		case ObjectExists_File:
 			{
 				// File exists with this name, which is fun. Get rid of it.
-				::printf("WARNING: File present with name '%s', removing out of the way of restored directory. Use specific restore with ID to restore this object.", rLocalDirectoryName.c_str());
+				BOX_WARNING("File present with name '" <<
+					rLocalDirectoryName << "', removing " <<
+					"out of the way of restored directory. "
+					"Use specific restore with ID to "
+					"restore this object.");
 				if(::unlink(rLocalDirectoryName.c_str()) != 0)
 				{
 					BOX_ERROR("Failed to delete file " <<

Modified: box/chris/general/lib/backupstore/BackupStoreCheck.cpp
===================================================================
--- box/chris/general/lib/backupstore/BackupStoreCheck.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/backupstore/BackupStoreCheck.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -102,7 +102,7 @@
 			// Couldn't lock the account -- just stop now
 			if(!mQuiet)
 			{
-				::printf("Couldn't lock the account -- did not check.\nTry again later after the client has disconnected.\nAlternatively, forcibly kill the server.\n");
+				BOX_ERROR("Failed to lock the account -- did not check.\nTry again later after the client has disconnected.\nAlternatively, forcibly kill the server.");
 			}
 			THROW_EXCEPTION(BackupStoreException, CouldNotLockStoreAccount)
 		}
@@ -110,41 +110,43 @@
 
 	if(!mQuiet && mFixErrors)
 	{
-		::printf("NOTE: Will fix errors encountered during checking.\n");
+		BOX_NOTICE("Will fix errors encountered during checking.");
 	}
 
 	// Phase 1, check objects
 	if(!mQuiet)
 	{
-		::printf("Check store account ID %08x\nPhase 1, check objects...\n", mAccountID);
+		BOX_INFO("Checking store account ID " <<
+			BOX_FORMAT_ACCOUNT(mAccountID) << "...");
+		BOX_INFO("Phase 1, check objects...");
 	}
 	CheckObjects();
 	
 	// Phase 2, check directories
 	if(!mQuiet)
 	{
-		::printf("Phase 2, check directories...\n");
+		BOX_INFO("Phase 2, check directories...");
 	}
 	CheckDirectories();
 	
 	// Phase 3, check root
 	if(!mQuiet)
 	{
-		::printf("Phase 3, check root...\n");
+		BOX_INFO("Phase 3, check root...");
 	}
 	CheckRoot();
 
 	// Phase 4, check unattached objects
 	if(!mQuiet)
 	{
-		::printf("Phase 4, fix unattached objects...\n");
+		BOX_INFO("Phase 4, fix unattached objects...");
 	}
 	CheckUnattachedObjects();
 
 	// Phase 5, fix bad info
 	if(!mQuiet)
 	{
-		::printf("Phase 5, fix unrecovered inconsistencies...\n");
+		BOX_INFO("Phase 5, fix unrecovered inconsistencies...");
 	}
 	FixDirsWithWrongContainerID();
 	FixDirsWithLostDirs();
@@ -152,7 +154,7 @@
 	// Phase 6, regenerate store info
 	if(!mQuiet)
 	{
-		::printf("Phase 6, regenerate store info...\n");
+		BOX_INFO("Phase 6, regenerate store info...");
 	}
 	WriteNewStoreInfo();
 	
@@ -160,29 +162,40 @@
 	
 	if(mNumberErrorsFound > 0)
 	{
-		::printf("%lld errors found\n", mNumberErrorsFound);
+		BOX_WARNING("Finished checking store account ID " <<
+			BOX_FORMAT_ACCOUNT(mAccountID) << ": " <<
+			mNumberErrorsFound << " errors found");
 		if(!mFixErrors)
 		{
-			::printf("NOTE: No changes to the store account have been made.\n");
+			BOX_WARNING("No changes to the store account "
+				"have been made.");
 		}
 		if(!mFixErrors && mNumberErrorsFound > 0)
 		{
-			::printf("Run again with fix option to fix these errors\n");
+			BOX_WARNING("Run again with fix option to "
+				"fix these errors");
 		}
-		if(mNumberErrorsFound > 0)
+		if(mFixErrors && mNumberErrorsFound > 0)
 		{
-			::printf("You should now use bbackupquery on the client machine to examine the store.\n");
+			BOX_WARNING("You should now use bbackupquery "
+				"on the client machine to examine the store.");
 			if(mLostAndFoundDirectoryID != 0)
 			{
-				::printf("A lost+found directory was created in the account root.\n"\
-					"This contains files and directories which could not be matched to existing directories.\n"\
-					"bbackupd will delete this directory in a few days time.\n");
+				BOX_WARNING("A lost+found directory was "
+					"created in the account root.\n"
+					"This contains files and directories "
+					"which could not be matched to "
+					"existing directories.\n"\
+					"bbackupd will delete this directory "
+					"in a few days time.");
 			}
 		}
 	}
 	else
 	{
-		::printf("Store account checked, no errors found.\n");
+		BOX_NOTICE("Finished checking store account ID " <<
+			BOX_FORMAT_ACCOUNT(mAccountID) << ": "
+			"no errors found");
 	}
 }
 
@@ -304,7 +317,10 @@
 			}
 			else
 			{
-				::printf("Spurious or invalid directory %s/%s found%s -- delete manually\n", rDirName.c_str(), (*i).c_str(), mFixErrors?", deleting":"");
+				BOX_WARNING("Spurious or invalid directory " <<
+					rDirName << DIRECTORY_SEPARATOR << 
+					(*i) << " found, " <<
+					(mFixErrors?"deleting":"delete manually"));
 				++mNumberErrorsFound;
 			}
 		}
@@ -336,7 +352,7 @@
 	// Check directory exists
 	if(!RaidFileRead::DirectoryExists(mDiscSetNumber, dirName))
 	{
-		TRACE1("RaidFile dir %s does not exist\n", dirName.c_str());
+		BOX_WARNING("RaidFile dir " << dirName << " does not exist");
 		return;
 	}
 
@@ -378,9 +394,9 @@
 		if(!fileOK)
 		{
 			// Unexpected or bad file, delete it
-			::printf("Spurious file %s" DIRECTORY_SEPARATOR "%s "
-				"found%s\n", dirName.c_str(), (*i).c_str(), 
-				mFixErrors?", deleting":"");
+			BOX_WARNING("Spurious file " << dirName << 
+				DIRECTORY_SEPARATOR << (*i) << " found" <<
+				(mFixErrors?", deleting":""));
 			++mNumberErrorsFound;
 			if(mFixErrors)
 			{
@@ -401,7 +417,9 @@
 			if(!CheckAndAddObject(StartID | i, dirName + leaf))
 			{
 				// File was bad, delete it
-				::printf("Corrupted file %s%s found%s\n", dirName.c_str(), leaf, mFixErrors?", deleting":"");
+				BOX_WARNING("Corrupted file " << dirName <<
+					leaf << " found" <<
+					(mFixErrors?", deleting":""));
 				++mNumberErrorsFound;
 				if(mFixErrors)
 				{
@@ -509,7 +527,7 @@
 	if(ObjectID == BACKUPSTORE_ROOT_DIRECTORY_ID)
 	{
 		// Get that dodgy thing deleted!
-		::printf("Have file as root directory. This is bad.\n");
+		BOX_ERROR("Have file as root directory. This is bad.");
 		return -1;
 	}
 
@@ -596,7 +614,9 @@
 				if(dir.CheckAndFix())
 				{
 					// Wasn't quite right, and has been modified
-					::printf("Directory ID %llx has bad structure\n", pblock->mID[e]);
+					BOX_WARNING("Directory ID " <<
+						BOX_FORMAT_OBJECTID(pblock->mID[e]) <<
+						" has bad structure");
 					++mNumberErrorsFound;
 					isModified = true;
 				}
@@ -622,7 +642,11 @@
 							!= ((en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir) == BackupStoreDirectory::Entry::Flags_Dir))
 						{
 							// Entry is of wrong type
-							::printf("Directory ID %llx references object %llx which has a different type than expected.\n", pblock->mID[e], en->GetObjectID());
+							BOX_WARNING("Directory ID " <<
+								BOX_FORMAT_OBJECTID(pblock->mID[e]) <<
+								" references object " <<
+								BOX_FORMAT_OBJECTID(en->GetObjectID()) <<
+								" which has a different type than expected.");
 							badEntry = true;
 						}
 						else
@@ -630,8 +654,12 @@
 							// Check that the entry is not already contained.
 							if(iflags & Flags_IsContained)
 							{
+								BOX_WARNING("Directory ID " <<
+									BOX_FORMAT_OBJECTID(pblock->mID[e]) <<
+									" references object " <<
+									BOX_FORMAT_OBJECTID(en->GetObjectID()) <<
+									" which is already contained.");
 								badEntry = true;
-								::printf("Directory ID %llx references object %llx which is already contained.\n", pblock->mID[e], en->GetObjectID());
 							}
 							else
 							{
@@ -645,13 +673,13 @@
 									if(iflags & Flags_IsDir)
 									{
 										// Add to will fix later list
-										::printf("Directory ID %llx has wrong container ID.\n", en->GetObjectID());
+										BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " has wrong container ID.");
 										mDirsWithWrongContainerID.push_back(en->GetObjectID());
 									}
 									else
 									{
 										// This is OK for files, they might move
-										::printf("File ID %llx has different container ID, probably moved\n", en->GetObjectID());
+										BOX_WARNING("File ID " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " has different container ID, probably moved");
 									}
 									
 									// Fix entry for now
@@ -670,7 +698,7 @@
 								// Mark as changed
 								isModified = true;
 								// Tell user
-								::printf("Directory ID %llx has wrong size for object %llx\n", pblock->mID[e], en->GetObjectID());
+								BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(pblock->mID[e]) << " has wrong size for object " << BOX_FORMAT_OBJECTID(en->GetObjectID()));
 							}
 						}
 					}
@@ -686,7 +714,7 @@
 						{
 							// Just remove the entry
 							badEntry = true;
-							::printf("Directory ID %llx references object %llx which does not exist.\n", pblock->mID[e], en->GetObjectID());
+							BOX_WARNING("Directory ID " << BOX_FORMAT_OBJECTID(pblock->mID[e]) << " references object " << BOX_FORMAT_OBJECTID(en->GetObjectID()) << " which does not exist.");
 						}
 					}
 					
@@ -729,7 +757,7 @@
 				
 				if(isModified && mFixErrors)
 				{	
-					::printf("Fixing directory ID %llx\n", pblock->mID[e]);
+					BOX_WARNING("Fixing directory ID " << BOX_FORMAT_OBJECTID(pblock->mID[e]));
 
 					// Save back to disc
 					RaidFileWrite fixed(mDiscSetNumber, filename);

Modified: box/chris/general/lib/backupstore/BackupStoreCheck2.cpp
===================================================================
--- box/chris/general/lib/backupstore/BackupStoreCheck2.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/backupstore/BackupStoreCheck2.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -47,7 +47,7 @@
 	}
 	else
 	{
-		::printf("Root directory doesn't exist\n");
+		BOX_WARNING("Root directory doesn't exist");
 		
 		++mNumberErrorsFound;
 		
@@ -118,7 +118,7 @@
 			if((flags & Flags_IsContained) == 0)
 			{
 				// Unattached object...
-				::printf("Object %llx is unattached.\n", pblock->mID[e]);
+				BOX_WARNING("Object " << BOX_FORMAT_OBJECTID(pblock->mID[e]) << " is unattached.");
 				++mNumberErrorsFound;
 
 				// What's to be done?
@@ -147,7 +147,7 @@
 						// Just delete it to be safe.
 						if(diffFromObjectID != 0)
 						{
-							::printf("Object %llx is unattached, and is a patch. Deleting, cannot reliably recover.\n", pblock->mID[e]);
+							BOX_WARNING("Object " << BOX_FORMAT_OBJECTID(pblock->mID[e]) << " is unattached, and is a patch. Deleting, cannot reliably recover.");
 						
 							// Delete this object instead
 							if(mFixErrors)
@@ -229,11 +229,15 @@
 	// Can recreate this! Wooo!
 	if(!mFixErrors)
 	{
-		::printf("Missing directory %llx could be recreated\n", MissingDirectoryID);
+		BOX_WARNING("Missing directory " << 
+			BOX_FORMAT_OBJECTID(MissingDirectoryID) <<
+			" could be recreated.");
 		mDirsAdded.insert(MissingDirectoryID);
 		return true;
 	}
-	::printf("Recreating missing directory %llx\n", MissingDirectoryID);
+
+	BOX_WARNING("Recreating missing directory " << 
+		BOX_FORMAT_OBJECTID(MissingDirectoryID));
 	
 	// Create a blank directory
 	BackupStoreDirectory dir(MissingDirectoryID, missing->second /* containing dir ID */);
@@ -300,7 +304,7 @@
 		if(!dir.NameInUse(lostAndFound))
 		{
 			// Found a name which can be used
-			::printf("Lost and found dir has name %s\n", name);
+			BOX_WARNING("Lost and found dir has name " << name);
 			break;
 		}
 	}
@@ -524,7 +528,7 @@
 	}
 	catch(...)
 	{
-		::printf("Load of existing store info failed, regenerating.\n");
+		BOX_WARNING("Load of existing store info failed, regenerating.");
 		++mNumberErrorsFound;
 	}
 
@@ -551,7 +555,7 @@
 	}
 	else
 	{
-		::printf("NOTE: Soft limit for account changed to ensure housekeeping doesn't delete files on next run\n");
+		BOX_WARNING("Soft limit for account changed to ensure housekeeping doesn't delete files on next run.");
 	}
 	if(poldInfo.get() != 0 && poldInfo->GetBlocksHardLimit() > minHard)
 	{
@@ -559,7 +563,7 @@
 	}
 	else
 	{
-		::printf("NOTE: Hard limit for account changed to ensure housekeeping doesn't delete files on next run\n");
+		BOX_WARNING("Hard limit for account changed to ensure housekeeping doesn't delete files on next run.");
 	}
 	
 	// Object ID
@@ -586,7 +590,7 @@
 	if(mFixErrors)
 	{
 		info->Save();
-		::printf("New store info file written successfully.\n");
+		BOX_NOTICE("New store info file written successfully.");
 	}
 }
 

Modified: box/chris/general/lib/common/DebugMemLeakFinder.cpp
===================================================================
--- box/chris/general/lib/common/DebugMemLeakFinder.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/common/DebugMemLeakFinder.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -374,7 +374,8 @@
 	}
 	else
 	{
-		printf("WARNING: Couldn't open memory leak results file %s for appending\n", filename);
+		BOX_WARNING("Couldn't open memory leak results file " <<
+			filename << " for appending");
 	}
 }
 

Modified: box/chris/general/lib/common/Logging.cpp
===================================================================
--- box/chris/general/lib/common/Logging.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/common/Logging.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -243,6 +243,23 @@
 	{
 		msg += "[" + sTag + "] ";
 	}
+
+	if (level <= Log::FATAL)
+	{
+		msg += "FATAL: ";
+	}
+	else if (level <= Log::ERROR)
+	{
+		msg += "ERROR: ";
+	}
+	else if (level <= Log::WARNING)
+	{
+		msg += "WARNING: ";
+	}
+	else if (level <= Log::NOTICE)
+	{
+		msg += "NOTICE: ";
+	}
 	
 	msg += rMessage;
 
@@ -272,8 +289,29 @@
 		case Log::TRACE:      /* fall through */
 		case Log::EVERYTHING: syslogLevel = LOG_DEBUG;   break;
 	}
-		
-	syslog(syslogLevel, "%s", rMessage.c_str());
+
+	std::string msg;
+
+	if (level <= Log::FATAL)
+	{
+		msg = "FATAL: ";
+	}
+	else if (level <= Log::ERROR)
+	{
+		msg = "ERROR: ";
+	}
+	else if (level <= Log::WARNING)
+	{
+		msg = "WARNING: ";
+	}
+	else if (level <= Log::NOTICE)
+	{
+		msg = "NOTICE: ";
+	}
+
+	msg += rMessage;
+
+	syslog(syslogLevel, "%s", msg.c_str());
 	
 	return true;
 }

Modified: box/chris/general/lib/crypto/Random.cpp
===================================================================
--- box/chris/general/lib/crypto/Random.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/crypto/Random.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -34,7 +34,8 @@
 		THROW_EXCEPTION(CipherException, RandomInitFailed)
 	}
 #else
-	::fprintf(stderr, "No random device -- additional seeding of random number generator not performed.\n");
+	BOX_ERROR("No random device -- additional seeding of random number "
+		"generator not performed.");
 #endif
 }
 

Modified: box/chris/general/lib/raidfile/RaidFileController.cpp
===================================================================
--- box/chris/general/lib/raidfile/RaidFileController.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/raidfile/RaidFileController.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -102,8 +102,7 @@
 	
 	if(pconfig.get() == 0 || !err.empty())
 	{
-		fprintf(stderr, "RaidFile configuation file errors:\n%s",
-			err.c_str());
+		BOX_ERROR("RaidFile configuration file errors: " << err);
 		THROW_EXCEPTION(RaidFileException, BadConfigFile)
 	}
 	

Modified: box/chris/general/lib/server/SSLLib.cpp
===================================================================
--- box/chris/general/lib/server/SSLLib.cpp	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/lib/server/SSLLib.cpp	2007-08-02 23:29:31 UTC (rev 1790)
@@ -49,7 +49,8 @@
 		THROW_EXCEPTION(ServerException, SSLRandomInitFailed)
 	}
 #else
-	::fprintf(stderr, "No random device -- additional seeding of random number generator not performed.\n");
+	BOX_WARNING("No random device -- additional seeding of "
+		"random number generator not performed.");
 #endif
 }
 

Modified: box/chris/general/test/bbackupd/testfiles/extcheck1.pl.in
===================================================================
--- box/chris/general/test/bbackupd/testfiles/extcheck1.pl.in	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/test/bbackupd/testfiles/extcheck1.pl.in	2007-08-02 23:29:31 UTC (rev 1790)
@@ -3,7 +3,7 @@
 
 my $flags = $ARGV[0] or "";
 
-unless(open IN,"../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query4.log \"compare -ac$flags\" quit|")
+unless(open IN,"../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query4.log \"compare -ac$flags\" quit 2>&1 |")
 {
 	print "Couldn't open compare utility\n";
 	exit 2;

Modified: box/chris/general/test/bbackupd/testfiles/extcheck2.pl.in
===================================================================
--- box/chris/general/test/bbackupd/testfiles/extcheck2.pl.in	2007-08-02 23:28:17 UTC (rev 1789)
+++ box/chris/general/test/bbackupd/testfiles/extcheck2.pl.in	2007-08-02 23:29:31 UTC (rev 1790)
@@ -3,7 +3,7 @@
 
 my $flags = $ARGV[0] or "";
 
-unless(open IN,"../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query4.log \"compare -ac$flags\" quit|")
+unless(open IN,"../../bin/bbackupquery/bbackupquery -q -c testfiles/bbackupd.conf -l testfiles/query4.log \"compare -ac$flags\" quit 2>&1 |")
 {
 	print "Couldn't open compare utility\n";
 	exit 2;




More information about the Boxbackup-commit mailing list