diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-04-09 22:15:25 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-04-09 22:15:25 +0000 |
commit | e0d11ae476981fd56229b4ccffdd30166361548b (patch) | |
tree | 1454c0ef13ea79acc495f10ca79de31ee613e9ab /lib | |
parent | cd45df502bf91e550692d9930c6aaffc137eaadf (diff) |
Remove the global logging level.
It's incompatible with having a logger that logs everything, regardless of
the global log level.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/backupstore/BackupCommands.cpp | 2 | ||||
-rw-r--r-- | lib/backupstore/StoreTestUtils.cpp | 7 | ||||
-rw-r--r-- | lib/common/Box.h | 20 | ||||
-rw-r--r-- | lib/common/Logging.cpp | 17 | ||||
-rw-r--r-- | lib/common/Logging.h | 54 | ||||
-rw-r--r-- | lib/common/Test.cpp | 67 |
6 files changed, 20 insertions, 147 deletions
diff --git a/lib/backupstore/BackupCommands.cpp b/lib/backupstore/BackupCommands.cpp index 2d927358..8b485d0c 100644 --- a/lib/backupstore/BackupCommands.cpp +++ b/lib/backupstore/BackupCommands.cpp @@ -298,7 +298,7 @@ std::auto_ptr<BackupProtocolMessage> BackupProtocolGetObject::DoCommand(BackupPr // Check the object exists if(!rContext.ObjectExists(mObjectID)) { - return std::auto_ptr<BackupProtocolMessage>(new BackupProtocolSuccess(NoObject)); + return PROTOCOL_ERROR(Err_DoesNotExist); } // Open the object diff --git a/lib/backupstore/StoreTestUtils.cpp b/lib/backupstore/StoreTestUtils.cpp index a5dbc28f..b1c8e424 100644 --- a/lib/backupstore/StoreTestUtils.cpp +++ b/lib/backupstore/StoreTestUtils.cpp @@ -34,7 +34,8 @@ bool create_account(int soft, int hard) 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 @@ bool delete_account() 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 @@ bool check_num_blocks(BackupProtocolCallable& Client, int Current, int Old, 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; diff --git a/lib/common/Box.h b/lib/common/Box.h index 316f4364..8ce2a625 100644 --- a/lib/common/Box.h +++ b/lib/common/Box.h @@ -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 ") (" << \ diff --git a/lib/common/Logging.cpp b/lib/common/Logging.cpp index 0a52fa5b..af132fa3 100644 --- a/lib/common/Logging.cpp +++ b/lib/common/Logging.cpp @@ -42,16 +42,12 @@ std::vector<Logger*> Logging::sLoggers; 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; 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::Remove(Logger* pOldLogger) 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 @@ void Logging::LogToSyslog(Log::Level level, const std::string& rFile, return; } - if (level > sGlobalLevel) - { - return; - } - std::string newMessage; if (sContextSet) @@ -255,8 +241,7 @@ Logger::~Logger() bool Logger::IsEnabled(Log::Level level) { - return Logging::IsEnabled(level) && - (int)mCurrentLevel >= (int)level; + return (int)mCurrentLevel >= (int)level; } bool Console::sShowTime = false; diff --git a/lib/common/Logging.h b/lib/common/Logging.h index 55d09c91..3e38b6af 100644 --- a/lib/common/Logging.h +++ b/lib/common/Logging.h @@ -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,19 +199,23 @@ class Logger virtual void SetProgramName(const std::string& rProgramName) = 0; - class Guard + class LevelGuard { private: Logger& mLogger; 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 @@ class Logging static bool sContextSet; static Console* spConsole; static Syslog* spSyslog; - static Log::Level sGlobalLevel; static Logging sGlobalLogging; static std::string sProgramName; @@ -317,52 +318,13 @@ class Logging 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); 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: diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp index de87c465..bfa7bcb0 100644 --- a/lib/common/Test.cpp +++ b/lib/common/Test.cpp @@ -230,14 +230,7 @@ int WaitForServerStartup(const char *pidFile, int pidIfKnown) #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 @@ int WaitForServerStartup(const char *pidFile, int pidIfKnown) break; } - if (Logging::GetGlobalLevel() < Log::TRACE) - { - ::fprintf(stdout, "."); - ::fflush(stdout); - } - ::sleep(1); } @@ -265,42 +252,17 @@ int WaitForServerStartup(const char *pidFile, int pidIfKnown) 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; } 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 @@ void terminate_bbackupd(int pid) // 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) |