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>
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 {