[icinga-checkins] icinga.org: icinga2/master: Implement validation for the Logger#severity attribute

git at icinga.org git at icinga.org
Tue May 17 11:44:09 CEST 2016


Module: icinga2
Branch: master
Commit: 597d300e20c78143b7f0de72526992d040d4de80
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=597d300e20c78143b7f0de72526992d040d4de80

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Apr 21 13:50:47 2016 +0200

Implement validation for the Logger#severity attribute

fixes #11646

---

 lib/base/logger.cpp |   17 ++++++++++++-----
 lib/base/logger.hpp |    2 ++
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp
index 3aa14c1..d4a2048 100644
--- a/lib/base/logger.cpp
+++ b/lib/base/logger.cpp
@@ -156,7 +156,6 @@ String Logger::SeverityToString(LogSeverity severity)
 		case LogCritical:
 			return "critical";
 		default:
-			Log(LogCritical, "Logger", "Invalid severity.");
 			BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity."));
 	}
 }
@@ -178,11 +177,8 @@ LogSeverity Logger::StringToSeverity(const String& severity)
 		return LogWarning;
 	else if (severity == "critical")
 		return LogCritical;
-	else {
-		Log(LogCritical, "Logger")
-		    << "Invalid severity: '" << severity << "'.";
+	else
 		BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid severity: " + severity));
-	}
 }
 
 void Logger::DisableConsoleLog(void)
@@ -219,3 +215,14 @@ bool Logger::IsTimestampEnabled(void)
 {
 	return m_TimestampEnabled;
 }
+
+void Logger::ValidateSeverity(const String& value, const ValidationUtils& utils)
+{
+	ObjectImpl<Logger>::ValidateSeverity(value, utils);
+
+	try {
+		StringToSeverity(value);
+	} catch (...) {
+		BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("severity"), "Invalid severity specified: " + value));
+	}
+}
diff --git a/lib/base/logger.hpp b/lib/base/logger.hpp
index 2a77d0f..36e727d 100644
--- a/lib/base/logger.hpp
+++ b/lib/base/logger.hpp
@@ -92,6 +92,8 @@ public:
 
 	static void StaticInitialize(void);
 
+	virtual void ValidateSeverity(const String& value, const ValidationUtils& utils) override;
+
 protected:
 	virtual void Start(bool runtimeCreated) override;
 	virtual void Stop(bool runtimeRemoved) override;



More information about the icinga-checkins mailing list