Extra space inserted when logging QString with easylogging++

220 views Asked by At

I have multiple lines of code where the logger is triggered (INFO mode):

LOG(INFO) << connectionsBOther.at(connectionIdx).line
          << " (" << QString::number(connectionsBOther.at(connectionIdx).direction) << ") | "
          << connectionsBOther.at(connectionIdx).directionTarget
          << " "
          << QString::number(connectionsBOther.at(connectionIdx).departureRelative);

An example for the output can be seen below:

2017-11-29 14:38:07,643 INFO  [default] M85 ( 2) |  Hello  1

The issue I'm having is the extra space that seems to be appended IN FRONT of the respective QString::number() call (spaces below are marked with # to mke them more visible):

2017-11-29 14:38:07,643 INFO  [default] M85#(#2)#|##Hello##1

I'm looking for the following output:

2017-11-29 14:38:07,643 INFO  [default] M85#(2)#|#Hello#1

I need to use INFO for this output. I'm used to LOG(DEBUG) putting extra spaces all over the place but wasn't expecting this for the LOG(INFO).

1

There are 1 answers

1
p-a-o-l-o On BEST ANSWER

According to this: https://github.com/muflihun/easyloggingpp/issues/179, a LoggingFlag::AutoSpacing flag is available.

From documentation (at https://github.com/muflihun/easyloggingpp#logging-flags):

You can set/unset these flags by using static el::Loggers::addFlag and el::Loggers::removeFlag. You can check to see if certain flag is available by using el::Loggers::hasFlag, all these functions take strongly-typed enum el::LoggingFlag

I think you should unset the above mentioned flag to avoid automatic spacing (i.e. to remove extra spaces from your log).

UPDATE:

If not using the << operator is something that is not a problem for you, you can always use concatenation:

LOG(INFO) << QString(connectionsBOther.at(connectionIdx).line
          + " (" + QString::number(connectionsBOther.at(connectionIdx).direction) + ") | "
          + connectionsBOther.at(connectionIdx).directionTarget
          + " "
          + QString::number(connectionsBOther.at(connectionIdx).departureRelative));