]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
dout: add DoutPrefixPipe for composing prefix providers
authorCasey Bodley <cbodley@redhat.com>
Wed, 29 Aug 2018 17:54:47 +0000 (13:54 -0400)
committerCasey Bodley <cbodley@redhat.com>
Thu, 6 Sep 2018 20:16:01 +0000 (16:16 -0400)
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 <cbodley@redhat.com>
src/common/dout.h

index c423c0818b841134695bf178d6fbbe8a2ad9da2f..2f7601d11dcb3e73256c928c2a26ade68532caab 100644 (file)
@@ -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 {