Skip to content

Commit

Permalink
Allow disabling rosout file logging (to rosout.log) (#1381)
Browse files Browse the repository at this point in the history
See issue #1380.
  • Loading branch information
yli-cpr authored and dirk-thomas committed May 18, 2018
1 parent 231f3e4 commit dac6635
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions tools/rosout/rosout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,35 @@ class Rosout

void init()
{
handle_ = fopen(log_file_name_.c_str(), "w");
bool disable_file_logging = false;
node_.getParamCached("/rosout/disable_file_logging", disable_file_logging);

if (handle_ == 0)
if (!disable_file_logging)
{
std::cerr << "Error opening rosout log file '" << log_file_name_.c_str() << "': " << strerror(errno);
}
else
{
std::cout << "logging to " << log_file_name_.c_str() << std::endl;
handle_ = fopen(log_file_name_.c_str(), "w");

std::stringstream ss;
ss << "\n\n" << ros::Time::now() << " Node Startup\n";
int written = fprintf(handle_, "%s", ss.str().c_str());
if (written < 0)
if (handle_ == 0)
{
std::cerr << "Error writting to rosout log file '" << log_file_name_.c_str() << "': " << strerror(ferror(handle_)) << std::endl;
std::cerr << "Error opening rosout log file '" << log_file_name_.c_str() << "': " << strerror(errno);
}
else if (written > 0)
else
{
current_file_size_ += written;
if (fflush(handle_))
std::cout << "logging to " << log_file_name_.c_str() << std::endl;

std::stringstream ss;
ss << "\n\n" << ros::Time::now() << " Node Startup\n";
int written = fprintf(handle_, "%s", ss.str().c_str());
if (written < 0)
{
std::cerr << "Error writting to rosout log file '" << log_file_name_.c_str() << "': " << strerror(ferror(handle_)) << std::endl;
}
else if (written > 0)
{
std::cerr << "Error flushing rosout log file '" << log_file_name_.c_str() << "': " << strerror(ferror(handle_));
current_file_size_ += written;
if (fflush(handle_))
{
std::cerr << "Error flushing rosout log file '" << log_file_name_.c_str() << "': " << strerror(ferror(handle_));
}
}
}
}
Expand All @@ -120,6 +126,11 @@ class Rosout
{
agg_pub_.publish(msg);

if (!handle_)
{
return;
}

std::stringstream ss;
ss << msg->header.stamp << " ";
switch (msg->level)
Expand Down

0 comments on commit dac6635

Please sign in to comment.