Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace sofa::helper::logging::percomponentloggingmessagehandler
{

void PerComponentLoggingMessageHandler::process(Message& m)
void PerComponentLoggingMessageHandler::doProcess(Message& m)
{
const SofaComponentInfo* nfo = dynamic_cast<SofaComponentInfo*>( m.componentInfo().get() ) ;
if(nfo != nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SOFA_CORE_API PerComponentLoggingMessageHandler : public MessageHandler
~PerComponentLoggingMessageHandler() override {}

/// Inherited from MessageHandler
void process(Message& m) override ;
void doProcess(Message& m) override ;
std::string getName() const override { return "PerComponentLoggingMessageHandler"; }
} ;

Expand Down
1 change: 1 addition & 0 deletions Sofa/framework/Helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ set(SOURCE_FILES
${SRC_ROOT}/logging/MessageDispatcher.cpp
${SRC_ROOT}/logging/MessageFormatter.cpp
${SRC_ROOT}/logging/ComponentInfo.cpp
${SRC_ROOT}/logging/MessageHandler.cpp
${SRC_ROOT}/logging/ClangMessageHandler.cpp
${SRC_ROOT}/logging/ClangStyleMessageFormatter.cpp
${SRC_ROOT}/logging/DefaultStyleMessageFormatter.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
namespace sofa::helper::logging
{


void ClangMessageHandler::process(Message &m) {
void ClangMessageHandler::doProcess(Message &m)
{
ClangStyleMessageFormatter::getInstance().formatMessage(m, std::cerr) ;
}

} // sofa::helper::logging

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace sofa::helper::logging
class SOFA_HELPER_API ClangMessageHandler : public MessageHandler
{
public:
void process(Message &m) override ;
void doProcess(Message &m) override ;
std::string getName() const override { return "ClangMessageHandler"; }
};
} // namespace sofa::helper::logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ ConsoleMessageHandler::ConsoleMessageHandler(MessageFormatter* formatter)
m_formatter = (formatter==nullptr?&DefaultStyleMessageFormatter::getInstance():formatter);
}

void ConsoleMessageHandler::process(Message &m) {
m_formatter->formatMessage(m, m.type()>=Message::Error ? std::cerr : std::cout ) ;
void ConsoleMessageHandler::doProcess(Message &m)
{
m_formatter->formatMessage(m, m.type()>Message::Info ? std::cerr : std::cout ) ;
}

void ConsoleMessageHandler::setMessageFormatter(MessageFormatter* formatter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SOFA_HELPER_API ConsoleMessageHandler : public MessageHandler
/// Create a new ConsoleMessageHandler. By default the handler is using the
/// DefaultStyleMessageFormatter object to format the message.
ConsoleMessageHandler(MessageFormatter* formatter = nullptr);
void process(Message &m) override ;
void doProcess(Message &m) override ;
std::string getName() const override { return "ConsoleMessageHandler"; }
void setMessageFormatter( MessageFormatter* formatter );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
namespace sofa::helper::logging::countingmessagehandler
{

void CountingMessageHandler::process(Message& m)
void CountingMessageHandler::doProcess(Message& m)
{
assert(m.type()<m_countMatching.size() && "If this happens this means that the code initializing m_countMatching is broken.") ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SOFA_HELPER_API CountingMessageHandler : public MessageHandler
int getMessageCountFor(const Message::Type& type) const ;

/// Inherited from MessageHandler
void process(Message& m) override ;
void doProcess(Message& m) override ;
std::string getName() const override { return "CountingMessageHandler"; }
private:
std::vector<int> m_countMatching ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
namespace sofa::helper::logging
{



void ExceptionMessageHandler::process(Message &m)
void ExceptionMessageHandler::doProcess(Message &m)
{
if( m.type()>=Message::Error )
{
if( m.type()>=Message::Error )
{
ErrorMessageException errorMessageException/*(some Message's information could be added to the exception)*/;
throw errorMessageException;
}
ErrorMessageException errorMessageException/*(some Message's information could be added to the exception)*/;
throw errorMessageException;
}
}

} // namespace sofa::helper::logging

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SOFA_HELPER_API ExceptionMessageHandler : public MessageHandler



void process(Message &m) override;
void doProcess(Message &m) override;
std::string getName() const override { return "ExceptionMessageHandler"; }
};
} // namespace sofa::helper::logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ FileMessageHandler::~FileMessageHandler()
m_outFile.close();
}

void FileMessageHandler::process(Message& m)
void FileMessageHandler::doProcess(Message& m)
{
if (m_outFile.is_open())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SOFA_HELPER_API FileMessageHandler : public MessageHandler
FileMessageHandler(const char* filename,MessageFormatter* formatter = nullptr);

~FileMessageHandler() override;
void process(Message& m) override ;
void doProcess(Message& m) override ;
std::string getName() const override { return "FileMessageHandler"; }

bool isValid(); // is output file ok ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace sofa::helper::logging::loggingmessagehandler
{

void LoggingMessageHandler::process(Message& m)
void LoggingMessageHandler::doProcess(Message& m)
{
if(m_activationCount>0){
m_messages.push_back(m) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SOFA_HELPER_API LoggingMessageHandler : public MessageHandler
const vector<Message>& getMessages() const ;

/// Inherited from MessageHandler
void process(Message& m) override ;
void doProcess(Message& m) override ;

std::string getName() const override { return "LoggingMessageHandler"; }

Expand Down
38 changes: 38 additions & 0 deletions Sofa/framework/Helper/src/sofa/helper/logging/MessageHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <sofa/helper/logging/MessageHandler.h>
#include <sofa/helper/logging/Message.h>


namespace sofa::helper::logging
{

void MessageHandler::process(Message& m)
{
if(not(this->isQuiet() && m.type() == Message::Info))
{
doProcess(m);
}
// else we discard as the message is an informational message and the handler is supposed to be quiet
};

} // namespace sofa::helper::logging
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ class SOFA_HELPER_API MessageHandler
{
public:
virtual ~MessageHandler(){}
virtual void process(Message& m) = 0 ;
virtual void process(Message& m) final;
virtual void doProcess(Message& m) = 0;
virtual std::string getName() const = 0;

virtual void setQuiet(bool quiet) { m_quiet = quiet; };
virtual bool isQuiet() const { return m_quiet; };

private:
bool m_quiet {false};
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace sofa::helper::logging::routingmessagehandler
{

void RoutingMessageHandler::process(Message& m)
void RoutingMessageHandler::doProcess(Message& m)
{
for(const auto& f : m_filters)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SOFA_HELPER_API RoutingMessageHandler : public MessageHandler
void removeAllFilters() ;

/// Inherited from MessageHandler
void process(Message& m) override ;
void doProcess(Message& m) override ;
std::string getName() const override { return "RoutingMessageHandler"; }

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace sofa::helper::logging
{

void SilentMessageHandler::process(Message& /*m*/) {
void SilentMessageHandler::doProcess(Message& /*m*/) {
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Message;
class SOFA_HELPER_API SilentMessageHandler : public MessageHandler
{
public:
void process(Message& /*m*/) override;
void doProcess(Message& /*m*/) override;
std::string getName() const override { return "SilentMessageHandler"; }
};

Expand Down
2 changes: 1 addition & 1 deletion Sofa/framework/Helper/test/logging/logging_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MyMessageHandler : public MessageHandler
{
vector<Message> m_messages ;
public:
void process(Message& m) override{
void doProcess(Message& m) override{
m_messages.push_back(m);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SOFA_TESTING_API GtestMessageHandler : public MessageHandler
~ GtestMessageHandler() override;

/// Inherited from MessageHandler
void process(Message& m) override ;
void doProcess(Message& m) override ;
std::string getName() const override { return "GtestMessageHandler"; }

void pushFrame(Message::Type type, GtestMessageFrame* frame) ;
Expand Down Expand Up @@ -173,7 +173,7 @@ GtestMessageHandler::GtestMessageHandler(Message::Class mclass)
}
}

void GtestMessageHandler::process(Message& m)
void GtestMessageHandler::doProcess(Message& m)
{
m_gtestframes[m.type()].back()->process(m) ;
}
Expand Down
75 changes: 47 additions & 28 deletions applications/projects/runSofa/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ int main(int argc, char** argv)
vector<string> plugins;
vector<string> files;

bool quiet = false;
string colorsStatus = "unset";
string messageHandler = "auto";
string messageHandlerString = "auto";
int width = 800;
int height = 600;

Expand Down Expand Up @@ -264,6 +265,13 @@ int main(int argc, char** argv)
"v,verification",
"load verification data for the scene"
);
argParser->addArgument(
cxxopts::value<bool>(quiet)
->default_value("false")
->implicit_value("true"),
"q,quiet",
"do not print informational messages at startup"
);
argParser->addArgument(
cxxopts::value<std::string>(colorsStatus)
->default_value("auto")
Expand All @@ -272,7 +280,7 @@ int main(int argc, char** argv)
"use colors on stdout and stderr (yes, no, auto)"
);
argParser->addArgument(
cxxopts::value<std::string>(messageHandler)
cxxopts::value<std::string>(messageHandlerString)
->default_value("auto"),
"f,formatting",
"select the message formatting to use (auto, clang, sofa, rich, test)"
Expand Down Expand Up @@ -334,33 +342,39 @@ int main(int argc, char** argv)
else if (colorsStatus == "no")
sofa::helper::console::setStatus(sofa::helper::console::Status::Off);

//TODO(dmarchal): Use smart pointer there to avoid memory leaks !!
if (messageHandler == "auto" )
{
MessageDispatcher::clearHandlers() ;
MessageDispatcher::addHandler( &sofa::helper::logging::MainConsoleMessageHandler::getInstance() ) ;
}
else if (messageHandler == "clang")
{
MessageDispatcher::clearHandlers() ;
MessageDispatcher::addHandler( new ClangMessageHandler() ) ;
}
else if (messageHandler == "sofa")
{
MessageDispatcher::clearHandlers() ;
MessageDispatcher::addHandler( &sofa::helper::logging::MainConsoleMessageHandler::getInstance() ) ;
}
else if (messageHandler == "rich")
sofa::helper::logging::MessageHandler* messageHandler = nullptr;
auto processMessageHandlerFromArg = [&]()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in a lambda although it is only used once and right after it ?

{
MessageDispatcher::clearHandlers() ;
MessageDispatcher::addHandler( new ConsoleMessageHandler(&RichConsoleStyleMessageFormatter::getInstance()) ) ;
}
else if (messageHandler == "test"){
MessageDispatcher::addHandler( new ExceptionMessageHandler() ) ;
}
else{
msg_warning(appName) << "Invalid argument '" << messageHandler << "' for '--formatting'";
}
if (messageHandlerString == "auto" || messageHandlerString == "sofa")
{
messageHandler = &sofa::helper::logging::MainConsoleMessageHandler::getInstance();
}
else if (messageHandlerString == "clang")
{
messageHandler = new ClangMessageHandler();
}
else if (messageHandlerString == "rich")
{
messageHandler = new ConsoleMessageHandler(&RichConsoleStyleMessageFormatter::getInstance());
}
else if (messageHandlerString == "test")
{
messageHandler = new ExceptionMessageHandler();
}
else{
msg_warning(appName) << "Invalid argument '" << messageHandlerString << "' for '--formatting'";
}

if(messageHandler)
{
messageHandler->setQuiet(quiet);
MessageDispatcher::addHandler(messageHandler);
}
};

MessageDispatcher::clearHandlers() ;
processMessageHandlerFromArg();

MessageDispatcher::addHandler(&MainPerComponentLoggingMessageHandler::getInstance()) ;
#ifdef TRACY_ENABLE
MessageDispatcher::addHandler(&sofa::helper::logging::MainTracyMessageHandler::getInstance());
Expand Down Expand Up @@ -486,6 +500,9 @@ int main(int argc, char** argv)
sofa::helper::AdvancedTimer::begin("Init");
}

//
messageHandler->setQuiet(false);

sofa::simulation::node::initRoot(groot.get());
if( computationTimeAtBegin )
{
Expand All @@ -499,6 +516,7 @@ int main(int argc, char** argv)
if (startAnim)
groot->setAnimate(true);

messageHandler->setQuiet(quiet);
// set scene and animation root to the gui
GUIManager::SetScene(groot, fileName.c_str(), temporaryFile);

Expand All @@ -516,6 +534,7 @@ int main(int argc, char** argv)
sofa::helper::AdvancedTimer::setOutputType("Animate", computationTimeOutputType);
}

messageHandler->setQuiet(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why three times ?

//=======================================
// Run the main loop
if (int err = GUIManager::MainLoop(groot,fileName.c_str()))
Expand Down
Loading