-
Notifications
You must be signed in to change notification settings - Fork 362
[runSofa] Main: add an option "quiet" , ignoring info messages at start-up #6295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fredroy
wants to merge
2
commits into
sofa-framework:master
Choose a base branch
from
fredroy:runsofa_quiet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
Sofa/framework/Helper/src/sofa/helper/logging/MessageHandler.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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") | ||
|
|
@@ -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)" | ||
|
|
@@ -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 = [&]() | ||
| { | ||
| 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()); | ||
|
|
@@ -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 ) | ||
| { | ||
|
|
@@ -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); | ||
|
|
||
|
|
@@ -516,6 +534,7 @@ int main(int argc, char** argv) | |
| sofa::helper::AdvancedTimer::setOutputType("Animate", computationTimeOutputType); | ||
| } | ||
|
|
||
| messageHandler->setQuiet(false); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?