From 386217862480c6185b192f915bb8a66ec03d086a Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Wed, 29 Aug 2018 13:54:47 -0400 Subject: [PATCH] dout: add DoutPrefixPipe for composing prefix providers a wonderful feature of DoutPrefixProviders is that they can be composed, with each Provider adding onto the prefix of the previous one to aid with this composition, add a DoutPrefixPipe that takes an existing Provider and forwards the DoutPrefixProvider interface to it the class that implements the DoutPrefixPipe interface only has to override one virtual function, and never has to reference the previous Provider after passing it to the DoutPrefixPipe constructor Signed-off-by: Casey Bodley --- src/common/dout.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/common/dout.h b/src/common/dout.h index c423c0818b8..2f7601d11dc 100644 --- a/src/common/dout.h +++ b/src/common/dout.h @@ -44,6 +44,23 @@ public: virtual ~DoutPrefixProvider() {} }; +// a prefix provider that composes itself on top of another +class DoutPrefixPipe : public DoutPrefixProvider { + const DoutPrefixProvider& dpp; + public: + DoutPrefixPipe(const DoutPrefixProvider& dpp) : dpp(dpp) {} + + std::ostream& gen_prefix(std::ostream& out) const override final { + dpp.gen_prefix(out); + add_prefix(out); + return out; + } + CephContext *get_cct() const override { return dpp.get_cct(); } + unsigned get_subsys() const override { return dpp.get_subsys(); } + + virtual void add_prefix(std::ostream& out) const = 0; +}; + // helpers namespace ceph::dout { -- 2.47.3