@@ -165,19 +165,19 @@ void RiaDefaultConsoleLogger::writeToConsole( const std::string& str )
165165// --------------------------------------------------------------------------------------------------
166166// /
167167// --------------------------------------------------------------------------------------------------
168- void RiaLogging::setLastMessage ( const QString& message )
168+ void RiaLogging::setLastMessage ( std::string_view message )
169169{
170170#pragma omp critical( critical_section_logging )
171171 {
172- sm_lastMessage = message;
172+ sm_lastMessage. assign ( message ) ;
173173 sm_lastMessageTime = std::chrono::high_resolution_clock::now ();
174174 }
175175}
176176
177177// --------------------------------------------------------------------------------------------------
178178// /
179179// --------------------------------------------------------------------------------------------------
180- bool RiaLogging::isSameMessage ( const QString& message )
180+ bool RiaLogging::isSameMessage ( std::string_view message )
181181{
182182 bool isSame = false ;
183183
@@ -198,14 +198,23 @@ bool RiaLogging::isSameMessage( const QString& message )
198198 return isSame;
199199}
200200
201+ // --------------------------------------------------------------------------------------------------
202+ // /
203+ // --------------------------------------------------------------------------------------------------
204+ bool RiaLogging::isKeywordEnabled ( std::string_view keyword )
205+ {
206+ return RiaPreferencesSystem::current ()->isLoggingActivatedForKeyword (
207+ QString::fromUtf8 ( keyword.data (), static_cast <qsizetype>( keyword.size () ) ) );
208+ }
209+
201210// ==================================================================================================
202211//
203212//
204213//
205214// ==================================================================================================
206215
207216std::vector<std::unique_ptr<RiaLogger>> RiaLogging::sm_logger;
208- QString RiaLogging::sm_lastMessage;
217+ std::string RiaLogging::sm_lastMessage;
209218std::chrono::time_point<std::chrono::high_resolution_clock> RiaLogging::sm_lastMessageTime;
210219
211220// --------------------------------------------------------------------------------------------------
@@ -261,87 +270,48 @@ std::optional<RILogLevel> RiaLogging::parseLogLevelString( const QString& logLev
261270}
262271
263272// --------------------------------------------------------------------------------------------------
264- // /
273+ // / QString overloads forward to the templated StdStringLike overloads, which hold the canonical
274+ // / implementation. The QByteArray locals keep the underlying bytes alive for the call.
265275// --------------------------------------------------------------------------------------------------
266- void RiaLogging::error ( const QString& message, const QString logKeyword )
276+ void RiaLogging::error ( const QString& message, const QString& logKeyword )
267277{
268- if ( !RiaPreferencesSystem::current ()->isLoggingActivatedForKeyword ( logKeyword ) ) return ;
269-
270- if ( isSameMessage ( message ) ) return ;
271-
272- for ( const auto & logger : sm_logger )
273- {
274- if ( logger && logger->level () >= int ( RILogLevel::RI_LL_ERROR ) )
275- {
276- #pragma omp critical( critical_section_logging )
277- logger->error ( message.toLatin1 ().constData () );
278- }
279- }
280-
281- setLastMessage ( message );
278+ const auto msgUtf8 = message.toUtf8 ();
279+ const auto kwUtf8 = logKeyword.toUtf8 ();
280+ error ( std::string_view{ msgUtf8.constData (), static_cast <size_t >( msgUtf8.size () ) },
281+ std::string_view{ kwUtf8.constData (), static_cast <size_t >( kwUtf8.size () ) } );
282282}
283283
284284// --------------------------------------------------------------------------------------------------
285285// /
286286// --------------------------------------------------------------------------------------------------
287- void RiaLogging::warning ( const QString& message, const QString logKeyword )
287+ void RiaLogging::warning ( const QString& message, const QString& logKeyword )
288288{
289- if ( !RiaPreferencesSystem::current ()->isLoggingActivatedForKeyword ( logKeyword ) ) return ;
290-
291- if ( isSameMessage ( message ) ) return ;
292-
293- for ( const auto & logger : sm_logger )
294- {
295- if ( logger && logger->level () >= int ( RILogLevel::RI_LL_WARNING ) )
296- {
297- #pragma omp critical( critical_section_logging )
298- logger->warning ( message.toLatin1 ().constData () );
299- }
300- }
301-
302- setLastMessage ( message );
289+ const auto msgUtf8 = message.toUtf8 ();
290+ const auto kwUtf8 = logKeyword.toUtf8 ();
291+ warning ( std::string_view{ msgUtf8.constData (), static_cast <size_t >( msgUtf8.size () ) },
292+ std::string_view{ kwUtf8.constData (), static_cast <size_t >( kwUtf8.size () ) } );
303293}
304294
305295// --------------------------------------------------------------------------------------------------
306296// /
307297// --------------------------------------------------------------------------------------------------
308- void RiaLogging::info ( const QString& message, const QString logKeyword )
298+ void RiaLogging::info ( const QString& message, const QString& logKeyword )
309299{
310- if ( !RiaPreferencesSystem::current ()->isLoggingActivatedForKeyword ( logKeyword ) ) return ;
311-
312- if ( isSameMessage ( message ) ) return ;
313-
314- for ( const auto & logger : sm_logger )
315- {
316- if ( logger && logger->level () >= int ( RILogLevel::RI_LL_INFO ) )
317- {
318- #pragma omp critical( critical_section_logging )
319- logger->info ( message.toLatin1 ().constData () );
320- }
321- }
322-
323- setLastMessage ( message );
300+ const auto msgUtf8 = message.toUtf8 ();
301+ const auto kwUtf8 = logKeyword.toUtf8 ();
302+ info ( std::string_view{ msgUtf8.constData (), static_cast <size_t >( msgUtf8.size () ) },
303+ std::string_view{ kwUtf8.constData (), static_cast <size_t >( kwUtf8.size () ) } );
324304}
325305
326306// --------------------------------------------------------------------------------------------------
327307// /
328308// --------------------------------------------------------------------------------------------------
329- void RiaLogging::debug ( const QString& message, const QString logKeyword )
309+ void RiaLogging::debug ( const QString& message, const QString& logKeyword )
330310{
331- if ( !RiaPreferencesSystem::current ()->isLoggingActivatedForKeyword ( logKeyword ) ) return ;
332-
333- if ( isSameMessage ( message ) ) return ;
334-
335- for ( const auto & logger : sm_logger )
336- {
337- if ( logger && logger->level () >= int ( RILogLevel::RI_LL_DEBUG ) )
338- {
339- #pragma omp critical( critical_section_logging )
340- logger->debug ( message.toLatin1 ().constData () );
341- }
342- }
343-
344- setLastMessage ( message );
311+ const auto msgUtf8 = message.toUtf8 ();
312+ const auto kwUtf8 = logKeyword.toUtf8 ();
313+ debug ( std::string_view{ msgUtf8.constData (), static_cast <size_t >( msgUtf8.size () ) },
314+ std::string_view{ kwUtf8.constData (), static_cast <size_t >( kwUtf8.size () ) } );
345315}
346316
347317// --------------------------------------------------------------------------------------------------
0 commit comments