summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-06-21 01:00:09 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-06-21 01:00:09 +0100
commita40ab0982d54291d0f07f5097a06be438e88118a (patch)
tree55a4b069c9c00a55cc65a4680194af1368b48764
parentAdd method for getting the configured domain of a logger (diff)
downloadicetray-a40ab0982d54291d0f07f5097a06be438e88118a.tar.bz2
icetray-a40ab0982d54291d0f07f5097a06be438e88118a.tar.xz
icetray-a40ab0982d54291d0f07f5097a06be438e88118a.zip
Add wrapper for creating a logger based on a template argument/type
-rw-r--r--icetray/icetray/logger.cpp9
-rw-r--r--icetray/icetray/logger.h5
-rw-r--r--icetray/unittests/testIceTrayLogger.cpp7
3 files changed, 21 insertions, 0 deletions
diff --git a/icetray/icetray/logger.cpp b/icetray/icetray/logger.cpp
index 6afe4d8..5e17af5 100644
--- a/icetray/icetray/logger.cpp
+++ b/icetray/icetray/logger.cpp
@@ -94,6 +94,15 @@ namespace IceTray {
}
LoggerPtr
+ LogManager::getLogger(const std::type_info & type)
+ {
+ std::unique_ptr<char, void(*)(void*)> res {
+ abi::__cxa_demangle(type.name(), NULL, NULL, NULL), std::free
+ };
+ return getLogger(res.get());
+ }
+
+ LoggerPtr
LogManager::getLogger(const std::string & domain)
{
auto logger = LoggerPtr(new Logger(domain));
diff --git a/icetray/icetray/logger.h b/icetray/icetray/logger.h
index 339f7eb..e78a126 100644
--- a/icetray/icetray/logger.h
+++ b/icetray/icetray/logger.h
@@ -71,6 +71,11 @@ namespace IceTray {
class DLL_PUBLIC LogManager {
public:
+ template<typename T>
+ LoggerPtr getLogger() {
+ return getLogger(typeid(T));
+ }
+ LoggerPtr getLogger(const std::type_info &);
LoggerPtr getLogger(const std::string &);
LogLevelWriters getLogsForDomain(const std::string &) const;
void addWriter(LogWriterPrx writer);
diff --git a/icetray/unittests/testIceTrayLogger.cpp b/icetray/unittests/testIceTrayLogger.cpp
index e7eb0fc..f051a58 100644
--- a/icetray/unittests/testIceTrayLogger.cpp
+++ b/icetray/unittests/testIceTrayLogger.cpp
@@ -281,5 +281,12 @@ BOOST_AUTO_TEST_CASE( getLogger )
ic->destroy();
}
+BOOST_AUTO_TEST_CASE( getLoggerForType )
+{
+ auto logger = LOGMANAGER()->getLogger<IceTray::Service>();
+ BOOST_REQUIRE(logger);
+ BOOST_REQUIRE_EQUAL("IceTray::Service", logger->getDomain());
+}
+
BOOST_AUTO_TEST_SUITE_END();