COMPMID-415: Add log level

Change-Id: I93f49198ab2c32f52b4723a0624d588683a92451
Reviewed-on: http://mpd-gerrit.cambridge.arm.com/81446
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
diff --git a/framework/Exceptions.cpp b/framework/Exceptions.cpp
new file mode 100644
index 0000000..d573fe9
--- /dev/null
+++ b/framework/Exceptions.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2017 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include "Exceptions.h"
+
+#include <map>
+#include <sstream>
+
+namespace arm_compute
+{
+namespace test
+{
+namespace framework
+{
+LogLevel log_level_from_name(const std::string &name)
+{
+    static const std::map<std::string, LogLevel> levels =
+    {
+        { "none", LogLevel::NONE },
+        { "config", LogLevel::CONFIG },
+        { "tests", LogLevel::TESTS },
+        { "errors", LogLevel::ERRORS },
+        { "debug", LogLevel::DEBUG },
+        { "measurements", LogLevel::MEASUREMENTS },
+        { "all", LogLevel::ALL },
+    };
+
+    try
+    {
+        return levels.at(name);
+    }
+    catch(const std::out_of_range &)
+    {
+        throw std::invalid_argument(name);
+    }
+}
+
+::std::istream &operator>>(::std::istream &stream, LogLevel &level)
+{
+    std::string value;
+    stream >> value;
+    level = log_level_from_name(value);
+    return stream;
+}
+
+::std::ostream &operator<<(::std::ostream &stream, LogLevel level)
+{
+    switch(level)
+    {
+        case LogLevel::NONE:
+            stream << "NONE";
+            break;
+        case LogLevel::CONFIG:
+            stream << "CONFIG";
+            break;
+        case LogLevel::TESTS:
+            stream << "TESTS";
+            break;
+        case LogLevel::ERRORS:
+            stream << "ERRORS";
+            break;
+        case LogLevel::DEBUG:
+            stream << "DEBUG";
+            break;
+        case LogLevel::MEASUREMENTS:
+            stream << "MEASUREMENTS";
+            break;
+        case LogLevel::ALL:
+            stream << "ALL";
+            break;
+        default:
+            throw std::invalid_argument("Unsupported log level");
+    }
+
+    return stream;
+}
+
+std::string to_string(LogLevel level)
+{
+    std::stringstream stream;
+    stream << level;
+    return stream.str();
+}
+
+TestError::TestError(const std::string &msg, LogLevel level)
+    : runtime_error{ msg }, _level{ level }
+{
+}
+
+LogLevel TestError::level() const
+{
+    return _level;
+}
+} // namespace framework
+} // namespace test
+} // namespace arm_compute