Merge remote-tracking branch 'upstream/dev' into sync-2.4.0

This commit is contained in:
tequ
2025-10-14 17:05:47 +09:00
46 changed files with 2049 additions and 1580 deletions

View File

@@ -155,6 +155,10 @@ public:
ScopedStream(Sink& sink, Severity level);
#ifdef BEAST_ENHANCED_LOGGING
ScopedStream(Sink& sink, Severity level, const char* file, int line);
#endif
template <typename T>
ScopedStream(Stream const& stream, T const& t);
@@ -182,6 +186,10 @@ public:
Sink& m_sink;
Severity const m_level;
std::ostringstream mutable m_ostream;
#ifdef BEAST_ENHANCED_LOGGING
const char* file_ = nullptr;
int line_ = 0;
#endif
};
#ifndef __INTELLISENSE__
@@ -200,6 +208,33 @@ public:
//--------------------------------------------------------------------------
public:
/** Provide a light-weight way to check active() before string formatting */
#ifdef BEAST_ENHANCED_LOGGING
/** Stream with location information that prepends file:line to the first
* message */
class StreamWithLocation
{
public:
StreamWithLocation(Stream const& stream, const char* file, int line)
: file_(file), line_(line), stream_(stream)
{
}
/** Override to inject file:line before the first output */
template <typename T>
ScopedStream
operator<<(T const& t) const;
ScopedStream
operator<<(std::ostream& manip(std::ostream&)) const;
private:
const char* file_;
int line_;
const Stream& stream_;
};
#endif
class Stream
{
public:
@@ -267,6 +302,15 @@ public:
operator<<(T const& t) const;
/** @} */
#ifdef BEAST_ENHANCED_LOGGING
/** Create a StreamWithLocation that prepends file:line info */
StreamWithLocation
withLocation(const char* file, int line) const
{
return StreamWithLocation(*this, file, line);
}
#endif
private:
Sink& m_sink;
Severity m_level;
@@ -366,6 +410,8 @@ static_assert(std::is_nothrow_destructible<Journal>::value == true, "");
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
template <typename T>
Journal::ScopedStream::ScopedStream(Journal::Stream const& stream, T const& t)
: ScopedStream(stream.sink(), stream.level())
@@ -390,6 +436,21 @@ Journal::Stream::operator<<(T const& t) const
return ScopedStream(*this, t);
}
#ifdef BEAST_ENHANCED_LOGGING
//------------------------------------------------------------------------------
template <typename T>
Journal::ScopedStream
Journal::StreamWithLocation::operator<<(T const& t) const
{
// Create a ScopedStream with location info
ScopedStream scoped(stream_.sink(), stream_.level(), file_, line_);
scoped.ostream() << t;
return scoped;
}
#endif
namespace detail {
template <class CharT, class Traits = std::char_traits<CharT>>