mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
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.
103 lines
2.6 KiB
C++
103 lines
2.6 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of Beast: https://github.com/vinniefalco/Beast
|
|
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <beast/utility/Journal.h>
|
|
#include <beast/unit_test/suite.h>
|
|
|
|
namespace beast {
|
|
|
|
class Journal_test : public unit_test::suite
|
|
{
|
|
public:
|
|
class TestSink : public Journal::Sink
|
|
{
|
|
private:
|
|
int m_count;
|
|
|
|
public:
|
|
TestSink()
|
|
: Sink (Journal::kWarning, false)
|
|
, m_count(0)
|
|
{
|
|
}
|
|
|
|
int
|
|
count() const
|
|
{
|
|
return m_count;
|
|
}
|
|
|
|
void
|
|
reset()
|
|
{
|
|
m_count = 0;
|
|
}
|
|
|
|
void
|
|
write (Journal::Severity level, std::string const&) override
|
|
{
|
|
if (level >= threshold())
|
|
++m_count;
|
|
}
|
|
};
|
|
|
|
void run ()
|
|
{
|
|
TestSink sink;
|
|
|
|
sink.threshold(Journal::kInfo);
|
|
|
|
Journal j(sink);
|
|
|
|
j.trace << " ";
|
|
expect(sink.count() == 0);
|
|
j.debug << " ";
|
|
expect(sink.count() == 0);
|
|
j.info << " ";
|
|
expect(sink.count() == 1);
|
|
j.warning << " ";
|
|
expect(sink.count() == 2);
|
|
j.error << " ";
|
|
expect(sink.count() == 3);
|
|
j.fatal << " ";
|
|
expect(sink.count() == 4);
|
|
|
|
sink.reset();
|
|
|
|
sink.threshold(Journal::kDebug);
|
|
|
|
j.trace << " ";
|
|
expect(sink.count() == 0);
|
|
j.debug << " ";
|
|
expect(sink.count() == 1);
|
|
j.info << " ";
|
|
expect(sink.count() == 2);
|
|
j.warning << " ";
|
|
expect(sink.count() == 3);
|
|
j.error << " ";
|
|
expect(sink.count() == 4);
|
|
j.fatal << " ";
|
|
expect(sink.count() == 5);
|
|
}
|
|
};
|
|
|
|
BEAST_DEFINE_TESTSUITE(Journal,utility,beast);
|
|
|
|
} // beast
|