Improved unit test logging:

Logging from the Application object in the Env is
redirected to the suite::log, with the severity level
set to error and above.
This commit is contained in:
Vinnie Falco
2016-01-26 13:43:20 -05:00
committed by Nik Bougalis
parent 5ac744ff66
commit 2be11874e3
4 changed files with 95 additions and 22 deletions

View File

@@ -25,6 +25,7 @@
#include <beast/utility/Journal.h>
#include <boost/filesystem.hpp>
#include <map>
#include <memory>
#include <mutex>
#include <utility>
@@ -145,7 +146,9 @@ private:
};
std::mutex mutable mutex_;
std::map <std::string, Sink, beast::ci_less> sinks_;
std::map <std::string,
std::unique_ptr<beast::Journal::Sink>,
beast::ci_less> sinks_;
beast::Journal::Severity level_;
File file_;
bool silent_ = false;
@@ -159,10 +162,10 @@ public:
bool
open (boost::filesystem::path const& pathToLogFile);
Sink&
beast::Journal::Sink&
get (std::string const& name);
Sink&
beast::Journal::Sink&
operator[] (std::string const& name);
beast::Journal
@@ -195,6 +198,11 @@ public:
silent_ = bSilent;
}
virtual
std::unique_ptr<beast::Journal::Sink>
makeSink(std::string const& partition,
beast::Journal::Severity startingLevel);
public:
static
LogSeverity

View File

@@ -119,17 +119,16 @@ Logs::open (boost::filesystem::path const& pathToLogFile)
return file_.open(pathToLogFile);
}
Logs::Sink&
beast::Journal::Sink&
Logs::get (std::string const& name)
{
std::lock_guard <std::mutex> lock (mutex_);
auto const result (sinks_.emplace (std::piecewise_construct,
std::forward_as_tuple(name), std::forward_as_tuple (name,
level_, *this)));
return result.first->second;
auto const result =
sinks_.emplace(name, makeSink(name, level_));
return *result.first->second;
}
Logs::Sink&
beast::Journal::Sink&
Logs::operator[] (std::string const& name)
{
return get(name);
@@ -153,7 +152,7 @@ Logs::severity (beast::Journal::Severity level)
std::lock_guard <std::mutex> lock (mutex_);
level_ = level;
for (auto& sink : sinks_)
sink.second.severity (level);
sink.second->severity (level);
}
std::vector<std::pair<std::string, std::string>>
@@ -164,7 +163,7 @@ Logs::partition_severities() const
list.reserve (sinks_.size());
for (auto const& e : sinks_)
list.push_back(std::make_pair(e.first,
toString(fromSeverity(e.second.severity()))));
toString(fromSeverity(e.second->severity()))));
return list;
}
@@ -193,6 +192,14 @@ Logs::rotate()
return "The log file could not be closed and reopened.";
}
std::unique_ptr<beast::Journal::Sink>
Logs::makeSink(std::string const& name,
beast::Journal::Severity startingLevel)
{
return std::make_unique<Sink>(
name, startingLevel, *this);
}
LogSeverity
Logs::fromSeverity (beast::Journal::Severity level)
{