From ac20c63f397d3974fac3a43ccabe028346bc909f Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 18 Jun 2021 14:24:28 -0400 Subject: [PATCH] add plugin names to logger instances --- include/villas/api/request.hpp | 16 +++++++++++++--- include/villas/format.hpp | 15 +++++++++++++-- include/villas/hook.hpp | 14 +++++++++++++- lib/hook.cpp | 1 - 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/include/villas/api/request.hpp b/include/villas/api/request.hpp index 67530d73b..26d16c836 100644 --- a/include/villas/api/request.hpp +++ b/include/villas/api/request.hpp @@ -116,8 +116,9 @@ public: return std::string(buf); } - virtual std::string - toString(); + + void setLogger(Logger log) + { logger = log; } }; class RequestFactory : public plugin::Plugin { @@ -133,6 +134,11 @@ public: static Request * create(Session *s, const std::string &uri, Session::Method meth, unsigned long ct); + + virtual + std::string + getType() const + { return "api:request"; } }; template @@ -150,7 +156,11 @@ public: virtual Request * make(Session *s) { - return new T(s); + auto *r = new T(s); + + r->setLogger(getLogger()); + + return r; } // Get plugin name diff --git a/include/villas/format.hpp b/include/villas/format.hpp index 13a2f7db0..45c871459 100644 --- a/include/villas/format.hpp +++ b/include/villas/format.hpp @@ -40,6 +40,8 @@ protected: bool destroy_signals; + Logger logger; + struct { char *buffer; size_t buflen; @@ -59,7 +61,8 @@ public: int getFlags() const { return flags; } - virtual ~Format(); + void setLogger(Logger log) + { logger = log; } void start(struct vlist *sigs, int fl = (int) SampleFlags::HAS_ALL); void start(const std::string &dtypes, int fl = (int) SampleFlags::HAS_ALL); @@ -142,6 +145,10 @@ public: static Format * make(const std::string &format); + + virtual + std::string getType() const + { return "format"; } }; template @@ -152,7 +159,11 @@ public: virtual Format * make() { - return new T(flags); + auto *f = new T(flags); + + f->setLogger(getLogger()); + + return f; } /// Get plugin name diff --git a/include/villas/hook.hpp b/include/villas/hook.hpp index 355c1cf21..20ecf472c 100644 --- a/include/villas/hook.hpp +++ b/include/villas/hook.hpp @@ -81,6 +81,9 @@ public: virtual void parse(json_t *c); void prepare(struct vlist *sigs); + void setLogger(Logger log) + { logger = log; } + /** Called whenever a hook is started; before threads are created. */ virtual void start() { @@ -183,6 +186,11 @@ public: virtual int getFlags() const = 0; virtual int getPriority() const = 0; + + virtual + std::string + getType() const + { return "hook"; } }; template @@ -193,7 +201,11 @@ public: virtual Hook * make(struct vpath *p, struct vnode *n) { - return new T(p, n, getFlags(), getPriority()); + auto *h = new T(p, n, getFlags(), getPriority()); + + h->setLogger(getLogger()); + + return h; } /// Get plugin name diff --git a/lib/hook.cpp b/lib/hook.cpp index c649e7bdf..86a82119d 100644 --- a/lib/hook.cpp +++ b/lib/hook.cpp @@ -39,7 +39,6 @@ using namespace villas; using namespace villas::node; Hook::Hook(struct vpath *p, struct vnode *n, int fl, int prio, bool en) : - logger(logging.get("hook")), state(State::INITIALIZED), flags(fl), priority(prio),