summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-08-05 19:47:00 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2019-08-05 19:47:00 +0100
commit5bba92f76c8b563c54281d8950ab21a209bb325e (patch)
tree931033450c7c43f13b4ec772bbc389e8e2c04ef7
parentGet glibmm flags from pkg-config (diff)
downloadicetray-5bba92f76c8b563c54281d8950ab21a209bb325e.tar.bz2
icetray-5bba92f76c8b563c54281d8950ab21a209bb325e.tar.xz
icetray-5bba92f76c8b563c54281d8950ab21a209bb325e.zip
Move width limited domain writer to a general location
-rw-r--r--icetray/icetray/logWriterConsole.cpp55
-rw-r--r--icetray/icetray/logger.cpp44
-rw-r--r--icetray/icetray/logger.h13
3 files changed, 58 insertions, 54 deletions
diff --git a/icetray/icetray/logWriterConsole.cpp b/icetray/icetray/logWriterConsole.cpp
index 11d9a16..5894e47 100644
--- a/icetray/icetray/logWriterConsole.cpp
+++ b/icetray/icetray/logWriterConsole.cpp
@@ -1,64 +1,11 @@
#include <logWriter.h>
#include "logWriterConsole.h"
-#include <compileTimeFormatter.h>
#include <slicer/modelPartsTypes.h>
-namespace AdHoc {
- AdHocFormatter(DomainFmt, ".%?");
- StreamWriterT('d') {
- template<typename ... Pn>
- static void write(stream & s, ssize_t width, const IceTray::Logging::Domain & domain, const Pn & ... pn)
- {
- auto di = domain.begin();
- if (di == domain.end()) {
- return StreamWriter::next(s, pn...);
- }
-
- if (width == -1) {
- s << *di++;
- while (di != domain.end()) {
- DomainFmt::write(s, *di++);
- }
- }
- else {
- auto target = width;
- while (di != domain.end()) {
- auto total = di == domain.begin() ? -1 : 0;
- for (auto dic = di; dic != domain.end(); dic++) {
- total += 1 + dic->length();
- }
- if (di == domain.begin()) {
- if (total > target) {
- s << di->front();
- target -= 1;
- }
- else {
- s << *di;
- target -= di->length();
- }
- }
- else {
- if (total > target) {
- DomainFmt::write(s, di->front());
- target -= 2;
- }
- else {
- DomainFmt::write(s, *di);
- target -= 1 + di->length();
- }
- }
- di++;
- }
- }
- StreamWriter::next(s, pn...);
- }
- };
-}
-
// NOLINTNEXTLINE(modernize-concat-nested-namespaces)
namespace IceTray {
namespace Logging {
- AdHocFormatter(LogMsg, "%?: %d: %?\n");
+ AdHocFormatter(LogMsg, "%?: %D: %?\n");
ConsoleLogWriter::ConsoleLogWriter(const Ice::PropertiesPtr & p) :
AbstractLogWriter("logging.console", p),
width(p ? p->getPropertyAsIntWithDefault("logging.console.width", -1) : -1)
diff --git a/icetray/icetray/logger.cpp b/icetray/icetray/logger.cpp
index 6ceff96..0944947 100644
--- a/icetray/icetray/logger.cpp
+++ b/icetray/icetray/logger.cpp
@@ -228,6 +228,50 @@ namespace IceTray {
boost::algorithm::split(domainTokens, domain, boost::algorithm::is_any_of(".:"), boost::algorithm::token_compress_on);
return domainTokens;
}
+
+ AdHocFormatter(DomainFmt, ".%?");
+ void
+ AbstractLogWriter::writeDomain(std::ostream & s, ssize_t width, const IceTray::Logging::Domain & domain)
+ {
+ if (auto di = domain.begin(); di != domain.end()) {
+ if (width == -1) {
+ s << *di++;
+ while (di != domain.end()) {
+ DomainFmt::write(s, *di++);
+ }
+ }
+ else {
+ auto target = width;
+ while (di != domain.end()) {
+ auto total = di == domain.begin() ? -1 : 0;
+ for (auto dic = di; dic != domain.end(); dic++) {
+ total += 1 + dic->length();
+ }
+ if (di == domain.begin()) {
+ if (total > target) {
+ s << di->front();
+ target -= 1;
+ }
+ else {
+ s << *di;
+ target -= di->length();
+ }
+ }
+ else {
+ if (total > target) {
+ DomainFmt::write(s, di->front());
+ target -= 2;
+ }
+ else {
+ DomainFmt::write(s, *di);
+ target -= 1 + di->length();
+ }
+ }
+ di++;
+ }
+ }
+ }
+ }
}
}
diff --git a/icetray/icetray/logger.h b/icetray/icetray/logger.h
index 5e7ef1f..2cdfcb1 100644
--- a/icetray/icetray/logger.h
+++ b/icetray/icetray/logger.h
@@ -10,6 +10,7 @@
#include <shared_mutex>
#include <Ice/Properties.h>
#include <globalStatic.h>
+#include <compileTimeFormatter.h>
namespace IceTray {
namespace Logging {
@@ -106,6 +107,7 @@ namespace IceTray {
public:
static Domain splitDomain(const std::string &);
+ static void writeDomain(std::ostream &, ssize_t, const Domain &);
};
typedef AdHoc::Factory<LogWriter, const Ice::PropertiesPtr &> LogWriterFactory;
@@ -116,5 +118,16 @@ namespace LOG = ::IceTray::Logging;
#define LOGMANAGER() (::IceTray::Logging::LogManager::getDefault())
+namespace AdHoc {
+ StreamWriterT('D') {
+ template<typename ... Pn>
+ static void write(stream & s, ssize_t width, const IceTray::Logging::Domain & domain, const Pn & ... pn)
+ {
+ IceTray::Logging::AbstractLogWriter::writeDomain(s, width, domain);
+ StreamWriter::next(s, pn...);
+ }
+ };
+}
+
#endif