Cleanups in beast::Journal:

The Journal API is affected.  There are two uses for the
Journal::Severity enum:

 o It is used to declare a threshold which log messages must meet
   in order to be logged.

 o It declares the current logging level which will be compared
   to the threshold.

Those uses that affect the threshold are now named threshold()
rather than severity() to make the uses easier to distinguish.

Additionally, Journal no longer carries a Severity variable.
All handling of the threshold() is now delegated to the
Journal::Sink.

Sinks are no longer constructed with a default threshold of
kWarning; their threshold must be passed in on construction.
This commit is contained in:
Scott Schurr
2016-02-17 18:34:42 -08:00
committed by seelabs
parent f846b1a88f
commit 6366f62f11
17 changed files with 149 additions and 291 deletions

View File

@@ -57,7 +57,7 @@ private:
public:
Sink (std::string const& partition,
beast::Journal::Severity severity, Logs& logs);
beast::Journal::Severity thresh, Logs& logs);
Sink (Sink const&) = delete;
Sink& operator= (Sink const&) = delete;
@@ -149,7 +149,7 @@ private:
std::map <std::string,
std::unique_ptr<beast::Journal::Sink>,
beast::ci_less> sinks_;
beast::Journal::Severity level_;
beast::Journal::Severity thresh_;
File file_;
bool silent_ = false;
@@ -174,10 +174,10 @@ public:
journal (std::string const& name);
beast::Journal::Severity
severity() const;
threshold() const;
void
severity (beast::Journal::Severity level);
threshold (beast::Journal::Severity thresh);
std::vector<std::pair<std::string, std::string>>
partition_severities() const;
@@ -276,19 +276,19 @@ class LogSquelcher
{
public:
LogSquelcher()
: severity_(deprecatedLogs().severity())
: thresh_(deprecatedLogs().threshold())
{
deprecatedLogs().severity(
deprecatedLogs().threshold(
beast::Journal::Severity::kNone);
}
~LogSquelcher()
{
deprecatedLogs().severity(severity_);
deprecatedLogs().threshold(thresh_);
}
private:
beast::Journal::Severity const severity_;
beast::Journal::Severity const thresh_;
};
} // ripple

View File

@@ -28,16 +28,19 @@
namespace ripple {
Logs::Sink::Sink (std::string const& partition,
beast::Journal::Severity severity, Logs& logs)
: logs_(logs)
beast::Journal::Severity thresh, Logs& logs)
: beast::Journal::Sink (thresh, false)
, logs_(logs)
, partition_(partition)
{
beast::Journal::Sink::severity (severity);
}
void
Logs::Sink::write (beast::Journal::Severity level, std::string const& text)
{
if (level < threshold())
return;
logs_.write (level, partition_, text, console());
}
@@ -109,7 +112,7 @@ void Logs::File::writeln (char const* text)
//------------------------------------------------------------------------------
Logs::Logs()
: level_ (beast::Journal::kWarning) // default severity
: thresh_ (beast::Journal::kWarning) // default severity
{
}
@@ -124,7 +127,7 @@ Logs::get (std::string const& name)
{
std::lock_guard <std::mutex> lock (mutex_);
auto const result =
sinks_.emplace(name, makeSink(name, level_));
sinks_.emplace(name, makeSink(name, thresh_));
return *result.first->second;
}
@@ -141,18 +144,18 @@ Logs::journal (std::string const& name)
}
beast::Journal::Severity
Logs::severity() const
Logs::threshold() const
{
return level_;
return thresh_;
}
void
Logs::severity (beast::Journal::Severity level)
Logs::threshold (beast::Journal::Severity thresh)
{
std::lock_guard <std::mutex> lock (mutex_);
level_ = level;
thresh_ = thresh;
for (auto& sink : sinks_)
sink.second->severity (level);
sink.second->threshold (thresh);
}
std::vector<std::pair<std::string, std::string>>
@@ -163,7 +166,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->threshold()))));
return list;
}
@@ -194,10 +197,10 @@ Logs::rotate()
std::unique_ptr<beast::Journal::Sink>
Logs::makeSink(std::string const& name,
beast::Journal::Severity startingLevel)
beast::Journal::Severity threshold)
{
return std::make_unique<Sink>(
name, startingLevel, *this);
name, threshold, *this);
}
LogSeverity