[Libreoffice-commits] online.git: loolwsd/Log.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Oct 31 06:09:35 UTC 2016
loolwsd/Log.hpp | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)
New commits:
commit 90c60d99318de07f5e421e822882e691cdd6f287
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Oct 30 19:16:57 2016 -0400
loolwsd: more efficient stream logging
Change-Id: I6596f87be4d36d2857c40b88864099c6cb5ab5b0
Reviewed-on: https://gerrit.libreoffice.org/30421
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/Log.hpp b/loolwsd/Log.hpp
index ea3d6ee..799fd77 100644
--- a/loolwsd/Log.hpp
+++ b/loolwsd/Log.hpp
@@ -24,7 +24,7 @@ namespace Log
const bool logToFile = false,
std::map<std::string, std::string> config = {});
Poco::Logger& logger();
- std::string prefix();
+ std::string prefix(const char* level);
void trace(const std::string& msg);
void debug(const std::string& msg);
@@ -35,7 +35,12 @@ namespace Log
void fatal(const std::string& msg);
void sysfatal(const std::string& msg);
- inline bool traceEnabled() { return logger().getLevel() > Poco::Message::PRIO_TRACE; }
+ inline bool traceEnabled() { return logger().getLevel() >= Poco::Message::PRIO_TRACE; }
+ inline bool debugEnabled() { return logger().getLevel() >= Poco::Message::PRIO_DEBUG; }
+ inline bool infoEnabled() { return logger().getLevel() >= Poco::Message::PRIO_INFORMATION; }
+ inline bool warnEnabled() { return logger().getLevel() >= Poco::Message::PRIO_WARNING; }
+ inline bool errorEnabled() { return logger().getLevel() >= Poco::Message::PRIO_ERROR; }
+ inline bool fatalEnabled() { return logger().getLevel() >= Poco::Message::PRIO_FATAL; }
/// Signal safe prefix logging
void signalLogPrefix();
@@ -63,10 +68,11 @@ namespace Log
{
}
- StreamLogger(std::function<void(const std::string&)> func)
+ StreamLogger(std::function<void(const std::string&)> func, const char* level)
: _func(std::move(func)),
_enabled(true)
{
+ _stream << prefix(level);
}
StreamLogger(StreamLogger&& sl) noexcept
@@ -96,33 +102,43 @@ namespace Log
inline StreamLogger trace()
{
return traceEnabled()
- ? StreamLogger([](const std::string& msg) { trace(msg); })
+ ? StreamLogger([](const std::string& msg) { logger().trace(msg); }, "TRC")
: StreamLogger();
}
inline StreamLogger debug()
{
- return StreamLogger([](const std::string& msg) { debug(msg); });
+ return debugEnabled()
+ ? StreamLogger([](const std::string& msg) { logger().debug(msg); }, "DBG")
+ : StreamLogger();
}
inline StreamLogger info()
{
- return StreamLogger([](const std::string& msg) { info(msg); });
+ return infoEnabled()
+ ? StreamLogger([](const std::string& msg) { logger().information(msg); }, "INF")
+ : StreamLogger();
}
inline StreamLogger warn()
{
- return StreamLogger([](const std::string& msg) { warn(msg); });
+ return warnEnabled()
+ ? StreamLogger([](const std::string& msg) { logger().warning(msg); }, "WRN")
+ : StreamLogger();
}
inline StreamLogger error()
{
- return StreamLogger([](const std::string& msg) { error(msg); });
+ return errorEnabled()
+ ? StreamLogger([](const std::string& msg) { logger().error(msg); }, "ERR")
+ : StreamLogger();
}
inline StreamLogger fatal()
{
- return StreamLogger([](const std::string& msg) { fatal(msg); });
+ return fatalEnabled()
+ ? StreamLogger([](const std::string& msg) { logger().fatal(msg); }, "FTL")
+ : StreamLogger();
}
template <typename U>
More information about the Libreoffice-commits
mailing list