[Box Backup-commit] COMMIT r3316 - in box/trunk: bin/bbackupquery infrastructure lib/backupstore lib/common test/backupstore test/bbackupd
subversion at boxbackup.org
subversion at boxbackup.org
Wed Apr 9 23:15:25 BST 2014
Author: chris
Date: 2014-04-09 23:15:25 +0100 (Wed, 09 Apr 2014)
New Revision: 3316
Modified:
box/trunk/bin/bbackupquery/BackupQueries.cpp
box/trunk/bin/bbackupquery/bbackupquery.cpp
box/trunk/infrastructure/buildenv-testmain-template.cpp
box/trunk/lib/backupstore/BackupCommands.cpp
box/trunk/lib/backupstore/StoreTestUtils.cpp
box/trunk/lib/common/Box.h
box/trunk/lib/common/Logging.cpp
box/trunk/lib/common/Logging.h
box/trunk/lib/common/Test.cpp
box/trunk/test/backupstore/testbackupstore.cpp
box/trunk/test/bbackupd/testbbackupd.cpp
Log:
Remove the global logging level.
It's incompatible with having a logger that logs everything, regardless of
the global log level.
Modified: box/trunk/bin/bbackupquery/BackupQueries.cpp
===================================================================
--- box/trunk/bin/bbackupquery/BackupQueries.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/bin/bbackupquery/BackupQueries.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -1967,11 +1967,9 @@
// At TRACE level, we print a line for each file and
// directory, so we don't need dots.
- bool printDots = ! Logging::IsEnabled(Log::TRACE);
-
result = BackupClientRestore(mrConnection, dirID,
storeDirEncoded.c_str(), localName.c_str(),
- printDots /* print progress dots */, restoreDeleted,
+ true /* print progress dots */, restoreDeleted,
false /* don't undelete after restore! */,
opts['r'] /* resume? */,
opts['f'] /* force continue after errors */);
Modified: box/trunk/bin/bbackupquery/bbackupquery.cpp
===================================================================
--- box/trunk/bin/bbackupquery/bbackupquery.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/bin/bbackupquery/bbackupquery.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -221,9 +221,9 @@
Logging::SetProgramName("bbackupquery");
#ifdef BOX_RELEASE_BUILD
- int masterLevel = Log::NOTICE; // need an int to do math with
+ int consoleLogLevel = Log::NOTICE; // need an int to do math with
#else
- int masterLevel = Log::INFO; // need an int to do math with
+ int consoleLogLevel = Log::INFO; // need an int to do math with
#endif
#ifdef WIN32
@@ -253,7 +253,7 @@
{
case 'q':
{
- if(masterLevel == Log::NOTHING)
+ if(consoleLogLevel == Log::NOTHING)
{
BOX_FATAL("Too many '-q': "
"Cannot reduce logging "
@@ -260,13 +260,13 @@
"level any more");
return 2;
}
- masterLevel--;
+ consoleLogLevel--;
}
break;
case 'v':
{
- if(masterLevel == Log::EVERYTHING)
+ if(consoleLogLevel == Log::EVERYTHING)
{
BOX_FATAL("Too many '-v': "
"Cannot increase logging "
@@ -273,20 +273,20 @@
"level any more");
return 2;
}
- masterLevel++;
+ consoleLogLevel++;
}
break;
case 'V':
{
- masterLevel = Log::EVERYTHING;
+ consoleLogLevel = Log::EVERYTHING;
}
break;
case 'W':
{
- masterLevel = Logging::GetNamedLevel(optarg);
- if (masterLevel == Log::INVALID)
+ consoleLogLevel = Logging::GetNamedLevel(optarg);
+ if (consoleLogLevel == Log::INVALID)
{
BOX_FATAL("Invalid logging level");
return 2;
@@ -351,7 +351,7 @@
argc -= optind;
argv += optind;
- Logging::SetGlobalLevel((Log::Level)masterLevel);
+ Logging::GetConsole().Filter((Log::Level)consoleLogLevel);
std::auto_ptr<FileLogger> fileLogger;
if (fileLogLevel != Log::INVALID)
@@ -359,20 +359,8 @@
fileLogger.reset(new FileLogger(fileLogFile, fileLogLevel));
}
- bool quiet = false;
- if (masterLevel < Log::NOTICE)
- {
- // Quiet mode
- quiet = true;
- }
+ BOX_NOTICE(BANNER_TEXT("Backup Query Tool"));
- // Print banner?
- if(!quiet)
- {
- const char *banner = BANNER_TEXT("Backup Query Tool");
- BOX_NOTICE(banner);
- }
-
#ifdef WIN32
if (unicodeConsole)
{
@@ -399,7 +387,7 @@
#endif // WIN32
// Read in the configuration file
- if(!quiet) BOX_INFO("Using configuration file " << configFilename);
+ BOX_INFO("Using configuration file " << configFilename);
std::string errs;
std::auto_ptr<Configuration> config(
@@ -428,7 +416,7 @@
BackupClientCryptoKeys_Setup(conf.GetKeyValue("KeysFile").c_str());
// 2. Connect to server
- if(!quiet) BOX_INFO("Connecting to store...");
+ BOX_INFO("Connecting to store...");
SocketStreamTLS *socket = new SocketStreamTLS;
std::auto_ptr<SocketStream> apSocket(socket);
socket->Open(tlsContext, Socket::TypeINET,
@@ -436,7 +424,7 @@
conf.GetKeyValueInt("StorePort"));
// 3. Make a protocol, and handshake
- if(!quiet) BOX_INFO("Handshake with store...");
+ BOX_INFO("Handshake with store...");
std::auto_ptr<BackupProtocolClient>
apConnection(new BackupProtocolClient(apSocket));
BackupProtocolClient& connection(*(apConnection.get()));
@@ -449,7 +437,7 @@
}
// 4. Log in to server
- if(!quiet) BOX_INFO("Login to store...");
+ BOX_INFO("Login to store...");
// Check the version of the server
{
std::auto_ptr<BackupProtocolVersion> serverVersion(connection.QueryVersion(BACKUP_STORE_SERVER_VERSION));
@@ -463,7 +451,8 @@
(readWrite)?0:(BackupProtocolLogin::Flags_ReadOnly));
// 5. Tell user.
- if(!quiet) printf("Login complete.\n\nType \"help\" for a list of commands.\n\n");
+ BOX_INFO("Login complete.");
+ BOX_INFO("Type \"help\" for a list of commands.");
// Set up a context for our work
BackupQueries context(connection, conf, readWrite);
@@ -572,9 +561,9 @@
}
// Done... stop nicely
- if(!quiet) BOX_INFO("Logging off...");
+ BOX_INFO("Logging off...");
connection.QueryFinished();
- if(!quiet) BOX_INFO("Session finished.");
+ BOX_INFO("Session finished.");
// Return code
returnCode = context.GetReturnCode();
Modified: box/trunk/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/trunk/infrastructure/buildenv-testmain-template.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/infrastructure/buildenv-testmain-template.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -372,7 +372,7 @@
}
}
- Logging::SetGlobalLevel((Log::Level)logLevel);
+ Logging::FilterSyslog(Log::NOTHING);
Logging::FilterConsole((Log::Level)logLevel);
argc -= optind - 1;
Modified: box/trunk/lib/backupstore/BackupCommands.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupCommands.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/lib/backupstore/BackupCommands.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -298,7 +298,7 @@
// Check the object exists
if(!rContext.ObjectExists(mObjectID))
{
- return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(NoObject));
+ return PROTOCOL_ERROR(Err_DoesNotExist);
}
// Open the object
Modified: box/trunk/lib/backupstore/StoreTestUtils.cpp
===================================================================
--- box/trunk/lib/backupstore/StoreTestUtils.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/lib/backupstore/StoreTestUtils.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -34,7 +34,8 @@
Configuration::LoadAndVerify
("testfiles/bbstored.conf", &BackupConfigFileVerify, errs));
BackupStoreAccountsControl control(*config);
- Logging::Guard guard(Log::WARNING);
+
+ Logger::LevelGuard guard(Logging::GetConsole(), Log::WARNING);
int result = control.CreateAccount(0x01234567, 0, soft, hard);
TEST_EQUAL(0, result);
return (result == 0);
@@ -47,7 +48,7 @@
Configuration::LoadAndVerify
("testfiles/bbstored.conf", &BackupConfigFileVerify, errs));
BackupStoreAccountsControl control(*config);
- Logging::Guard guard(Log::WARNING);
+ Logger::LevelGuard guard(Logging::GetConsole(), Log::WARNING);
TEST_THAT_THROWONFAIL(control.DeleteAccount(0x01234567, false) == 0);
return true;
}
@@ -204,7 +205,7 @@
int check_account_for_errors(Log::Level log_level)
{
- Logging::Guard guard(log_level);
+ Logger::LevelGuard guard(Logging::GetConsole(), log_level);
Logging::Tagger tag("check fix", true);
Logging::ShowTagOnConsole show;
std::string errs;
Modified: box/trunk/lib/common/Box.h
===================================================================
--- box/trunk/lib/common/Box.h 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/lib/common/Box.h 2014-04-09 22:15:25 UTC (rev 3316)
@@ -116,16 +116,8 @@
{ \
if((!HideExceptionMessageGuard::ExceptionsHidden() \
&& !HideSpecificExceptionGuard::IsHidden( \
- type::ExceptionType, type::subtype)) \
- || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
+ type::ExceptionType, type::subtype))) \
{ \
- std::auto_ptr<Logging::Guard> guard; \
- \
- if(Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
- { \
- guard.reset(new Logging::Guard(Log::EVERYTHING)); \
- } \
- \
OPTIONAL_DO_BACKTRACE \
BOX_WARNING("Exception thrown: " \
#type "(" #subtype ") " \
@@ -140,16 +132,8 @@
_box_throw_line << message; \
if((!HideExceptionMessageGuard::ExceptionsHidden() \
&& !HideSpecificExceptionGuard::IsHidden( \
- type::ExceptionType, type::subtype)) \
- || Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
+ type::ExceptionType, type::subtype))) \
{ \
- std::auto_ptr<Logging::Guard> guard; \
- \
- if(Logging::Guard::IsGuardingFrom(Log::EVERYTHING)) \
- { \
- guard.reset(new Logging::Guard(Log::EVERYTHING)); \
- } \
- \
OPTIONAL_DO_BACKTRACE \
BOX_WARNING("Exception thrown: " \
#type "(" #subtype ") (" << \
Modified: box/trunk/lib/common/Logging.cpp
===================================================================
--- box/trunk/lib/common/Logging.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/lib/common/Logging.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -42,7 +42,6 @@
std::string Logging::sContext;
Console* Logging::spConsole = NULL;
Syslog* Logging::spSyslog = NULL;
-Log::Level Logging::sGlobalLevel = Log::EVERYTHING;
Logging Logging::sGlobalLogging; //automatic initialisation
std::string Logging::sProgramName;
@@ -49,9 +48,6 @@
HideSpecificExceptionGuard::SuppressedExceptions_t
HideSpecificExceptionGuard::sSuppressedExceptions;
-int Logging::Guard::sGuardCount = 0;
-Log::Level Logging::Guard::sOriginalLevel = Log::INVALID;
-
Logging::Logging()
{
ASSERT(!spConsole);
@@ -142,11 +138,6 @@
void Logging::Log(Log::Level level, const std::string& rFile,
int line, const std::string& rMessage)
{
- if (level > sGlobalLevel)
- {
- return;
- }
-
std::string newMessage;
if (sContextSet)
@@ -175,11 +166,6 @@
return;
}
- if (level > sGlobalLevel)
- {
- return;
- }
-
std::string newMessage;
if (sContextSet)
@@ -255,8 +241,7 @@
bool Logger::IsEnabled(Log::Level level)
{
- return Logging::IsEnabled(level) &&
- (int)mCurrentLevel >= (int)level;
+ return (int)mCurrentLevel >= (int)level;
}
bool Console::sShowTime = false;
Modified: box/trunk/lib/common/Logging.h
===================================================================
--- box/trunk/lib/common/Logging.h 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/lib/common/Logging.h 2014-04-09 22:15:25 UTC (rev 3316)
@@ -39,9 +39,7 @@
#define BOX_WARNING(stuff) BOX_LOG(Log::WARNING, stuff)
#define BOX_NOTICE(stuff) BOX_LOG(Log::NOTICE, stuff)
#define BOX_INFO(stuff) BOX_LOG(Log::INFO, stuff)
-#define BOX_TRACE(stuff) \
- if (Logging::IsEnabled(Log::TRACE)) \
- { BOX_LOG(Log::TRACE, stuff) }
+#define BOX_TRACE(stuff) BOX_LOG(Log::TRACE, stuff)
#define BOX_SYS_ERRNO_MESSAGE(error_number, stuff) \
stuff << ": " << std::strerror(error_number) << \
@@ -201,7 +199,7 @@
virtual void SetProgramName(const std::string& rProgramName) = 0;
- class Guard
+ class LevelGuard
{
private:
Logger& mLogger;
@@ -208,12 +206,16 @@
Log::Level mOldLevel;
public:
- Guard(Logger& Logger)
+ LevelGuard(Logger& Logger, Log::Level newLevel = Log::INVALID)
: mLogger(Logger)
{
mOldLevel = Logger.GetLevel();
+ if (newLevel != Log::INVALID)
+ {
+ Logger.Filter(newLevel);
+ }
}
- ~Guard()
+ ~LevelGuard()
{
mLogger.Filter(mOldLevel);
}
@@ -298,7 +300,6 @@
static bool sContextSet;
static Console* spConsole;
static Syslog* spSyslog;
- static Log::Level sGlobalLevel;
static Logging sGlobalLogging;
static std::string sProgramName;
@@ -317,13 +318,7 @@
int line, const std::string& rMessage);
static void SetContext(std::string context);
static void ClearContext();
- static void SetGlobalLevel(Log::Level level) { sGlobalLevel = level; }
- static Log::Level GetGlobalLevel() { return sGlobalLevel; }
static Log::Level GetNamedLevel(const std::string& rName);
- static bool IsEnabled(Log::Level level)
- {
- return (int)sGlobalLevel >= (int)level;
- }
static void SetProgramName(const std::string& rProgramName);
static std::string GetProgramName() { return sProgramName; }
static void SetFacility(int facility);
@@ -330,39 +325,6 @@
static Console& GetConsole() { return *spConsole; }
static Syslog& GetSyslog() { return *spSyslog; }
- class Guard
- {
- private:
- Log::Level mOldLevel;
- static int sGuardCount;
- static Log::Level sOriginalLevel;
-
- public:
- Guard(Log::Level newLevel)
- {
- mOldLevel = Logging::GetGlobalLevel();
- if(sGuardCount == 0)
- {
- sOriginalLevel = mOldLevel;
- }
- sGuardCount++;
- Logging::SetGlobalLevel(newLevel);
- }
- ~Guard()
- {
- sGuardCount--;
- Logging::SetGlobalLevel(mOldLevel);
- }
-
- static bool IsActive() { return (sGuardCount > 0); }
- static Log::Level GetOriginalLevel() { return sOriginalLevel; }
- static bool IsGuardingFrom(Log::Level originalLevel)
- {
- return IsActive() &&
- (int)sOriginalLevel >= (int)originalLevel;
- }
- };
-
class ShowTagOnConsole
{
private:
Modified: box/trunk/lib/common/Test.cpp
===================================================================
--- box/trunk/lib/common/Test.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/lib/common/Test.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -230,14 +230,7 @@
#endif
// time for it to start up
- if (Logging::GetGlobalLevel() >= Log::TRACE)
- {
- BOX_TRACE("Waiting for server to start");
- }
- else
- {
- ::fprintf(stdout, "Waiting for server to start: ");
- }
+ BOX_TRACE("Waiting for server to start");
for (int i = 0; i < 15; i++)
{
@@ -251,12 +244,6 @@
break;
}
- if (Logging::GetGlobalLevel() < Log::TRACE)
- {
- ::fprintf(stdout, ".");
- ::fflush(stdout);
- }
-
::sleep(1);
}
@@ -265,15 +252,6 @@
if (pidIfKnown && !ServerIsAlive(pidIfKnown))
{
- if (Logging::GetGlobalLevel() >= Log::TRACE)
- {
- BOX_ERROR("server died!");
- }
- else
- {
- ::fprintf(stdout, " server died!\n");
- }
-
TEST_FAIL_WITH_MESSAGE("Server died!");
return -1;
}
@@ -280,27 +258,11 @@
if (!TestFileNotEmpty(pidFile))
{
- if (Logging::GetGlobalLevel() >= Log::TRACE)
- {
- BOX_ERROR("timed out!");
- }
- else
- {
- ::fprintf(stdout, " timed out!\n");
- }
-
TEST_FAIL_WITH_MESSAGE("Server didn't save PID file");
return -1;
}
- if (Logging::GetGlobalLevel() >= Log::TRACE)
- {
- BOX_TRACE("Server started");
- }
- else
- {
- ::fprintf(stdout, " done.\n");
- }
+ BOX_TRACE("Server started");
// wait a second for the pid to be written to the file
::sleep(1);
@@ -419,35 +381,14 @@
// Wait a given number of seconds for something to complete
void wait_for_operation(int seconds, const char* message)
{
- if (Logging::GetGlobalLevel() >= Log::TRACE)
- {
- BOX_TRACE("Waiting " << seconds << " seconds for " << message);
- }
- else
- {
- printf("Waiting for %s: ", message);
- fflush(stdout);
- }
+ BOX_TRACE("Waiting " << seconds << " seconds for " << message);
for(int l = 0; l < seconds; ++l)
{
sleep(1);
- if (Logging::GetGlobalLevel() < Log::TRACE)
- {
- printf(".");
- fflush(stdout);
- }
}
- if (Logging::GetGlobalLevel() >= Log::TRACE)
- {
- BOX_TRACE("Finished waiting for " << message);
- }
- else
- {
- printf(" done.\n");
- fflush(stdout);
- }
+ BOX_TRACE("Finished waiting for " << message);
}
void safe_sleep(int seconds)
Modified: box/trunk/test/backupstore/testbackupstore.cpp
===================================================================
--- box/trunk/test/backupstore/testbackupstore.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/test/backupstore/testbackupstore.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -1104,6 +1104,11 @@
ConnectionException, Conn_Protocol_UnexpectedReply);
}
+ // Try retrieving an object that doesn't exist. That used to return
+ // BackupProtocolSuccess(NoObject) for no apparent reason.
+ TEST_COMMAND_RETURNS_ERROR(protocol, QueryGetObject(store1objid + 1),
+ Err_DoesNotExist);
+
// Close the protocol, so we can housekeep the account
protocol.QueryFinished();
TEST_THAT(run_housekeeping_and_check_account());
Modified: box/trunk/test/bbackupd/testbbackupd.cpp
===================================================================
--- box/trunk/test/bbackupd/testbbackupd.cpp 2014-04-09 22:15:19 UTC (rev 3315)
+++ box/trunk/test/bbackupd/testbbackupd.cpp 2014-04-09 22:15:25 UTC (rev 3316)
@@ -324,7 +324,7 @@
BackupClientFileAttributes t3;
{
- Logging::Guard guard(Log::ERROR);
+ Logger::LevelGuard(Logging::GetConsole(), Log::ERROR);
TEST_CHECK_THROWS(t3.ReadAttributes("doesn't exist"),
CommonException, OSFileError);
}
@@ -345,7 +345,7 @@
#ifndef WIN32
{
- Logging::Guard guard(Log::ERROR);
+ Logger::LevelGuard(Logging::GetConsole(), Log::ERROR);
TEST_CHECK_THROWS(t1.WriteAttributes("testfiles/test1_nXX"),
CommonException, OSFileError);
TEST_CHECK_THROWS(t3.WriteAttributes("doesn't exist"),
@@ -879,7 +879,7 @@
context, 0 /* read-write */);
{
- Logging::Guard guard(Log::ERROR);
+ Logger::LevelGuard(Logging::GetConsole(), Log::ERROR);
TEST_CHECK_THROWS(ReadDirectory(*client, 0x12345678),
ConnectionException,
Conn_Protocol_UnexpectedReply);
@@ -1713,11 +1713,6 @@
// in fork child
TEST_THAT(setsid() != -1);
- if (!Logging::IsEnabled(Log::TRACE))
- {
- Logging::SetGlobalLevel(Log::NOTHING);
- }
-
// BackupStoreDaemon must be destroyed before exit(),
// to avoid memory leaks being reported.
{
@@ -1742,15 +1737,14 @@
::signal(SIGPIPE, SIG_IGN);
{
- Log::Level newLevel = Logging::GetGlobalLevel();
+ Console& console(Logging::GetConsole());
+ Logger::LevelGuard guard(console);
- if (!Logging::IsEnabled(Log::TRACE))
+ if (console.GetLevel() < Log::TRACE)
{
- newLevel = Log::NOTHING;
+ console.Filter(Log::NOTHING);
}
- Logging::Guard guard(newLevel);
-
BackupDaemon bbackupd;
bbackupd.Configure("testfiles/bbackupd.conf");
bbackupd.InitCrypto();
@@ -3424,7 +3418,8 @@
fflush(stdout);
{
- Logging::Guard guard(Log::FATAL);
+ Logger::LevelGuard(Logging::GetConsole(),
+ Log::FATAL);
TEST_THAT(BackupClientRestore(*client,
restoredirid, "Test1",
"testfiles/no-such-path/subdir",
More information about the Boxbackup-commit
mailing list