diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f37ac87..9f7ed1f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ option(OPT_SAMPLES "Build the samples" ON) option(OPT_BUILD_TESTS "Build the tests" OFF) option(OPT_BUILD_STATIC "Build static libraries for the client" ON) option(OPT_LOG4CXX "Use log4cxx for logging" ON) +option(OPT_OUTPUTDEBUGSTRING "Use OutputDebugString logging (only Windows, log4cxx preferred)" OFF) # Use, i.e. don't skip the full RPATH for the build tree set(CMAKE_SKIP_BUILD_RPATH FALSE) @@ -136,6 +137,11 @@ endif() set(MUJINCLIENT_LINK_DIRS) +set(MUJINCLIENT_OUTPUTDEBUGSTRING 0) +if(OPT_OUTPUTDEBUGSTRING AND MSVC) + set(MUJINCLIENT_OUTPUTDEBUGSTRING 1) +endif() + find_package(PkgConfig) set(MUJINCLIENT_LOG4CXX 0) if (OPT_LOG4CXX) diff --git a/config.h.in b/config.h.in index d6da334a..de79f43e 100644 --- a/config.h.in +++ b/config.h.in @@ -51,6 +51,7 @@ // whether log4cxx is to be used #define MUJINCLIENT_LOG4CXX @MUJINCLIENT_LOG4CXX@ +#define MUJINCLIENT_OUTPUTDEBUGSTRING @MUJINCLIENT_OUTPUTDEBUGSTRING@ #define MUJIN_USEZMQ @MUJIN_USEZMQ@ #endif diff --git a/src/controllerclientimpl.cpp b/src/controllerclientimpl.cpp index 6453fad2..8216ef39 100644 --- a/src/controllerclientimpl.cpp +++ b/src/controllerclientimpl.cpp @@ -199,7 +199,7 @@ ControllerClientImpl::ControllerClientImpl(const std::string& usernamepassword, _charset = itcodepage->second; } #endif - MUJIN_LOG_INFO("setting character set to " << _charset); + MUJIN_LOG_INFO(std::string("setting character set to ")+_charset); _SetupHTTPHeadersJSON(); _SetupHTTPHeadersSTL(); _SetupHTTPHeadersMultipartFormData(); @@ -1837,7 +1837,7 @@ void ControllerClientImpl::_DeleteDirectoryOnController(const std::string& destu CURL_PERFORM(_curl); long http_code = 0; CURL_INFO_GETTER(_curl, CURLINFO_RESPONSE_CODE, &http_code); - MUJIN_LOG_INFO("response code: " << http_code); + MUJIN_LOG_INFO(str(boost::format("response code: %d")%http_code)); } size_t ControllerClientImpl::_ReadUploadCallback(void *ptr, size_t size, size_t nmemb, void *stream) diff --git a/src/logging.h b/src/logging.h index 662d8c6d..51723519 100644 --- a/src/logging.h +++ b/src/logging.h @@ -19,6 +19,14 @@ #define MUJIN_LOG_INFO(msg) LOG4CXX_INFO(logger, msg); #define MUJIN_LOG_ERROR(msg) LOG4CXX_ERROR(logger, msg); +#elif MUJINCLIENT_OUTPUTDEBUGSTRING + +#define MUJIN_LOGGER(name) +#define MUJIN_LOG_VERBOSE(msg) // empty +#define MUJIN_LOG_DEBUG(msg) OutputDebugString(std::string(msg).c_str()); +#define MUJIN_LOG_INFO(msg) OutputDebugString(std::string(msg).c_str()); +#define MUJIN_LOG_ERROR(msg) OutputDebugString(std::string(msg).c_str()); + #else #define MUJIN_LOGGER(name) diff --git a/src/mujinzmq.cpp b/src/mujinzmq.cpp index eb1bf1d6..84bcf85b 100644 --- a/src/mujinzmq.cpp +++ b/src/mujinzmq.cpp @@ -290,7 +290,7 @@ std::string ZmqClient::Call(const std::string& msg, const double timeout, const ss << "Timed out trying to send request."; MUJIN_LOG_ERROR(ss.str()); if (msg.length() > 1000) { - MUJIN_LOG_INFO(msg.substr(0,1000) << "..."); + MUJIN_LOG_INFO(msg.substr(0,1000)+"..."); } else { MUJIN_LOG_INFO(msg); } @@ -354,7 +354,7 @@ std::string ZmqClient::Call(const std::string& msg, const double timeout, const } else { MUJIN_LOG_INFO("failed to send"); if (msg.length() > 1000) { - MUJIN_LOG_INFO(msg.substr(0,1000) << "..."); + MUJIN_LOG_INFO(msg.substr(0,1000)+"..."); } else { MUJIN_LOG_INFO(msg); } @@ -379,7 +379,7 @@ std::string ZmqClient::Call(const std::string& msg, const double timeout, const ss << "timed out trying to receive request"; MUJIN_LOG_ERROR(ss.str()); if (msg.length() > 1000) { - MUJIN_LOG_INFO(msg.substr(0,1000) << "..."); + MUJIN_LOG_INFO(msg.substr(0,1000)+"..."); } else { MUJIN_LOG_INFO(msg); }