From c71493ad47f6a667ebb7b47ea35962620cbc42d1 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Thu, 6 Sep 2018 16:19:25 -0400 Subject: [PATCH] dout: add basic prefix providers adds two simple DoutPrefixProvider implementations for use as building blocks for composition with DoutPrefixPipe Signed-off-by: Casey Bodley --- src/common/dout.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/common/dout.h b/src/common/dout.h index 2f7601d11dcb..b96c7f093758 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -44,6 +44,30 @@ public: virtual ~DoutPrefixProvider() {} }; +// a prefix provider with empty prefix +class NoDoutPrefix : public DoutPrefixProvider { + CephContext *const cct; + const unsigned subsys; + public: + NoDoutPrefix(CephContext *cct, unsigned subsys) : cct(cct), subsys(subsys) {} + + std::ostream& gen_prefix(std::ostream& out) const override { return out; } + CephContext *get_cct() const override { return cct; } + unsigned get_subsys() const override { return subsys; } +}; + +// a prefix provider with static (const char*) prefix +class DoutPrefix : public NoDoutPrefix { + const char *const prefix; + public: + DoutPrefix(CephContext *cct, unsigned subsys, const char *prefix) + : NoDoutPrefix(cct, subsys), prefix(prefix) {} + + std::ostream& gen_prefix(std::ostream& out) const override { + return out << prefix; + } +}; + // a prefix provider that composes itself on top of another class DoutPrefixPipe : public DoutPrefixProvider { const DoutPrefixProvider& dpp; -- 2.47.3