diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/common/ostream_temp.h | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/common/ostream_temp.h')
-rw-r--r-- | src/common/ostream_temp.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/common/ostream_temp.h b/src/common/ostream_temp.h new file mode 100644 index 000000000..73e9e3f25 --- /dev/null +++ b/src/common/ostream_temp.h @@ -0,0 +1,56 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include <sstream> + +typedef enum { + CLOG_DEBUG = 0, + CLOG_INFO = 1, + CLOG_SEC = 2, + CLOG_WARN = 3, + CLOG_ERROR = 4, + CLOG_UNKNOWN = -1, +} clog_type; + +class OstreamTemp +{ +public: + class OstreamTempSink { + public: + virtual void do_log(clog_type prio, std::stringstream& ss) = 0; + virtual ~OstreamTempSink() {} + }; + OstreamTemp(clog_type type_, OstreamTempSink *parent_); + OstreamTemp(OstreamTemp &&rhs) = default; + ~OstreamTemp(); + + template<typename T> + std::ostream& operator<<(const T& rhs) + { + return ss << rhs; + } + +private: + clog_type type; + OstreamTempSink *parent; + std::stringstream ss; +}; + +class LoggerSinkSet : public OstreamTemp::OstreamTempSink { +public: + virtual void info(std::stringstream &s) = 0; + virtual void warn(std::stringstream &s) = 0; + virtual void error(std::stringstream &s) = 0; + virtual void sec(std::stringstream &s) = 0; + virtual void debug(std::stringstream &s) = 0; + virtual OstreamTemp info() = 0; + virtual OstreamTemp warn() = 0; + virtual OstreamTemp error() = 0; + virtual OstreamTemp sec() = 0; + virtual OstreamTemp debug() = 0; + virtual void do_log(clog_type prio, std::stringstream& ss) = 0; + virtual void do_log(clog_type prio, const std::string& ss) = 0; + virtual ~LoggerSinkSet() {}; +}; |