Add glog backend as stderr mode
authorSangwan Kwon <sangwan.kwon@samsung.com>
Fri, 22 Nov 2019 07:16:26 +0000 (16:16 +0900)
committer권상완/Security 2Lab(SR)/Engineer/삼성전자 <sangwan.kwon@samsung.com>
Tue, 26 Nov 2019 08:24:15 +0000 (17:24 +0900)
Signed-off-by: Sangwan Kwon <sangwan.kwon@samsung.com>
src/vist/logger/CMakeLists.txt
src/vist/logger/dlog.cpp
src/vist/logger/dlog.hpp
src/vist/logger/glog.cpp [new file with mode: 0644]
src/vist/logger/glog.hpp [new file with mode: 0644]
src/vist/logger/tests/logger.cpp
src/vist/main/main.cpp

index efab7bbe4742402031fafdd9284f004485975d30..90f8261db5941d487e42aa3962a20cdb12e428f3 100644 (file)
@@ -13,6 +13,7 @@
 #  limitations under the License
 
 ADD_VIST_COMMON_LIBRARY(vist_logger dlog.cpp
+                                                                       glog.cpp
                                                                        logger.cpp)
 
 FILE(GLOB LOGGER_TESTS "tests/*.cpp")
index 05670ae13927278c83933b0e53a508ea00bb42a6..13f9ab1b757033da5494b0b7eeee5e4d8c430e1a 100644 (file)
@@ -22,7 +22,7 @@
 
 namespace vist {
 
-/// Make logger backend as Dlog.
+/// Make default logger backend as Dlog.
 std::shared_ptr<LogBackend> Dlog::backend = LogStream::Init(std::make_shared<Dlog>());
 
 void Dlog::info(const LogRecord& record) const noexcept
index 235600b4b666eeb75a3c2a9db960311fdd63f9fd..a584ee11123bd60c85dbb86c5c79433222836ccb 100644 (file)
@@ -28,6 +28,7 @@ public:
        void error(const LogRecord& record) const noexcept override;
 
 private:
+       /// Make default logger backend as Dlog.
        static std::shared_ptr<LogBackend> backend;
 };
 
diff --git a/src/vist/logger/glog.cpp b/src/vist/logger/glog.cpp
new file mode 100644 (file)
index 0000000..c48cfc8
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <vist/logger/glog.hpp>
+
+#undef ERROR
+#include <glog/logging.h>
+
+namespace vist {
+
+Glog::Glog()
+{
+       /// osquery calls below function
+       // google::InitGoogleLogging("ViST");
+
+       FLAGS_logtostderr = 1;
+}
+
+Glog::~Glog()
+{
+       // google::ShutdownGoogleLogging();
+}
+
+void Glog::info(const LogRecord& record) const noexcept
+{
+       LOG(INFO) << "[" << record.tag << "]" << record.message << std::endl;
+}
+
+void Glog::debug(const LogRecord& record) const noexcept
+{
+       DLOG(INFO) << "[" << record.tag << "]" << record.message << std::endl;
+}
+
+void Glog::warn(const LogRecord& record) const noexcept
+{
+       LOG(WARNING) << "[" << record.tag << "]" << record.message << std::endl;
+}
+
+void Glog::error(const LogRecord& record) const noexcept
+{
+       LOG(ERROR) << "[" << record.tag << "]" << record.message << std::endl;
+}
+
+} // namespace vist
diff --git a/src/vist/logger/glog.hpp b/src/vist/logger/glog.hpp
new file mode 100644 (file)
index 0000000..6dada86
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include <vist/logger.hpp>
+
+#include <memory>
+#include <string>
+
+namespace vist {
+
+class Glog final : public LogBackend {
+public:
+       explicit Glog();
+       ~Glog();
+
+       void info(const LogRecord& record) const noexcept override;
+       void debug(const LogRecord& record) const noexcept override;
+       void warn(const LogRecord& record) const noexcept override;
+       void error(const LogRecord& record) const noexcept override;
+};
+
+} // namespace vist
index 15c98c849cf0852034e6eda55483029c76ebe45a..45fbc2efc4220d8edf9d46c4a77cb6e37bff74be 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <vist/logger.hpp>
 #include <vist/logger/dlog.hpp>
+#include <vist/logger/glog.hpp>
 
 using namespace vist;
 
@@ -38,6 +39,15 @@ TEST(LoggerTests, console)
        ERROR(VIST) << "Error message" << 4 << 'c' << false << 0.0f;
 }
 
+TEST(LoggerTests, glog)
+{
+       LogStream::Init(std::make_shared<Glog>());
+       INFO(VIST) << "Info message" << 1;
+       DEBUG(VIST) << "Debug message" << 2 << 'a';
+       WARN(VIST) << "Warn message" << 3 << 'b' << true;
+       ERROR(VIST) << "Error message" << 4 << 'c' << false << 0.0f;
+}
+
 TEST(LoggerTests, dlog)
 {
        LogStream::Init(std::make_shared<Dlog>());
index 8e64bbcc50a7c44af6e1682149a2daf141e0f8c0..a1815788c5c1d6290139e87b0a3c3cec8d3f8d3c 100644 (file)
 
 #include <vist/exception.hpp>
 #include <vist/logger.hpp>
+#include <vist/logger/dlog.hpp>
 
 #include <cstdlib>
 
 using namespace vist;
 
 int main() try {
+       LogStream::Init(std::make_shared<Dlog>());
        Vist::Instance().start();
        return EXIT_SUCCESS;
 } catch(const Exception<ErrCode>& e) {