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

Added log storing for ign-gui #272

Merged
merged 3 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 20 additions & 0 deletions src/ign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ char* g_argv[] =
reinterpret_cast<char*>(const_cast<char*>("./ignition")),
};

//////////////////////////////////////////////////
void startConsoleLog()
{
std::string home;
ignition::common::env(IGN_HOMEDIR, home);

std::string logPathMod = ignition::common::joinPaths(home,
".ignition", "gui", "log",
ignition::common::timeToIso(IGN_SYSTEM_TIME()));
ignLogInit(logPathMod, "console.log");
}

//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE char *ignitionVersion()
{
Expand All @@ -42,6 +54,8 @@ extern "C" IGNITION_GUI_VISIBLE char *ignitionVersion()
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdPluginList()
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv);

auto pluginsList = app.PluginList();
Expand All @@ -65,6 +79,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdPluginList()
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdStandalone(const char *_filename)
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv,
ignition::gui::WindowType::kDialog);

Expand All @@ -79,6 +95,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdStandalone(const char *_filename)
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdConfig(const char *_config)
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv);

if (!app.findChild<ignition::gui::MainWindow *>())
Expand All @@ -103,6 +121,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdVerbose(const char *_verbosity)
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdEmptyWindow()
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv);

if (!app.findChild<ignition::gui::MainWindow *>())
Expand Down
37 changes: 36 additions & 1 deletion src/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <string>

#include <ignition/common/Filesystem.hh>
#include <ignition/common/Util.hh>
#include <ignition/utilities/ExtraTestMacros.hh>

#include "test_config.h" // NOLINT(build/include)
Expand Down Expand Up @@ -52,10 +54,43 @@ std::string custom_exec_str(std::string _cmd)
return result;
}

using namespace ignition;

class CmdLine : public ::testing::Test
{
// Documentation inherited
protected: void SetUp() override
{
// Change environment variable so that test files aren't written to $HOME
common::env(IGN_HOMEDIR, this->realHome);
EXPECT_TRUE(common::setenv(IGN_HOMEDIR, this->kFakeHome.c_str()));
}

// Documentation inherited
protected: void TearDown() override
{
// Restore $HOME
EXPECT_TRUE(common::setenv(IGN_HOMEDIR, this->realHome.c_str()));
}

/// \brief Directory to act as $HOME for tests
public: const std::string kFakeHome = common::joinPaths(PROJECT_BINARY_PATH,
"test", "fake_home");

/// \brief Store user's real $HOME to set it back at the end of tests.
public: std::string realHome;
};

// See https:/ignitionrobotics/ign-gui/issues/75
TEST(CmdLine, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(list))
TEST_F(CmdLine, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(list))
{
EXPECT_TRUE(common::removeAll(this->kFakeHome));
chapulina marked this conversation as resolved.
Show resolved Hide resolved
EXPECT_FALSE(common::exists(this->kFakeHome));

std::string output = custom_exec_str("ign gui -l");
EXPECT_NE(output.find("TopicEcho"), std::string::npos) << output;
EXPECT_NE(output.find("Publisher"), std::string::npos) << output;

EXPECT_TRUE(common::exists(common::joinPaths(this->kFakeHome, ".ignition",
"gui")));
}
3 changes: 3 additions & 0 deletions tutorials/02_commandline.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ If you have Ignition Tools installed, you can use the `ign gui` command line too
--force-version <VERSION> Use a specific library version.

--versions Show the available versions.

When using the command line tool, all console messages are logged to
`$HOME/.ignition/gui/log/<timestamp>`.