Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Journal to be copied/moved #2292

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions src/ripple/beast/utility/Journal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class Journal
// Severity level / threshold of a Journal message.
using Severity = severities::Severity;

Sink& m_sink;
// Invariant: m_sink always points to a valid Sink
Sink* m_sink;

public:
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -259,30 +260,19 @@ static_assert(std::is_nothrow_destructible<Stream>::value == true, "");

/** Create a journal that writes to the specified sink. */
explicit Journal (Sink& sink)
: m_sink (sink)
: m_sink (&sink)
{ }

/** Create a journal from another journal. */
Journal (Journal const& other)
: Journal (other.m_sink)
{ }

// Disallowed.
Journal& operator= (Journal const& other) = delete;

/** Destroy the journal. */
~Journal () = default;

/** Returns the Sink associated with this Journal. */
Sink& sink() const
{
return m_sink;
return *m_sink;
}

/** Returns a stream for this sink, with the specified severity level. */
Stream stream (Severity level) const
{
return Stream (m_sink, level);
return Stream (*m_sink, level);
}

/** Returns `true` if any message would be logged at this severity level.
Expand All @@ -291,39 +281,39 @@ static_assert(std::is_nothrow_destructible<Stream>::value == true, "");
*/
bool active (Severity level) const
{
return m_sink.active (level);
return m_sink->active (level);
}

/** Severity stream access functions. */
/** @{ */
Stream trace() const
{
return { m_sink, severities::kTrace };
return { *m_sink, severities::kTrace };
}

Stream debug() const
{
return { m_sink, severities::kDebug };
return { *m_sink, severities::kDebug };
}

Stream info() const
{
return { m_sink, severities::kInfo };
return { *m_sink, severities::kInfo };
}

Stream warn() const
{
return { m_sink, severities::kWarning };
return { *m_sink, severities::kWarning };
}

Stream error() const
{
return { m_sink, severities::kError };
return { *m_sink, severities::kError };
}

Stream fatal() const
{
return { m_sink, severities::kFatal };
return { *m_sink, severities::kFatal };
}
/** @} */
};
Expand All @@ -332,8 +322,8 @@ static_assert(std::is_nothrow_destructible<Stream>::value == true, "");
static_assert(std::is_default_constructible<Journal>::value == true, "");
static_assert(std::is_copy_constructible<Journal>::value == true, "");
static_assert(std::is_move_constructible<Journal>::value == true, "");
static_assert(std::is_copy_assignable<Journal>::value == false, "");
static_assert(std::is_move_assignable<Journal>::value == false, "");
static_assert(std::is_copy_assignable<Journal>::value == true, "");
static_assert(std::is_move_assignable<Journal>::value == true, "");
static_assert(std::is_nothrow_destructible<Journal>::value == true, "");
#endif

Expand Down