From 2e761f8a7744f18059e2048f319f4cac8e32d765 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 29 Mar 2008 01:56:39 +0000 Subject: Replace all remaining use of TRACEx() macros with logging framework. Remove the old TRACEx macros to catch any remaining uses. --- lib/backupclient/BackupStoreFileDiff.cpp | 36 +++++++++++++++++++-------- lib/backupclient/BackupStoreFilenameClear.cpp | 6 +++-- lib/backupclient/BackupStoreObjectDump.cpp | 10 +++++--- lib/backupstore/BackupStoreCheck.cpp | 3 ++- lib/backupstore/BackupStoreCheck2.cpp | 35 ++++++++++++++++++++------ lib/backupstore/BackupStoreCheckData.cpp | 13 ++++++---- lib/common/Box.h | 19 -------------- lib/common/Configuration.cpp | 4 +-- lib/common/DebugMemLeakFinder.cpp | 19 ++++++++++---- lib/common/Logging.h | 7 ++++-- lib/common/PartialReadStream.cpp | 3 ++- lib/common/Utils.cpp | 4 +-- lib/compress/Compress.h | 8 +++--- lib/compress/CompressStream.cpp | 2 +- lib/crypto/CipherContext.cpp | 12 ++++++--- lib/intercept/intercept.cpp | 10 ++++---- lib/raidfile/RaidFileWrite.cpp | 8 +++--- lib/server/ProtocolUncertainStream.cpp | 3 ++- 18 files changed, 123 insertions(+), 79 deletions(-) (limited to 'lib') diff --git a/lib/backupclient/BackupStoreFileDiff.cpp b/lib/backupclient/BackupStoreFileDiff.cpp index f7842a0b..d550e2ba 100644 --- a/lib/backupclient/BackupStoreFileDiff.cpp +++ b/lib/backupclient/BackupStoreFileDiff.cpp @@ -149,7 +149,7 @@ std::auto_ptr BackupStoreFile::EncodeFileDiff int64_t blocksInIndex = 0; bool canDiffFromThis = false; LoadIndex(rDiffFromBlockIndex, DiffFromObjectID, &pindex, blocksInIndex, Timeout, canDiffFromThis); - //TRACE1("Diff: Blocks in index: %lld\n", blocksInIndex); + // BOX_TRACE("Diff: Blocks in index: " << blocksInIndex); if(!canDiffFromThis) { @@ -439,7 +439,9 @@ static void FindMostUsedSizes(BlocksAvailableEntry *pIndex, int64_t NumBlocks, i { for(int t = 0; t < BACKUP_FILE_DIFF_MAX_BLOCK_SIZES; ++t) { - TRACE3("Diff block size %d: %d (count = %lld)\n", t, Sizes[t], sizeCounts[t]); + BOX_TRACE("Diff block size " << t << ": " << + Sizes[t] << " (count = " << + sizeCounts[t] << ")"); } } #endif @@ -774,7 +776,7 @@ static void SetupHashTable(BlocksAvailableEntry *pIndex, int64_t NumBlocks, int3 // Already present in table? if(pHashTable[hash] != 0) { - //TRACE1("Another hash entry for %d found\n", hash); + //BOX_TRACE("Another hash entry for " << hash << " found"); // Yes -- need to set the pointer in this entry to the current entry to build the linked list pIndex[b].mpNextInHashList = pHashTable[hash]; } @@ -840,17 +842,19 @@ static bool SecondStageMatch(BlocksAvailableEntry *pFirstInHashList, RollingChec // Then go through the entries in the hash list, comparing with the strong digest calculated scan = pFirstInHashList; - //TRACE0("second stage match\n"); + //BOX_TRACE("second stage match"); while(scan != 0) { - //TRACE3("scan size %d, block size %d, hash %d\n", scan->mSize, BlockSize, Hash); + //BOX_TRACE("scan size " << scan->mSize << + // ", block size " << BlockSize << + // ", hash " << Hash); ASSERT(scan->mSize == BlockSize); ASSERT(RollingChecksum::ExtractHashingComponent(scan->mWeakChecksum) == DEBUG_Hash); // Compare? if(strong.DigestMatches(scan->mStrongChecksum)) { - //TRACE0("Match!\n"); + //BOX_TRACE("Match!\n"); // Found! Add to list of found blocks... int64_t fileOffset = (FileBlockNumber * BlockSize) + Offset; int64_t blockIndex = (scan - pIndex); // pointer arthmitic is frowned upon. But most efficient way of doing it here -- alternative is to use more memory @@ -912,7 +916,8 @@ static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksA #ifndef NDEBUG if(BackupStoreFile::TraceDetailsOfDiffProcess) { - TRACE1("Diff: Default recipe generated, %lld bytes of file\n", SizeOfInputFile); + BOX_TRACE("Diff: Default recipe generated, " << + SizeOfInputFile << " bytes of file"); } #endif @@ -1005,10 +1010,14 @@ static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksA // dump out the recipe #ifndef NDEBUG - TRACE2("Diff: %lld new bytes found, %lld old blocks used\n", debug_NewBytesFound, debug_OldBlocksUsed); + BOX_TRACE("Diff: " << + debug_NewBytesFound << " new bytes found, " << + debug_OldBlocksUsed << " old blocks used"); if(BackupStoreFile::TraceDetailsOfDiffProcess) { - TRACE1("Diff: Recipe generated (size %d)\n======== ========= ========\nSpace b4 FirstBlk NumBlks\n", rRecipe.size()); + BOX_TRACE("Diff: Recipe generated (size " << rRecipe.size()); + BOX_TRACE("======== ========= ========"); + BOX_TRACE("Space b4 FirstBlk NumBlks"); { for(unsigned int e = 0; e < rRecipe.size(); ++e) { @@ -1018,10 +1027,15 @@ static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksA #else sprintf(b, "%8lld", (int64_t)(rRecipe[e].mpStartBlock - pIndex)); #endif - TRACE3("%8lld %s %8lld\n", rRecipe[e].mSpaceBefore, (rRecipe[e].mpStartBlock == 0)?" -":b, (int64_t)rRecipe[e].mBlocks); + BOX_TRACE(std::setw(8) << + rRecipe[e].mSpaceBefore << + " " << + ((rRecipe[e].mpStartBlock == 0)?" -":b) << + " " << std::setw(8) << + rRecipe[e].mBlocks); } } - TRACE0("======== ========= ========\n"); + BOX_TRACE("======== ========= ========"); } #endif } diff --git a/lib/backupclient/BackupStoreFilenameClear.cpp b/lib/backupclient/BackupStoreFilenameClear.cpp index 9114fdd1..cf168bfc 100644 --- a/lib/backupclient/BackupStoreFilenameClear.cpp +++ b/lib/backupclient/BackupStoreFilenameClear.cpp @@ -167,7 +167,8 @@ void BackupStoreFilenameClear::MakeClearAvailable() const switch(encoding) { case Encoding_Clear: - TRACE0("**** BackupStoreFilename encoded with Clear encoding ****\n"); + BOX_TRACE("**** BackupStoreFilename encoded with " + "Clear encoding ****"); mClearFilename.assign(c_str() + 2, size - 2); break; @@ -193,7 +194,8 @@ static void EnsureEncDecBufferSize(int BufSize) if(spEncDecBuffer == 0) { #ifndef WIN32 - TRACE1("Allocating filename encoding/decoding buffer with size %d\n", BufSize); + BOX_TRACE("Allocating filename encoding/decoding buffer " + "with size " << BufSize); #endif spEncDecBuffer = new MemoryBlockGuard(BufSize); MEMLEAKFINDER_NOT_A_LEAK(spEncDecBuffer); diff --git a/lib/backupclient/BackupStoreObjectDump.cpp b/lib/backupclient/BackupStoreObjectDump.cpp index d3d9cc17..0ad044bb 100644 --- a/lib/backupclient/BackupStoreObjectDump.cpp +++ b/lib/backupclient/BackupStoreObjectDump.cpp @@ -47,7 +47,7 @@ static void OutputLine(FILE *file, bool ToTrace, const char *format, ...) } if(ToTrace) { - TRACE1("%s", text); + BOX_TRACE(text); } } @@ -211,14 +211,16 @@ void BackupStoreFile::DumpFile(void *clibFileHandle, bool ToTrace, IOStream &rFi if(s > 0) { nnew++; - TRACE2("%8lld this s=%8lld\n", b, s); + BOX_TRACE(std::setw(8) << b << " this s=" << + std::setw(8) << s); } else { nold++; - TRACE2("%8lld other i=%8lld\n", b, 0 - s); + BOX_TRACE(std::setw(8) << b << " other i=" << + std::setw(8) << 0 - s); } } - TRACE0("======== ===== ==========\n"); + BOX_TRACE("======== ===== =========="); } diff --git a/lib/backupstore/BackupStoreCheck.cpp b/lib/backupstore/BackupStoreCheck.cpp index 176ece8f..7598094e 100644 --- a/lib/backupstore/BackupStoreCheck.cpp +++ b/lib/backupstore/BackupStoreCheck.cpp @@ -268,7 +268,8 @@ void BackupStoreCheck::CheckObjects() } maxDir = CheckObjectsScanDir(0, 1, mStoreRoot); - TRACE1("Max dir starting ID is %llx\n", maxDir); + BOX_TRACE("Max dir starting ID is " << + BOX_FORMAT_OBJECTID(maxDir)); } // Then go through and scan all the objects within those directories diff --git a/lib/backupstore/BackupStoreCheck2.cpp b/lib/backupstore/BackupStoreCheck2.cpp index 9c6f2452..40d34a5b 100644 --- a/lib/backupstore/BackupStoreCheck2.cpp +++ b/lib/backupstore/BackupStoreCheck2.cpp @@ -594,6 +594,8 @@ void BackupStoreCheck::WriteNewStoreInfo() } } +#define FMT_OID(x) BOX_FORMAT_OBJECTID(x) +#define FMT_i BOX_FORMAT_OBJECTID((*i)->GetObjectID()) // -------------------------------------------------------------------------- // @@ -620,7 +622,11 @@ bool BackupStoreDirectory::CheckAndFix() if(newerEn == 0) { // Depends on something, but it isn't there. - TRACE2("Entry id %llx removed because depends on newer version %llx which doesn't exist\n", (*i)->GetObjectID(), dependsNewer); + BOX_TRACE("Entry id " << FMT_i << + " removed because depends " + "on newer version " << + FMT_OID(dependsNewer) << + " which doesn't exist"); // Remove delete *i; @@ -638,7 +644,12 @@ bool BackupStoreDirectory::CheckAndFix() if(newerEn->GetDependsOlder() != (*i)->GetObjectID()) { // Wrong entry - TRACE3("Entry id %llx, correcting DependsOlder to %llx, was %llx\n", dependsNewer, (*i)->GetObjectID(), newerEn->GetDependsOlder()); + BOX_TRACE("Entry id " << + FMT_OID(dependsNewer) << + ", correcting DependsOlder to " << + FMT_i << + ", was " << + FMT_OID(newerEn->GetDependsOlder())); newerEn->SetDependsOlder((*i)->GetObjectID()); // Mark as changed changed = true; @@ -657,7 +668,11 @@ bool BackupStoreDirectory::CheckAndFix() if(dependsOlder != 0 && FindEntryByID(dependsOlder) == 0) { // Has an older version marked, but this doesn't exist. Remove this mark - TRACE2("Entry id %llx was marked that %llx depended on it, which doesn't exist, dependency info cleared\n", (*i)->GetObjectID(), dependsOlder); + BOX_TRACE("Entry id " << FMT_i << + " was marked as depended on by " << + FMT_OID(dependsOlder) << ", " + "which doesn't exist, dependency " + "info cleared"); (*i)->SetDependsOlder(0); @@ -693,7 +708,7 @@ bool BackupStoreDirectory::CheckAndFix() bool removeEntry = false; if((*i) == 0) { - TRACE0("Remove because null pointer found\n"); + BOX_TRACE("Remove because null pointer found"); removeEntry = true; } else @@ -704,7 +719,8 @@ bool BackupStoreDirectory::CheckAndFix() if(isDir && (((*i)->GetFlags() & Entry::Flags_File) == Entry::Flags_File)) { // Bad! Unset the file flag - TRACE1("Entry %llx: File flag set when dir flag set\n", (*i)->GetObjectID()); + BOX_TRACE("Entry " << FMT_i << + ": File flag and dir flag both set"); (*i)->RemoveFlags(Entry::Flags_File); changed = true; } @@ -713,7 +729,8 @@ bool BackupStoreDirectory::CheckAndFix() if(idsEncountered.find((*i)->GetObjectID()) != idsEncountered.end()) { // ID already seen, or type doesn't match - TRACE1("Entry %llx: Remove because ID already seen\n", (*i)->GetObjectID()); + BOX_TRACE("Entry " << FMT_i << + ": Remove because ID already seen"); removeEntry = true; } else @@ -730,7 +747,8 @@ bool BackupStoreDirectory::CheckAndFix() && ((*i)->GetFlags() & Entry::Flags_Deleted) == 0) { // Not set, set it - TRACE1("Entry %llx: Set old flag\n", (*i)->GetObjectID()); + BOX_TRACE("Entry " << FMT_i << + ": Set old flag"); (*i)->AddFlags(Entry::Flags_OldVersion); changed = true; } @@ -741,7 +759,8 @@ bool BackupStoreDirectory::CheckAndFix() if(((*i)->GetFlags() & Entry::Flags_OldVersion) == Entry::Flags_OldVersion) { // Set, unset it - TRACE1("Entry %llx: Old flag unset\n", (*i)->GetObjectID()); + BOX_TRACE("Entry " << FMT_i << + ": Old flag unset"); (*i)->RemoveFlags(Entry::Flags_OldVersion); changed = true; } diff --git a/lib/backupstore/BackupStoreCheckData.cpp b/lib/backupstore/BackupStoreCheckData.cpp index f22c8339..aeb96173 100644 --- a/lib/backupstore/BackupStoreCheckData.cpp +++ b/lib/backupstore/BackupStoreCheckData.cpp @@ -189,15 +189,18 @@ void BackupStoreCheck::DumpObjectInfo() { IDBlock *pblock = i->second; int32_t bentries = (pblock == mpInfoLastBlock)?mInfoLastBlockEntries:BACKUPSTORECHECK_BLOCK_SIZE; - TRACE2("BLOCK @ 0x%08x, %d entries\n", pblock, bentries); + BOX_TRACE("BLOCK @ " << BOX_FORMAT_HEX32(pblock) << + ", " << bentries << " entries"); for(int e = 0; e < bentries; ++e) { uint8_t flags = GetFlags(pblock, e); - TRACE4("id %llx, c %llx, %s, %s\n", - pblock->mID[e], pblock->mContainer[e], - (flags & Flags_IsDir)?"dir":"file", - (flags & Flags_IsContained)?"contained":"unattached"); + BOX_TRACE(std::hex << + "id " << pblock->mID[e] << + ", c " << pblock->mContainer[e] << + ", " << ((flags & Flags_IsDir)?"dir":"file") << + ", " << ((flags & Flags_IsContained) ? + "contained":"unattached")); } } } diff --git a/lib/common/Box.h b/lib/common/Box.h index d0e7ab1e..dd91dfe2 100644 --- a/lib/common/Box.h +++ b/lib/common/Box.h @@ -52,15 +52,6 @@ extern bool BoxDebugTraceOn; int BoxDebug_printf(const char *format, ...); int BoxDebugTrace(const char *format, ...); - #define TRACE0(msg) {BoxDebugTrace("%s", msg);} - #define TRACE1(msg, a0) {BoxDebugTrace(msg, a0);} - #define TRACE2(msg, a0, a1) {BoxDebugTrace(msg, a0, a1);} - #define TRACE3(msg, a0, a1, a2) {BoxDebugTrace(msg, a0, a1, a2);} - #define TRACE4(msg, a0, a1, a2, a3) {BoxDebugTrace(msg, a0, a1, a2, a3);} - #define TRACE5(msg, a0, a1, a2, a3, a4) {BoxDebugTrace(msg, a0, a1, a2, a3, a4);} - #define TRACE6(msg, a0, a1, a2, a3, a4, a5) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5);} - #define TRACE7(msg, a0, a1, a2, a3, a4, a5, a6) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5, a6);} - #define TRACE8(msg, a0, a1, a2, a3, a4, a5, a6, a7) {BoxDebugTrace(msg, a0, a1, a2, a3, a4, a5, a6, a7);} #ifndef PLATFORM_DISABLE_MEM_LEAK_TESTING #define BOX_MEMORY_LEAK_TESTING @@ -76,16 +67,6 @@ #define TRACE_TO_SYSLOG(x) {} #define TRACE_TO_STDOUT(x) {} - #define TRACE0(msg) - #define TRACE1(msg, a0) - #define TRACE2(msg, a0, a1) - #define TRACE3(msg, a0, a1, a2) - #define TRACE4(msg, a0, a1, a2, a3) - #define TRACE5(msg, a0, a1, a2, a3, a4) - #define TRACE6(msg, a0, a1, a2, a3, a4, a5) - #define TRACE7(msg, a0, a1, a2, a3, a4, a5, a6) - #define TRACE8(msg, a0, a1, a2, a3, a4, a5, a6, a7) - // Box Backup builds release get extra information for exception logging #define EXCEPTION_CODENAMES_EXTENDED #define EXCEPTION_CODENAMES_EXTENDED_WITH_DESCRIPTION diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp index f797f454..10e06680 100644 --- a/lib/common/Configuration.cpp +++ b/lib/common/Configuration.cpp @@ -208,8 +208,8 @@ std::auto_ptr Configuration::LoadAndVerify( if(!rErrorMsg.empty()) { // An error occured, return now - //TRACE1("Error message from LoadInto: %s", rErrorMsg.c_str()); - TRACE0("Error at Configuration::LoadInfo\n"); + BOX_ERROR("Error in Configuration::LoadInfo: " << + rErrorMsg); delete pconfig; pconfig = 0; return std::auto_ptr(0); diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp index 87cdf00d..094820b3 100644 --- a/lib/common/DebugMemLeakFinder.cpp +++ b/lib/common/DebugMemLeakFinder.cpp @@ -146,7 +146,9 @@ void *memleakfinder_realloc(void *ptr, size_t size) std::map::iterator i(sMallocBlocks.find(ptr)); if(ptr && i == sMallocBlocks.end()) { - TRACE1("Block %x realloc(), but not in list. Error? Or allocated in startup static objects?\n", ptr); + BOX_WARNING("Block " << ptr << " realloc()ated, but not " + "in list. Error? Or allocated in startup static " + "objects?"); } void *b = ::realloc(ptr, size); @@ -193,7 +195,9 @@ void memleakfinder_free(void *ptr) } else { - TRACE1("Block %p freed, but not known. Error? Or allocated in startup static allocation?\n", ptr); + BOX_WARNING("Block " << ptr << " freed, but not " + "known. Error? Or allocated in startup " + "static allocation?"); } if(sTrackMallocInSection) @@ -293,16 +297,21 @@ void memleakfinder_traceblocksinsection() std::map::const_iterator i(sMallocBlocks.find(*s)); if(i == sMallocBlocks.end()) { - TRACE0("Logical error in section block finding\n"); + BOX_WARNING("Logical error in section block finding"); } else { - TRACE4("Block %p size %d allocated at %s:%d\n", i->first, i->second.size, i->second.file, i->second.line); + BOX_TRACE("Block " << i->first << " size " << + i->second.size << " allocated at " << + i->second.file << ":" << i->second.line); } } for(std::map::const_iterator i(sSectionObjectBlocks.begin()); i != sSectionObjectBlocks.end(); ++i) { - TRACE5("Object%s %p size %d allocated at %s:%d\n", i->second.array?" []":"", i->first, i->second.size, i->second.file, i->second.line); + BOX_TRACE("Object" << (i->second.array?" []":"") << " " << + i->first << " size " << i->second.size << + " allocated at " << i->second.file << + ":" << i->second.line); } } diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 2d09b319..dafafbbd 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -62,15 +62,18 @@ BOX_ERROR(stuff << ": " << GetErrorMessage(number)) #endif -#define BOX_FORMAT_ACCOUNT(accno) \ +#define BOX_FORMAT_HEX32(number) \ std::hex << \ std::showbase << \ std::internal << \ std::setw(10) << \ std::setfill('0') << \ - (accno) << \ + (number) << \ std::dec +#define BOX_FORMAT_ACCOUNT(accno) \ + BOX_FORMAT_HEX32(accno) + #define BOX_FORMAT_OBJECTID(objectid) \ std::hex << \ std::showbase << \ diff --git a/lib/common/PartialReadStream.cpp b/lib/common/PartialReadStream.cpp index 76096738..f2f79715 100644 --- a/lib/common/PartialReadStream.cpp +++ b/lib/common/PartialReadStream.cpp @@ -44,7 +44,8 @@ PartialReadStream::~PartialReadStream() // Warn in debug mode if(mBytesLeft != 0) { - TRACE1("PartialReadStream::~PartialReadStream when mBytesLeft = %d\n", mBytesLeft); + BOX_TRACE("PartialReadStream destroyed with " << mBytesLeft << + " bytes remaining"); } } diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index 83a12ccf..66fab21f 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -53,10 +53,10 @@ void SplitString(const std::string &String, char SplitOn, std::vector