From: Sangwan Kwon Date: Fri, 22 Nov 2019 07:16:26 +0000 (+0900) Subject: Add glog backend as stderr mode X-Git-Tag: submit/tizen/20200810.073515~151 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=df187a2f720ae9ecbe4269d9a072c209bcc8cab1;p=platform%2Fcore%2Fsecurity%2Fvist.git Add glog backend as stderr mode Signed-off-by: Sangwan Kwon --- diff --git a/src/vist/logger/CMakeLists.txt b/src/vist/logger/CMakeLists.txt index efab7bb..90f8261 100644 --- a/src/vist/logger/CMakeLists.txt +++ b/src/vist/logger/CMakeLists.txt @@ -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") diff --git a/src/vist/logger/dlog.cpp b/src/vist/logger/dlog.cpp index 05670ae..13f9ab1 100644 --- a/src/vist/logger/dlog.cpp +++ b/src/vist/logger/dlog.cpp @@ -22,7 +22,7 @@ namespace vist { -/// Make logger backend as Dlog. +/// Make default logger backend as Dlog. std::shared_ptr Dlog::backend = LogStream::Init(std::make_shared()); void Dlog::info(const LogRecord& record) const noexcept diff --git a/src/vist/logger/dlog.hpp b/src/vist/logger/dlog.hpp index 235600b..a584ee1 100644 --- a/src/vist/logger/dlog.hpp +++ b/src/vist/logger/dlog.hpp @@ -28,6 +28,7 @@ public: void error(const LogRecord& record) const noexcept override; private: + /// Make default logger backend as Dlog. static std::shared_ptr backend; }; diff --git a/src/vist/logger/glog.cpp b/src/vist/logger/glog.cpp new file mode 100644 index 0000000..c48cfc8 --- /dev/null +++ b/src/vist/logger/glog.cpp @@ -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 + +#undef ERROR +#include + +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 index 0000000..6dada86 --- /dev/null +++ b/src/vist/logger/glog.hpp @@ -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 + +#include +#include + +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 diff --git a/src/vist/logger/tests/logger.cpp b/src/vist/logger/tests/logger.cpp index 15c98c8..45fbc2e 100644 --- a/src/vist/logger/tests/logger.cpp +++ b/src/vist/logger/tests/logger.cpp @@ -18,6 +18,7 @@ #include #include +#include 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()); + 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()); diff --git a/src/vist/main/main.cpp b/src/vist/main/main.cpp index 8e64bbc..a181578 100644 --- a/src/vist/main/main.cpp +++ b/src/vist/main/main.cpp @@ -18,12 +18,14 @@ #include #include +#include #include using namespace vist; int main() try { + LogStream::Init(std::make_shared()); Vist::Instance().start(); return EXIT_SUCCESS; } catch(const Exception& e) {