dlr-gtlab / gt-logging

Basic C++14 logging library based on QsLog
0 stars 0 forks source link

Enabling "log file and line numbers" flag will break verbosity levels #43

Closed rainman110 closed 10 months ago

rainman110 commented 1 year ago

In GitLab by @mariusalexander on May 3, 2023, 12:31

Enabling the GT_LOG_IMPL_LINE_NUMBERS flag and using verbosity levels will still log the file and line numbers.

Example:

gtDebug().verbose() << "Test";
>> "my_file@123:"

Explanation

A macro like gtDebug will be expanded to

if (gt::log::Logger::instance().loggingLevel() > gt::log::Debug) {
}
else gt::log::Logger::Helper(gt::log::Debug).stream() GT_LOG_IMPL_LINE_NUMBERS GT_LOG_IMPL_QUOTE GT_LOG_IMPL_NOSPACE

If the GT_LOG_LINE_NUMBERS flag is enabled the macro GT_LOG_IMPL_LINE_NUMBERS will be replaced by .operator<<( __FILE__ "@" GT_LOG_TO_STR(__LINE__) ":")

The logging statement

gtDebug().verbose() << "Test";

will therefore effectively be translated to

gt::log::Logger::Helper(gt::log::Debug).stream().operator<<("my_file@123:").verbose() << "Test"

One can now see that the file and line numbers will be printed but not the rest of the message.

Obviously the file and line numbers should not be logged when using a higher verbosity level. This would either require changes to the logging macro or an additional check in the gt::log::Logger::Helper destructor for the verbosity level.

rainman110 commented 1 year ago

In GitLab by @mariusalexander on May 3, 2023, 13:47

created branch 43-enabling-log-file-and-line-numbers-flag-will-break-verbosity-levels to address this issue

rainman110 commented 1 year ago

In GitLab by @rainman110 on May 5, 2023, 10:08

mentioned in commit 40b1f321d093f22b14c72376ff3219ffa8ca15ee