From f193302e15f246638129ee3b6cdabeda29ae570e Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 9 Nov 2014 17:05:06 -0800 Subject: [PATCH] Add WrappedSink --- Builds/VisualStudio2013/RippleD.vcxproj | 2 + .../VisualStudio2013/RippleD.vcxproj.filters | 3 + src/beast/beast/utility/WrappedSink.h | 89 +++++++++++++++++++ src/ripple/overlay/impl/PeerImp.h | 1 + 4 files changed, 95 insertions(+) create mode 100644 src/beast/beast/utility/WrappedSink.h diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 75b4e225c..50c76500c 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -998,6 +998,8 @@ True + + diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index d5af87b59..d30891af2 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -1686,6 +1686,9 @@ beast\utility + + beast\utility + beast\utility diff --git a/src/beast/beast/utility/WrappedSink.h b/src/beast/beast/utility/WrappedSink.h new file mode 100644 index 000000000..3bd8d273f --- /dev/null +++ b/src/beast/beast/utility/WrappedSink.h @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +/* + 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_UTILITY_WRAPPED_SINK_H_INCLUDED +#define BEAST_UTILITY_WRAPPED_SINK_H_INCLUDED + +#include + +namespace beast { + +/** Wraps a Journal::Sink to prefix its output with a string. */ +class WrappedSink : public beast::Journal::Sink +{ +private: + std::string prefix_; + beast::Journal::Sink& sink_; + +public: + explicit + WrappedSink (beast::Journal::Sink& sink) + : sink_ (sink) + { + } + + explicit + WrappedSink (beast::Journal const& journal) + : sink_ (journal.sink()) + { + } + + void prefix (std::string const& s) + { + prefix_ = s; + } + + bool + active (beast::Journal::Severity level) const override + { + return sink_.active (level); + } + + bool + console () const override + { + return sink_.console (); + } + + void console (bool output) override + { + sink_.console (output); + } + + beast::Journal::Severity + severity() const + { + return sink_.severity(); + } + + void severity (beast::Journal::Severity level) + { + sink_.severity (level); + } + + void write (beast::Journal::Severity level, std::string const& text) + { + using beast::Journal; + sink_.write (level, prefix_ + text); + } +}; + +} + +#endif diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h index 622d11b07..4400e463b 100644 --- a/src/ripple/overlay/impl/PeerImp.h +++ b/src/ripple/overlay/impl/PeerImp.h @@ -39,6 +39,7 @@ #include #include #include +#include #include namespace ripple {