Skip to content

Commit 7589567

Browse files
alxbilgerfredroy
authored andcommitted
[Helper] Replace console message handler instantiation with singleton usage
1 parent 981e53a commit 7589567

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

Sofa/Component/SceneUtility/src/sofa/component/sceneutility/MessageHandlerComponent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void MessageHandlerComponent::parse ( core::objectmodel::BaseObjectDescription*
7878
const string stype(type) ;
7979

8080
if(stype=="sofa"){
81-
MessageDispatcher::addHandler(new ConsoleMessageHandler()) ;
81+
MessageDispatcher::addHandler(&sofa::helper::logging::MainConsoleMessageHandler::getInstance()) ;
8282
}else if(stype=="clang"){
8383
MessageDispatcher::addHandler(new ClangMessageHandler()) ;
8484
}else if(stype=="rich"){

Sofa/framework/Helper/src/sofa/helper/logging/MessageDispatcher.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ namespace sofa::helper::logging
6464
/// some of them are duplicated
6565
/// other get a weak reference
6666

67-
std::vector<MessageHandler*> getDefaultMessageHandlers(){
68-
std::vector<MessageHandler*> messageHandlers;
69-
static ConsoleMessageHandler s_consoleMessageHandler(&DefaultStyleMessageFormatter::getInstance());
70-
messageHandlers.push_back(&s_consoleMessageHandler);
71-
return messageHandlers;
67+
std::vector<MessageHandler*> getDefaultMessageHandlers()
68+
{
69+
return { &sofa::helper::logging::MainConsoleMessageHandler::getInstance() };
7270
}
7371

7472
class MessageDispatcherImpl

applications/projects/runSofa/Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ int main(int argc, char** argv)
338338
if (messageHandler == "auto" )
339339
{
340340
MessageDispatcher::clearHandlers() ;
341-
MessageDispatcher::addHandler( new ConsoleMessageHandler() ) ;
341+
MessageDispatcher::addHandler( &sofa::helper::logging::MainConsoleMessageHandler::getInstance() ) ;
342342
}
343343
else if (messageHandler == "clang")
344344
{
@@ -348,7 +348,7 @@ int main(int argc, char** argv)
348348
else if (messageHandler == "sofa")
349349
{
350350
MessageDispatcher::clearHandlers() ;
351-
MessageDispatcher::addHandler( new ConsoleMessageHandler() ) ;
351+
MessageDispatcher::addHandler( &sofa::helper::logging::MainConsoleMessageHandler::getInstance() ) ;
352352
}
353353
else if (messageHandler == "rich")
354354
{

0 commit comments

Comments
 (0)