Improve Journal logging framework:

* Allow partition log levels to be adjusted
* Cleanups
This commit is contained in:
Howard Hinnant
2014-06-12 20:49:37 -07:00
committed by Nik Bougalis
parent b11e857148
commit 7b4c705a3f
5 changed files with 108 additions and 5 deletions

View File

@@ -20,12 +20,13 @@
#ifndef BEAST_LEXICALCAST_H_INCLUDED #ifndef BEAST_LEXICALCAST_H_INCLUDED
#define BEAST_LEXICALCAST_H_INCLUDED #define BEAST_LEXICALCAST_H_INCLUDED
#include <string> #include <beast/Config.h>
#include <beast/cxx14/type_traits.h> // <type_traits> #include <beast/cxx14/type_traits.h> // <type_traits>
#include <cerrno> #include <cerrno>
#include <cstdlib> #include <cstdlib>
#include <limits> #include <limits>
#include <string>
#include <utility> #include <utility>
namespace beast { namespace beast {

View File

@@ -20,8 +20,9 @@
#ifndef BEAST_DEADLINETIMER_H_INCLUDED #ifndef BEAST_DEADLINETIMER_H_INCLUDED
#define BEAST_DEADLINETIMER_H_INCLUDED #define BEAST_DEADLINETIMER_H_INCLUDED
namespace beast #include <beast/module/core/memory/SharedSingleton.h>
{
namespace beast {
/** Provides periodic or one time notifications at a specified time interval. /** Provides periodic or one time notifications at a specified time interval.
*/ */

View File

@@ -31,5 +31,6 @@
#include <beast/utility/tests/bassert.test.cpp> #include <beast/utility/tests/bassert.test.cpp>
#include <beast/utility/tests/empty_base_optimization.test.cpp> #include <beast/utility/tests/empty_base_optimization.test.cpp>
#include <beast/utility/tests/Zero.test.cpp> #include <beast/utility/tests/Journal.test.cpp>
#include <beast/utility/tests/tagged_integer.test.cpp> #include <beast/utility/tests/tagged_integer.test.cpp>
#include <beast/utility/tests/Zero.test.cpp>

View File

@@ -67,7 +67,7 @@ Journal::Sink& Journal::getNullSink ()
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Journal::Sink::Sink () Journal::Sink::Sink ()
: m_level (kAll) : m_level (kWarning)
, m_console (false) , m_console (false)
{ {
} }

View File

@@ -0,0 +1,100 @@
//------------------------------------------------------------------------------
/*
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()
: m_count(0)
{
}
int
count() const
{
return m_count;
}
void
reset()
{
m_count = 0;
}
void
write (Journal::Severity, std::string const&)
{
++m_count;
}
};
void run ()
{
TestSink sink;
sink.severity(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.severity(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_MANUAL(Journal,utility,beast);
} // beast