diff options
author | Chris Wilson <chris+github@qwirx.com> | 2007-08-02 23:28:17 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2007-08-02 23:28:17 +0000 |
commit | 747589f03a1ba61273d21ed6446ad47841a1f46a (patch) | |
tree | c354364468b80aaf25b4522ebbe5e45a97911822 /lib | |
parent | c0f0b74c04054ddab5610cba9d2268c04c6a7e9f (diff) |
Convert most printf() and fprintf() calls to use logging framework
instead. (refs #3)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backupclient/BackupClientRestore.cpp | 6 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreCheck.cpp | 92 | ||||
-rw-r--r-- | lib/backupstore/BackupStoreCheck2.cpp | 24 | ||||
-rw-r--r-- | lib/common/DebugMemLeakFinder.cpp | 3 | ||||
-rw-r--r-- | lib/common/Logging.cpp | 42 | ||||
-rw-r--r-- | lib/crypto/Random.cpp | 3 | ||||
-rw-r--r-- | lib/raidfile/RaidFileController.cpp | 3 | ||||
-rw-r--r-- | lib/server/SSLLib.cpp | 3 |
8 files changed, 126 insertions, 50 deletions
diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp index 92853624..3c03c87c 100644 --- a/lib/backupclient/BackupClientRestore.cpp +++ b/lib/backupclient/BackupClientRestore.cpp @@ -260,7 +260,11 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection, int64_t Dir 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 " << diff --git a/lib/backupstore/BackupStoreCheck.cpp b/lib/backupstore/BackupStoreCheck.cpp index 16eeecf9..176ece8f 100644 --- a/lib/backupstore/BackupStoreCheck.cpp +++ b/lib/backupstore/BackupStoreCheck.cpp @@ -102,7 +102,7 @@ void BackupStoreCheck::Check() // 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 @@ void BackupStoreCheck::Check() 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 @@ void BackupStoreCheck::Check() // 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 @@ void BackupStoreCheck::Check() 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 @@ int64_t BackupStoreCheck::CheckObjectsScanDir(int64_t StartID, int Level, const } 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 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID) // 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 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID) 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 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID) 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 @@ int64_t BackupStoreCheck::CheckFile(int64_t ObjectID, IOStream &rStream) 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 @@ void BackupStoreCheck::CheckDirectories() 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 @@ void BackupStoreCheck::CheckDirectories() != ((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 @@ void BackupStoreCheck::CheckDirectories() // 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 @@ void BackupStoreCheck::CheckDirectories() 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 @@ void BackupStoreCheck::CheckDirectories() // 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 @@ void BackupStoreCheck::CheckDirectories() { // 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 @@ void BackupStoreCheck::CheckDirectories() 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); diff --git a/lib/backupstore/BackupStoreCheck2.cpp b/lib/backupstore/BackupStoreCheck2.cpp index 7bc9a109..9c6f2452 100644 --- a/lib/backupstore/BackupStoreCheck2.cpp +++ b/lib/backupstore/BackupStoreCheck2.cpp @@ -47,7 +47,7 @@ void BackupStoreCheck::CheckRoot() } else { - ::printf("Root directory doesn't exist\n"); + BOX_WARNING("Root directory doesn't exist"); ++mNumberErrorsFound; @@ -118,7 +118,7 @@ void BackupStoreCheck::CheckUnattachedObjects() 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 @@ void BackupStoreCheck::CheckUnattachedObjects() // 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 @@ bool BackupStoreCheck::TryToRecreateDirectory(int64_t MissingDirectoryID) // 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 @@ int64_t BackupStoreCheck::GetLostAndFoundDirID() 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 @@ void BackupStoreCheck::WriteNewStoreInfo() } catch(...) { - ::printf("Load of existing store info failed, regenerating.\n"); + BOX_WARNING("Load of existing store info failed, regenerating."); ++mNumberErrorsFound; } @@ -551,7 +555,7 @@ void BackupStoreCheck::WriteNewStoreInfo() } 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 @@ void BackupStoreCheck::WriteNewStoreInfo() } 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 @@ void BackupStoreCheck::WriteNewStoreInfo() if(mFixErrors) { info->Save(); - ::printf("New store info file written successfully.\n"); + BOX_NOTICE("New store info file written successfully."); } } diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp index a99b2072..e9b0e681 100644 --- a/lib/common/DebugMemLeakFinder.cpp +++ b/lib/common/DebugMemLeakFinder.cpp @@ -374,7 +374,8 @@ void memleakfinder_reportleaks_appendfile(const char *filename, const char *mark } 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"); } } diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index eee05ba3..d22db238 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -243,6 +243,23 @@ bool Console::Log(Log::Level level, const std::string& rFile, { 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 @@ bool Syslog::Log(Log::Level level, const std::string& rFile, 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; } diff --git a/lib/crypto/Random.cpp b/lib/crypto/Random.cpp index 30049ff7..1d6a07f0 100644 --- a/lib/crypto/Random.cpp +++ b/lib/crypto/Random.cpp @@ -34,7 +34,8 @@ void Random::Initialise() 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 } diff --git a/lib/raidfile/RaidFileController.cpp b/lib/raidfile/RaidFileController.cpp index 81307103..0cc2ede7 100644 --- a/lib/raidfile/RaidFileController.cpp +++ b/lib/raidfile/RaidFileController.cpp @@ -102,8 +102,7 @@ void RaidFileController::Initialise(const std::string& rConfigFilename) 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) } diff --git a/lib/server/SSLLib.cpp b/lib/server/SSLLib.cpp index 6082a9f4..e9c990b9 100644 --- a/lib/server/SSLLib.cpp +++ b/lib/server/SSLLib.cpp @@ -49,7 +49,8 @@ void SSLLib::Initialise() 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 } |