Skip to content

Commit

Permalink
Merge pull request #335 from ignitionrobotics/4-to-5-20220401
Browse files Browse the repository at this point in the history
4 to 5 20220401
  • Loading branch information
nkoenig authored Apr 1, 2022
2 parents d266053 + 831924d commit f50d514
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Logger::~Logger()
/////////////////////////////////////////////////
Logger &Logger::operator()()
{
Console::log << "(" << ignition::common::systemTimeIso() << ") ";
Console::log() << "(" << ignition::common::systemTimeIso() << ") ";
(*this) << Console::Prefix() << this->prefix;

return (*this);
Expand All @@ -98,7 +98,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) << ":"
Expand Down
2 changes: 1 addition & 1 deletion src/URI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,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
Expand Down
48 changes: 48 additions & 0 deletions test/integration/console.cc
Original file line number Diff line number Diff line change
@@ -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 <gtest/gtest.h>

#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<char>(t)),
std::istreambuf_iterator<char>());

EXPECT_TRUE(buffer.find("This is an error") != std::string::npos)
<< "Log file content[" << buffer << "]\n";
}

0 comments on commit f50d514

Please sign in to comment.