Skip to content

Commit

Permalink
Merged in LogRecord_3_to_4 (pull request #557)
Browse files Browse the repository at this point in the history
3 to 4 logging behavior and tests

Approved-by: John Shepherd
  • Loading branch information
John Shepherd committed Mar 19, 2020
2 parents dca6d7d + 4a504e6 commit fd3d541
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
30 changes: 18 additions & 12 deletions src/ServerPrivate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,26 @@ void ServerPrivate::AddRecordPlugin(const ServerConfig &_config)
LoggingPlugin::LoggingPluginSuffix()) != std::string::npos)
{
// If record plugin already specified in SDF, and record flags are
// specified on command line, replace SDF parameters with those on
// command line. (If none specified on command line, use those in
// SDF.)
// specified on command line, replace SDF path with the one on
// command line.
if (pluginName->GetAsString() == LoggingPlugin::RecordPluginName())
{
std::string recordPath = ignLogDirectory();
return;
}

// If playback plugin also specified, do not add a record plugin
if (pluginName->GetAsString() == LoggingPlugin::PlaybackPluginName())
{
ignwarn << "Both record and playback are specified. "
<< "Ignoring record.\n";
// If playback plugin also specified, do not add a record plugin
if (pluginName->GetAsString() ==
LoggingPlugin::PlaybackPluginName())
{
ignwarn << "Both record and playback are specified. "
<< "Ignoring record.\n";
return;
}

// Add path to plugin
sdf::ElementPtr pathElem = std::make_shared<sdf::Element>();
pathElem->SetName("path");
pluginElem->AddElementDescription(pathElem);
pathElem = pluginElem->GetElement("path");
pathElem->AddValue("string", "", false, "");
pathElem->Set<std::string>(_config.LogRecordPath());
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extern "C" IGNITION_GAZEBO_VISIBLE int runServer(const char *_sdfString,
{
ignLogInit(serverConfig.LogRecordPath(), "server_console.log");
}

serverConfig.SetLogRecordPath(recordPathMod);

ignmsg << "Ignition Gazebo Server v" << IGNITION_GAZEBO_VERSION_FULL
Expand Down
47 changes: 22 additions & 25 deletions test/integration/log_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ TEST_F(LogSystemTest, LogPaths)
"log_record_dbl_pendulum.sdf");

// Test case 1:
// A path is specified in SDF.
// A path is specified in SDF - a feature deprecated in Ignition Dome.
// No path specified in C++ API.
// Should take SDF path. State log should be stored here. Console log is not
// initialized because ign.cc is not triggered.
// Should ignore SDF path. No default logging directory is initialized for
// state and console logs because ign.cc is not triggered.
{
// Change log path in SDF to build directory
sdf::Root recordSdfRoot;
Expand All @@ -408,10 +408,11 @@ TEST_F(LogSystemTest, LogPaths)
recordServer.Run(true, 200, false);
}

EXPECT_TRUE(common::exists(common::joinPaths(this->logDir,
// Check state.tlog is no longer stored to path specified in SDF
EXPECT_FALSE(common::exists(common::joinPaths(this->logDir,
"state.tlog")));
#ifndef __APPLE__
EXPECT_EQ(1, entryCount(this->logDir));
EXPECT_EQ(0, entryCount(this->logDir));
#endif

// Remove artifacts. Recreate new directory
Expand All @@ -434,10 +435,10 @@ TEST_F(LogSystemTest, LogPaths)
#endif

// Test case 2:
// A path is specified in SDF.
// State log should be stored in SDF path.
// Console log should be stored to default timestamp path ignLogDirectory
// because ign.cc is triggered by command line.
// A path is specified in SDF - a feature deprecated in Ignition Dome.
// SDF path should be ignored.
// State log and console log should be stored to default timestamp path
// ignLogDirectory because ign.cc is triggered by command line.
{
// Change log path in SDF to build directory
sdf::Root recordSdfRoot;
Expand All @@ -448,7 +449,6 @@ TEST_F(LogSystemTest, LogPaths)
// Save changed SDF to temporary file
std::string tmpRecordSdfPath = common::joinPaths(this->logsDir,
"with_record_path.sdf");
// TODO(anyone): Does this work on Apple?
std::ofstream ofs(tmpRecordSdfPath);
ofs << recordSdfRoot.Element()->ToString("").c_str();
ofs.close();
Expand All @@ -463,11 +463,11 @@ TEST_F(LogSystemTest, LogPaths)
std::cout << output << std::endl;
}

// Check state.tlog is stored to path specified in SDF
EXPECT_TRUE(common::exists(common::joinPaths(this->logDir,
// Check state.tlog is no longer stored to path specified in SDF
EXPECT_FALSE(common::exists(common::joinPaths(this->logDir,
"state.tlog")));
#ifndef __APPLE__
EXPECT_EQ(1, entryCount(this->logDir));
EXPECT_EQ(0, entryCount(this->logDir));

// Check the diff of list of files in directory, and assume there is
// a single diff, it being the newly created log directory from the run above.
Expand All @@ -485,23 +485,22 @@ TEST_F(LogSystemTest, LogPaths)
EXPECT_TRUE(common::exists(timestampPath));
EXPECT_TRUE(common::exists(common::joinPaths(timestampPath,
"server_console.log")));
EXPECT_EQ(1, entryCount(timestampPath));
EXPECT_TRUE(common::exists(common::joinPaths(timestampPath,
"state.tlog")));
EXPECT_EQ(2, entryCount(timestampPath));
#endif

// Remove artifacts. Recreate new directory
this->RemoveLogsDir();
this->CreateLogsDir();

// Test case 3:
// A path is specified in SDF.
// A different path is specified via C++ API.
// Should store state.tlog to SDF path. Console log is not initialized
// because ign.cc is not triggered.
// A path is specified in SDF - a feature deprecated in Ignition Dome.
// Empty path is specified via C++ API.
// Should ignore SDF path. No default logging directory is initialized for
// state and console logs because ign.cc is not triggered.
std::string stateLogPath = this->logDir;

std::string consoleLogPath = common::joinPaths(this->logsDir, "console");
common::createDirectories(consoleLogPath);

{
// Change log path in SDF to build directory
sdf::Root recordSdfRoot;
Expand All @@ -525,12 +524,10 @@ TEST_F(LogSystemTest, LogPaths)
// tlog-journal file
}

EXPECT_TRUE(common::exists(common::joinPaths(stateLogPath, "state.tlog")));
EXPECT_FALSE(common::exists(common::joinPaths(stateLogPath, "state.tlog")));
#ifndef __APPLE__
EXPECT_EQ(1, entryCount(stateLogPath));
EXPECT_EQ(0, entryCount(consoleLogPath));
EXPECT_EQ(0, entryCount(stateLogPath));
#endif
common::removeAll(consoleLogPath);

// Remove artifacts. Recreate new directory
this->RemoveLogsDir();
Expand Down

0 comments on commit fd3d541

Please sign in to comment.