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

Add cmake option to disable console logfile #348

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ set(sdf_import_target_name ${PROJECT_EXPORT_NAME}::${sdf_target})
set(sdf_target_output_filename "${sdf_target}-targets.cmake")


OPTION(SDFORMAT_DISABLE_CONSOLE_LOGFILE "Disable the sdformat console logfile" OFF)

if (USE_FULL_RPATH)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
Expand Down
1 change: 1 addition & 0 deletions cmake/sdf_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#cmakedefine BUILD_TYPE_RELEASE 1
#cmakedefine HAVE_URDFDOM 1
#cmakedefine USE_INTERNAL_URDF 1
#cmakedefine SDFORMAT_DISABLE_CONSOLE_LOGFILE 1

#define SDF_SHARE_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/"
#define SDF_VERSION_PATH "${CMAKE_INSTALL_FULL_DATAROOTDIR}/sdformat${SDF_MAJOR_VERSION}/${SDF_PKG_VERSION}"
5 changes: 4 additions & 1 deletion include/sdf/Console.hh
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ namespace sdf
const std::string &file,
unsigned int line, int color);

/// \brief Use this to output a message to a log file
/// \brief Use this to output a message to a log file at
/// `$HOME/.sdformat/sdformat.log`.
/// To disable this log file, define the following symbol when
/// compiling: SDFORMAT_DISABLE_CONSOLE_LOGFILE
/// \return Reference to output stream
public: ConsoleStream &Log(const std::string &lbl,
const std::string &file,
Expand Down
3 changes: 3 additions & 0 deletions src/Console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "sdf/Console.hh"
#include "sdf/Filesystem.hh"
#include "sdf/Types.hh"
#include "sdf/sdf_config.h"

using namespace sdf;

Expand All @@ -45,6 +46,7 @@ static Console::ConsoleStream g_NullStream(nullptr);
Console::Console()
: dataPtr(new ConsolePrivate)
{
#ifndef SDFORMAT_DISABLE_CONSOLE_LOGFILE
// Set up the file that we'll log to.
#ifndef _WIN32
const char *home = std::getenv("HOME");
Expand Down Expand Up @@ -72,6 +74,7 @@ Console::Console()
}
std::string logFile = sdf::filesystem::append(logDir, "sdformat.log");
this->dataPtr->logFileStream.open(logFile.c_str(), std::ios::out);
#endif
}

//////////////////////////////////////////////////
Expand Down