# limitations under the License
ADD_VIST_COMMON_LIBRARY(vist_logger dlog.cpp
+ glog.cpp
logger.cpp)
FILE(GLOB LOGGER_TESTS "tests/*.cpp")
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
void error(const LogRecord& record) const noexcept override;
private:
+ /// Make default logger backend as Dlog.
static std::shared_ptr<LogBackend> backend;
};
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
#include <vist/logger.hpp>
#include <vist/logger/dlog.hpp>
+#include <vist/logger/glog.hpp>
using namespace vist;
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>());
#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) {