From 3731edae75d8ea104207dd33f512507c196ef6b3 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Thu, 31 Mar 2022 13:38:21 -0700 Subject: [PATCH 1/2] Fix issue 331 Signed-off-by: Nate Koenig --- src/Console.cc | 4 ++-- test/integration/console.cc | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test/integration/console.cc diff --git a/src/Console.cc b/src/Console.cc index 0e8b1fbbb..4dad30375 100644 --- a/src/Console.cc +++ b/src/Console.cc @@ -86,7 +86,7 @@ Logger::~Logger() ///////////////////////////////////////////////// Logger &Logger::operator()() { - Console::log << "(" << ignition::common::systemTimeIso() << ") "; + Console::log() << "(" << ignition::common::systemTimeIso() << ") "; (*this) << Console::Prefix() << this->prefix; return (*this); @@ -97,7 +97,7 @@ Logger &Logger::operator()(const std::string &_file, int _line) { int index = _file.find_last_of("/") + 1; - Console::log << "(" << ignition::common::systemTimeIso() << ") "; + Console::log() << "(" << ignition::common::systemTimeIso() << ") "; std::stringstream prefixString; prefixString << Console::Prefix() << this->prefix << "[" << _file.substr(index , _file.size() - index) << ":" diff --git a/test/integration/console.cc b/test/integration/console.cc new file mode 100644 index 000000000..267e0020f --- /dev/null +++ b/test/integration/console.cc @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 Open Source Robotics Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ + +#include + +#include "ignition/common/Console.hh" +#include "test_config.h" + +using namespace ignition; + +TEST(Console_TEST, LogInitAfterConsoleOut) +{ + std::string logFilename = "uri.log"; + std::string logDir = common::joinPaths(PROJECT_BINARY_PATH, "test", "uri"); + std::string logFile = common::joinPaths(logDir, logFilename); + + common::Console::SetVerbosity(4); + + // We are not logging to a file yet. + ignerr << "This is an error" << std::endl; + + // Initialize the log file. + ignLogInit(logDir, logFilename); + + // Run the same console output, which should output the message to the log + // file. + ignerr << "This is an error" << std::endl; + std::ifstream t(logFile); + std::string buffer((std::istreambuf_iterator(t)), + std::istreambuf_iterator()); + + EXPECT_TRUE(buffer.find("This is an error") != std::string::npos) + << "Log file content[" << buffer << "]\n"; +} From 123df4913f453cd4dc2c5df281785b8085812cf2 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Thu, 31 Mar 2022 13:41:12 -0700 Subject: [PATCH 2/2] Fix spelling Signed-off-by: Nate Koenig --- src/URI.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/URI.cc b/src/URI.cc index 67a09203d..7b38e93cc 100644 --- a/src/URI.cc +++ b/src/URI.cc @@ -1122,7 +1122,7 @@ bool URI::Valid(const std::string &_str) if (localScheme != "file" && authEndPos == authDelimPos+2) { - ignerr << "A host is manadatory when using a scheme other than file\n"; + ignerr << "A host is mandatory when using a scheme other than file\n"; return false; } else