From 9aea20fdde009b1373fa1f5168303609c91196e1 Mon Sep 17 00:00:00 2001 From: Ernst Hellbar Date: Tue, 11 Feb 2025 13:24:44 +0100 Subject: [PATCH] Following changes in most recent FairLogger tag using string_view instead of string --- include/InfoLogger/InfoLogger.hxx | 7 ++----- include/InfoLogger/InfoLoggerFMQ.hxx | 4 ++-- src/InfoLogger.cxx | 8 +------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/include/InfoLogger/InfoLogger.hxx b/include/InfoLogger/InfoLogger.hxx index 38f5bec..f9f8793 100644 --- a/include/InfoLogger/InfoLogger.hxx +++ b/include/InfoLogger/InfoLogger.hxx @@ -242,19 +242,16 @@ class InfoLogger InfoLogger::Severity severity; int level; int errorCode; - const char* sourceFile; + std::string_view sourceFile; int sourceLine; }; - // make sure options are a POD struct - static_assert(std::is_pod::value, "struct InfoLoggerMessageOption is not POD"); - /// Definition of a constant, to be used for corresponding fields when not defined static constexpr InfoLoggerMessageOption undefinedMessageOption = { Severity::Undefined, // severity -1, // level -1, // errorCode - nullptr, // sourceFile + std::string_view(), // sourceFile -1, // sourceLine }; diff --git a/include/InfoLogger/InfoLoggerFMQ.hxx b/include/InfoLogger/InfoLoggerFMQ.hxx index 708a924..481f76f 100644 --- a/include/InfoLogger/InfoLoggerFMQ.hxx +++ b/include/InfoLogger/InfoLoggerFMQ.hxx @@ -91,8 +91,8 @@ void setFMQLogsToInfoLogger(AliceO2::InfoLogger::InfoLogger* logPtr = nullptr) severity, level, AliceO2::InfoLogger::InfoLogger::undefinedMessageOption.errorCode, - metadata.file.c_str(), - atoi(metadata.line.c_str()) + metadata.file, + atoi(std::string(metadata.line.data(), metadata.line.size()).c_str()) }; if (prefix == NULL) { theLogPtr->log(opt, ctx, "FMQ: %s", content.c_str()); diff --git a/src/InfoLogger.cxx b/src/InfoLogger.cxx index 7dabfcf..414526b 100644 --- a/src/InfoLogger.cxx +++ b/src/InfoLogger.cxx @@ -629,13 +629,7 @@ int InfoLogger::Impl::pushMessage(const InfoLoggerMessageOption& options, const } if (options.sourceFile != undefinedMessageOption.sourceFile) { // trim directory path to keep it short - const char *shortName=options.sourceFile; - for (int i=(int)strlen(options.sourceFile)-1; i>=0; i--) { - if (options.sourceFile[i]=='/') { - shortName=&options.sourceFile[i+1]; - break; - } - } + const char* shortName = &options.sourceFile[options.sourceFile.rfind('/') + 1]; InfoLoggerMessageHelperSetValue(msg, msgHelper.ix_errsource, String, shortName); } if (options.sourceLine != undefinedMessageOption.sourceLine) {