Fix base log partition severity

This commit is contained in:
Vinnie Falco
2014-06-28 10:45:38 -07:00
committed by Nik Bougalis
parent fac82204b6
commit 1b48ccc868
2 changed files with 13 additions and 36 deletions

View File

@@ -24,40 +24,22 @@
namespace ripple { namespace ripple {
Logs::Sink::Sink (std::string const& partition, Logs& logs) Logs::Sink::Sink (std::string const& partition,
beast::Journal::Severity severity, Logs& logs)
: logs_(logs) : logs_(logs)
, partition_(partition) , partition_(partition)
{ {
beast::Journal::Sink::severity (severity);
} }
bool
Logs::Sink::active (beast::Journal::Severity level) const
{
return level >= logs_.severity() &&
level >= beast::Journal::Sink::severity();
}
beast::Journal::Severity
Logs::Sink::severity() const
{
return beast::Journal::Sink::severity();
}
void
Logs::Sink::severity (beast::Journal::Severity level)
{
std::lock_guard <std::mutex> lock (logs_.mutex_);
beast::Journal::Sink::severity(level);
}
//------------------------------------------------------------------------------
void void
Logs::Sink::write (beast::Journal::Severity level, std::string const& text) Logs::Sink::write (beast::Journal::Severity level, std::string const& text)
{ {
logs_.write (level, partition_, text, console()); logs_.write (level, partition_, text, console());
} }
//------------------------------------------------------------------------------
Logs::File::File() Logs::File::File()
: m_stream (nullptr) : m_stream (nullptr)
{ {
@@ -138,8 +120,9 @@ Logs::Sink&
Logs::get (std::string const& name) Logs::get (std::string const& name)
{ {
std::lock_guard <std::mutex> lock (mutex_); std::lock_guard <std::mutex> lock (mutex_);
auto const result (sinks_.emplace(std::piecewise_construct, auto const result (sinks_.emplace (std::piecewise_construct,
std::forward_as_tuple(name), std::forward_as_tuple(name, *this))); std::forward_as_tuple(name), std::forward_as_tuple (name,
level_, *this)));
return result.first->second; return result.first->second;
} }
@@ -164,8 +147,10 @@ Logs::severity() const
void void
Logs::severity (beast::Journal::Severity level) Logs::severity (beast::Journal::Severity level)
{ {
// VFALCO Do we need the lock? std::lock_guard <std::mutex> lock (mutex_);
level_ = level; level_ = level;
for (auto& sink : sinks_)
sink.second.severity (level);
} }
std::vector<std::pair<std::string, std::string>> std::vector<std::pair<std::string, std::string>>

View File

@@ -52,20 +52,12 @@ private:
std::string partition_; std::string partition_;
public: public:
Sink (std::string const& partition, Logs& logs); Sink (std::string const& partition,
beast::Journal::Severity severity, Logs& logs);
Sink (Sink const&) = delete; Sink (Sink const&) = delete;
Sink& operator= (Sink const&) = delete; Sink& operator= (Sink const&) = delete;
bool
active (beast::Journal::Severity level) const override;
beast::Journal::Severity
severity() const override;
void
severity (beast::Journal::Severity level) override;
void void
write (beast::Journal::Severity level, std::string const& text) override; write (beast::Journal::Severity level, std::string const& text) override;
}; };