diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj
index a7ef873432..110602f2a6 100644
--- a/Builds/VisualStudio2012/beast.vcxproj
+++ b/Builds/VisualStudio2012/beast.vcxproj
@@ -154,6 +154,7 @@
+
@@ -579,6 +580,12 @@
true
true
+
+ true
+ true
+ true
+ true
+
true
true
diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters
index 3a99643827..8a25b7bf9c 100644
--- a/Builds/VisualStudio2012/beast.vcxproj.filters
+++ b/Builds/VisualStudio2012/beast.vcxproj.filters
@@ -1025,6 +1025,9 @@
beast_core\memory
+
+ beast_core\diagnostic
+
@@ -1546,6 +1549,9 @@
beast_core\diagnostic
+
+ beast_core\diagnostic
+
diff --git a/modules/beast_core/beast_core.cpp b/modules/beast_core/beast_core.cpp
index b238839f30..0278a0890a 100644
--- a/modules/beast_core/beast_core.cpp
+++ b/modules/beast_core/beast_core.cpp
@@ -156,6 +156,7 @@ namespace beast
#include "diagnostic/beast_SemanticVersion.cpp"
#include "diagnostic/beast_UnitTest.cpp"
#include "diagnostic/beast_UnitTestUtilities.cpp"
+#include "diagnostic/Journal.cpp"
#include "files/beast_DirectoryIterator.cpp"
#include "files/beast_File.cpp"
diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h
index 2b19116d64..9c806c00b5 100644
--- a/modules/beast_core/beast_core.h
+++ b/modules/beast_core/beast_core.h
@@ -281,6 +281,7 @@ extern BEAST_API void BEAST_CALLTYPE logAssertion (char const* file, int line) n
#include "text/beast_String.h"
#include "time/AtExitHook.h"
#include "diagnostic/beast_LeakChecked.h"
+#include "diagnostic/Journal.h"
#include "time/beast_RelativeTime.h"
#include "time/beast_Time.h"
#include "memory/beast_HeapBlock.h"
diff --git a/modules/beast_core/diagnostic/Journal.cpp b/modules/beast_core/diagnostic/Journal.cpp
new file mode 100644
index 0000000000..3271e7cd2e
--- /dev/null
+++ b/modules/beast_core/diagnostic/Journal.cpp
@@ -0,0 +1,38 @@
+//------------------------------------------------------------------------------
+/*
+ This file is part of Beast: https://github.com/vinniefalco/Beast
+ Copyright 2013, Vinnie Falco
+
+ 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.
+*/
+//==============================================================================
+
+Journal::Sink* Journal::getNullSink ()
+{
+ // A Sink that does nothing.
+ class NullSink : public Sink
+ {
+ public:
+ void write (Severity, std::string const&)
+ {
+ }
+
+ bool active (Severity)
+ {
+ return false;
+ }
+ };
+
+ return SharedSingleton ::get (
+ SingletonLifetime::neverDestroyed);
+}
diff --git a/modules/beast_core/diagnostic/Journal.h b/modules/beast_core/diagnostic/Journal.h
new file mode 100644
index 0000000000..7eb89278f4
--- /dev/null
+++ b/modules/beast_core/diagnostic/Journal.h
@@ -0,0 +1,188 @@
+//------------------------------------------------------------------------------
+/*
+ This file is part of Beast: https://github.com/vinniefalco/Beast
+ Copyright 2013, Vinnie Falco
+
+ 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.
+*/
+//==============================================================================
+
+#ifndef BEAST_CORE_JOURNAL_H_INCLUDED
+#define BEAST_CORE_JOURNAL_H_INCLUDED
+
+/** A generic endpoint for log messages. */
+class Journal
+{
+public:
+ /** Severity level of the message. */
+ enum Severity
+ {
+ kTrace,
+ kDebug,
+ kInfo,
+ kWarning,
+ kError,
+ kFatal
+ };
+
+ //--------------------------------------------------------------------------
+
+ /** Abstraction for the underlying message destination. */
+ class Sink
+ {
+ public:
+ virtual ~Sink () { }
+
+ /** Write text to the sink at the specified severity. */
+ virtual void write (Severity severity, std::string const& text) = 0;
+
+ /** Returns `true` if text at the passed severity produces output. */
+ virtual bool active (Severity)
+ {
+ return true;
+ }
+ };
+
+ /** Returns a Sink which does nothing. */
+ static Sink* getNullSink ();
+
+ //--------------------------------------------------------------------------
+
+ /** Scoped container for building journal messages. */
+ class Stream
+ {
+ public:
+ explicit Stream (Sink* sink, Severity severity)
+ : m_sink (sink)
+ , m_severity (severity)
+ {
+ }
+
+ Stream (Stream const& other)
+ : m_sink (other.m_sink)
+ , m_severity (other.m_severity)
+ {
+ }
+
+ Stream& operator= (Stream const& other)
+ {
+ m_sink = other.m_sink;
+ m_severity = other.m_severity;
+ return *this;
+ }
+
+ ~Stream ()
+ {
+ if (m_sink ->active (m_severity))
+ m_sink->write (m_severity, m_stream.str ());
+ }
+
+ template
+ std::ostream& operator<< (T const& t) const
+ {
+ return m_stream << t;
+ }
+
+ std::ostringstream& stream () const
+ {
+ return m_stream;
+ }
+
+ private:
+ Sink* m_sink;
+ Severity m_severity;
+ std::ostringstream mutable m_stream;
+ };
+
+ //--------------------------------------------------------------------------
+
+ Journal (Sink* sink = getNullSink ())
+ : m_sink (sink)
+ {
+ }
+
+ bool reportActive (Severity severity) const
+ {
+ return m_sink->active (severity);
+ }
+
+ bool traceActive () const
+ {
+ return reportActive (kTrace);
+ }
+
+ bool debugActive () const
+ {
+ return reportActive (kDebug);
+ }
+
+ bool infoActive () const
+ {
+ return reportActive (kInfo);
+ }
+
+ bool warningActive () const
+ {
+ return reportActive (kWarning);
+ }
+
+ bool errorActive () const
+ {
+ return reportActive (kError);
+ }
+
+ bool fatalActive () const
+ {
+ return reportActive (kFatal);
+ }
+
+ Stream report (Severity severity) const
+ {
+ return Stream (m_sink, severity);
+ }
+
+ Stream trace () const
+ {
+ return report (kTrace);
+ }
+
+ Stream debug () const
+ {
+ return report (kDebug);
+ }
+
+ Stream info () const
+ {
+ return report (kInfo);
+ }
+
+ Stream warning () const
+ {
+ return report (kWarning);
+ }
+
+ Stream error () const
+ {
+ return report (kError);
+ }
+
+ Stream fatal () const
+ {
+ return Stream (m_sink, kFatal);
+ }
+
+private:
+ Sink* m_sink;
+};
+
+#endif
diff --git a/modules/beast_core/memory/SharedSingleton.h b/modules/beast_core/memory/SharedSingleton.h
index 14b2a8dffb..895f266d9f 100644
--- a/modules/beast_core/memory/SharedSingleton.h
+++ b/modules/beast_core/memory/SharedSingleton.h
@@ -75,7 +75,7 @@ class SharedSingleton
public:
typedef SharedPtr > Ptr;
- static Ptr getInstance (SingletonLifetime::Lifetime lifetime
+ static Ptr get (SingletonLifetime::Lifetime lifetime
= SingletonLifetime::persistAfterCreation)
{
StaticData& staticData (getStaticData ());
@@ -95,12 +95,20 @@ public:
return instance;
}
+ // DEPRECATED LEGACY FUNCTION NAME
+ static Ptr getInstance (SingletonLifetime::Lifetime lifetime
+ = SingletonLifetime::persistAfterCreation)
+ {
+ return get (lifetime);
+ }
+
private:
explicit SharedSingleton (SingletonLifetime::Lifetime lifetime)
: m_lifetime (lifetime)
, m_exitHook (this)
{
- if (m_lifetime == SingletonLifetime::persistAfterCreation)
+ if (m_lifetime == SingletonLifetime::persistAfterCreation ||
+ m_lifetime == SingletonLifetime::neverDestroyed)
this->incReferenceCount ();
}