1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * @brief a header file with logging facility for common samples
17 * @class LogStreamEndLine
18 * @brief The LogStreamEndLine class implements an end line marker for a log stream
20 class LogStreamEndLine { };
22 static constexpr LogStreamEndLine endl;
27 * @brief The LogStream class implements a stream for sample logging
31 std::ostream* _log_stream;
36 * @brief A constructor. Creates an LogStream object
37 * @param prefix The prefix to print
39 LogStream(const std::string &prefix, std::ostream& log_stream)
40 : _prefix(prefix), _new_line(true) {
41 _log_stream = &log_stream;
45 * @brief A stream output operator to be used within the logger
46 * @param arg Object for serialization in the logger message
49 LogStream &operator<<(const T &arg) {
51 (*_log_stream) << "[ " << _prefix << " ] ";
55 (*_log_stream) << arg;
59 // Specializing for LogStreamEndLine to support slog::endl
60 LogStream& operator<< (const LogStreamEndLine &/*arg*/) {
63 (*_log_stream) << std::endl;
69 static LogStream info("INFO", std::cout);
70 static LogStream warn("WARNING", std::cout);
71 static LogStream err("ERROR", std::cerr);