From: Casey Bodley Date: Wed, 29 Aug 2018 17:54:47 +0000 (-0400) Subject: dout: add DoutPrefixPipe for composing prefix providers X-Git-Tag: v14.0.1~359^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=386217862480c6185b192f915bb8a66ec03d086a;p=ceph.git 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 --- diff --git a/src/common/dout.h b/src/common/dout.h index c423c0818b84..2f7601d11dcb 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 {