-friend PLUGIN_LOGGER GetPluginLogger(const STG_LOGGER& logger, const std::string& pluginName);
-
-public:
- PLUGIN_LOGGER(const PLUGIN_LOGGER& rhs) : m_parent(rhs.m_parent), m_pluginName(rhs.m_pluginName) {} // Need move here.
- void operator()(const char* fmt, ...) const;
- void operator()(const std::string& line) const;
-
-private:
- PLUGIN_LOGGER& operator=(const PLUGIN_LOGGER&); // Copy assignment is prohibited.
-
- PLUGIN_LOGGER(const STG_LOGGER & logger, const std::string & pn);
- const STG_LOGGER& m_parent;
- std::string m_pluginName;
+ public:
+ static PluginLogger get(std::string pluginName)
+ {
+ return PluginLogger(std::move(pluginName));
+ }
+
+ PluginLogger(PluginLogger&& rhs)
+ : m_parent(Logger::get()),
+ m_pluginName(std::move(rhs.m_pluginName))
+ {}
+ PluginLogger& operator=(PluginLogger&& rhs)
+ {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ m_pluginName = std::move(rhs.m_pluginName);
+ return *this;
+ }
+
+ void operator()(const char* fmt, ...) const;
+ void operator()(const std::string& line) const;
+
+ private:
+ explicit PluginLogger(std::string pn)
+ : m_parent(Logger::get()),
+ m_pluginName(std::move(pn))
+ {}
+
+ mutable std::mutex m_mutex;
+ Logger& m_parent;
+ std::string m_pluginName;