Skip to content
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

Disable rosout.log by using environment variable #1425

Merged
merged 9 commits into from
Aug 8, 2018

Conversation

yli-cpr
Copy link
Contributor

@yli-cpr yli-cpr commented Jun 6, 2018

rosout is usually started together with roscore. There may be race condition so that it cannot connect to the master during initialization. This change lets rosout wait at most 1 second for the master to be online, so that it can read the ROS parameter.

@mikepurvis
Copy link
Member

Rather than blocking startup of the node, can we do something like check on each message received until either we get an answer or 10s have elapsed, and then stop checking?

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jun 6, 2018

That may leave a rosout.log file on the disk. When the first message arrives the master must have been online, I guess? What about opening the file upon the first received message?

Another idea is to make it runtime parameter, so we check the paramter every time when we are going to log a message.

What do you think?

I don't like environment variable solution because, when roslaunch spawns rosout process, it seems not to use the environment variables defined in the launch file.

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jun 6, 2018

Using environment variable will be a clean change though

@yli-cpr yli-cpr changed the title rosout waits 1 second for parameter to be available. Disable rosout.log by using environment variable Jun 6, 2018
The parameter server may not be available at the time rosout is
starting.
@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jun 6, 2018

The test failure seems unrelated? 12:06:45 Caused by: com.fasterxml.jackson.core.JsonParseException: Numeric value (5048810355) out of range of int


if (!disable_file_logging)
const char* disable_file_logging = getenv("ROSOUT_DISABLE_FILE_LOGGING");
if (!disable_file_logging || !boost::iequals(disable_file_logging, "true"))
Copy link
Member

Choose a reason for hiding this comment

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

This is new to me. Other than the allocation, is there any advantage to this over just instantiating a throwaway std::string and comparing that directly?

Copy link
Contributor Author

@yli-cpr yli-cpr Jun 7, 2018

Choose a reason for hiding this comment

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

std::string cannot be constructed with nullptr. So anyway, checking for null is required. I first tried std::string and got an exception complaining about nullptr

Copy link
Member

Choose a reason for hiding this comment

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

gotcha, makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

The case insensitive comparison to true seems to be rather restrictive. I would suggest the opposite and if the string is empty or 0 (maybe "false", "off"?) consider the value to be false, otherwise true.

@mikepurvis
Copy link
Member

LGTM, but you'll need to add the boost dependency to this package's package.xml:

https://github.com/ros/ros_comm/blob/melodic-devel/tools/rosout/package.xml#L15-L19

IMO a good opportunity to consolidate the build/run deps and switch this one to format="2" as well.

The wiki page describing the parameter will need to be updated to describe the envvar, once this is merged: http://wiki.ros.org/rosout#rosout.log

Will wait on @dirk-thomas for any final thoughts.

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jun 11, 2018

Thanks. Updated the package.xml. Also submitted a change to the wiki page.

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jun 15, 2018

The wiki page has been updated. Ping @dirk-thomas
@mikepurvis we will need this in lunar-edge branch

@jliviero
Copy link
Contributor

jliviero commented Jul 10, 2018

You may need to add Boost to CMake as well:

You could also avoid needing to pull in the Boost dependency altogether by doing something like the following (and let's avoid the nasty true/True discrepancy we've seen before at the same time):

const char* disable_logging_env = getenv("ROSOUT_DISABLE_FILE_LOGGING"); 
std::string disable_file_logging = disable_logging_env ? disable_logging_env : "false";
std::transform(disable_file_logging.begin(), disable_file_logging.end(), disable_file_logging.begin(), ::tolower);

if (disable_file_logging == "true")
{
   // ...etc
}

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jul 10, 2018

Thanks for the suggestions.

find_package(Boost REQUIRED COMPONENTS thread)

This is not needed for boost algorithm because that lib is headers only. I remember it gave an error when I tried that with algorithm.

I could use find_package(Boost) and add the boost include directories. However, it is not mentioned in the catkin wiki page, and the fact it builds probably means the boost include directories is already included in catkin_INCLUDE_DIRS.

Opinions?

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jul 10, 2018

Added Boost_INCLUDE_DIRS explicitly

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Jul 19, 2018

The test failure is not related.

@dirk-thomas
Copy link
Member

Just as a note: this patch revert the logic added in #1381.

It also looks like that the documentation has already been updated to reflect the proposed change: http://wiki.ros.org/action/info/rosout?action=diff&rev2=53&rev1=52 Please do not update the wiki with not yet merged changes since that feature is not yet usable by users.

@yli-cpr
Copy link
Contributor Author

yli-cpr commented Aug 7, 2018

Yes, lesson learned. Will do the change.

|| strcmp(disable_file_logging, "0") == 0
|| boost::iequals(disable_file_logging, "false")
|| boost::iequals(disable_file_logging, "off")
|| boost::iequals(disable_file_logging, "no"))
Copy link
Member

Choose a reason for hiding this comment

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

I am just wondering if the case insensitive comparison if worth the boost dependency? Each condition could be duplicates to check for lower case as well as upper case (not allowing mixed case)...

Copy link
Contributor

@jliviero jliviero Aug 7, 2018

Choose a reason for hiding this comment

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

You don't need boost for case-insensitivity. Just convert the input value to lower case before comparing:

#1425 (comment)

@dirk-thomas
Copy link
Member

Thank you for the patch and for iterating on it.

@dirk-thomas dirk-thomas merged commit 678ad4f into ros:melodic-devel Aug 8, 2018
@yli-cpr
Copy link
Contributor Author

yli-cpr commented Aug 9, 2018

Thanks for the cleanup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants