summaryrefslogtreecommitdiff
path: root/python/openvino/runtime/common/demo_utils/include/utils/slog.hpp
diff options
context:
space:
mode:
authorEric Dao <eric@erickhangdao.com>2025-03-10 17:54:31 -0400
committerEric Dao <eric@erickhangdao.com>2025-03-10 17:54:31 -0400
commitab224e2e6ba65f5a369ec392f99cd8845ad06c98 (patch)
treea1e757e9341863ed52b8ad4c5a1c45933aab9da4 /python/openvino/runtime/common/demo_utils/include/utils/slog.hpp
parent40da1752f2c8639186b72f6838aa415e854d0b1d (diff)
downloadthesis-master.tar.gz
thesis-master.tar.bz2
thesis-master.zip
completed thesisHEADmaster
Diffstat (limited to 'python/openvino/runtime/common/demo_utils/include/utils/slog.hpp')
-rw-r--r--python/openvino/runtime/common/demo_utils/include/utils/slog.hpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/python/openvino/runtime/common/demo_utils/include/utils/slog.hpp b/python/openvino/runtime/common/demo_utils/include/utils/slog.hpp
new file mode 100644
index 0000000..316b98d
--- /dev/null
+++ b/python/openvino/runtime/common/demo_utils/include/utils/slog.hpp
@@ -0,0 +1,99 @@
+// Copyright (C) 2018-2019 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+/**
+ * @brief a header file with logging facility for common samples
+ * @file log.hpp
+ */
+
+#pragma once
+
+#include <iostream>
+#include <string>
+
+namespace slog {
+
+/**
+ * @class LogStreamEndLine
+ * @brief The LogStreamEndLine class implements an end line marker for a log stream
+ */
+class LogStreamEndLine { };
+
+static constexpr LogStreamEndLine endl;
+
+
+/**
+ * @class LogStreamBoolAlpha
+ * @brief The LogStreamBoolAlpha class implements bool printing for a log stream
+ */
+class LogStreamBoolAlpha { };
+
+static constexpr LogStreamBoolAlpha boolalpha;
+
+
+/**
+ * @class LogStream
+ * @brief The LogStream class implements a stream for sample logging
+ */
+class LogStream {
+ std::string _prefix;
+ std::ostream* _log_stream;
+ bool _new_line;
+
+public:
+ /**
+ * @brief A constructor. Creates a LogStream object
+ * @param prefix The prefix to print
+ */
+ LogStream(const std::string &prefix, std::ostream& log_stream)
+ : _prefix(prefix), _new_line(true) {
+ _log_stream = &log_stream;
+ }
+
+ /**
+ * @brief A stream output operator to be used within the logger
+ * @param arg Object for serialization in the logger message
+ */
+ template<class T>
+ LogStream &operator<<(const T &arg) {
+ if (_new_line) {
+ (*_log_stream) << "[ " << _prefix << " ] ";
+ _new_line = false;
+ }
+
+ (*_log_stream) << arg;
+ return *this;
+ }
+
+ // Specializing for LogStreamEndLine to support slog::endl
+ LogStream& operator<< (const LogStreamEndLine &/*arg*/) {
+ _new_line = true;
+
+ (*_log_stream) << std::endl;
+ return *this;
+ }
+
+ // Specializing for LogStreamBoolAlpha to support slog::boolalpha
+ LogStream& operator<< (const LogStreamBoolAlpha &/*arg*/) {
+ (*_log_stream) << std::boolalpha;
+ return *this;
+ }
+
+ // Specializing for std::vector and std::list
+ template<template<class, class> class Container, class T>
+ LogStream& operator<< (const Container<T, std::allocator<T>>& container) {
+ for (const auto& el : container) {
+ *this << el << slog::endl;
+ }
+ return *this;
+ }
+};
+
+
+static LogStream info("INFO", std::cout);
+static LogStream debug("DEBUG", std::cout);
+static LogStream warn("WARNING", std::cout);
+static LogStream err("ERROR", std::cerr);
+
+} // namespace slog