18#ifndef LOG4CXX_ASYNC_BUFFER_H
19#define LOG4CXX_ASYNC_BUFFER_H
24#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
26#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
31#if defined(__cpp_concepts) && 202002 <= __cpp_concepts && defined(__GNUC__) && __GNUC__ <= 12
33#define LOG4CXX_CONCEPTS 0
34#elif defined(__cpp_concepts) && 202002 <= __cpp_concepts
35#define LOG4CXX_CONCEPTS 1
37#define LOG4CXX_CONCEPTS 0
79#if LOG4CXX_LOGCHAR_IS_UTF8
80 if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
87#if LOG4CXX_WCHAR_T_API
88 else if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
97 static_assert(
false,
"operator<<(std::ostream&) overload must be provided");
99 if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
106 else if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
114 static_assert(
false,
"operator<<(std::wostream&) overload must be provided");
117 append([value](LogCharMessageBuffer& msgBuf)
125#ifdef __cpp_init_captures
130 template <
typename T>
134#if LOG4CXX_LOGCHAR_IS_UTF8
135 if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
137 append([value = std::move(rvalue)](CharMessageBuffer& msgBuf)
142#if LOG4CXX_WCHAR_T_API
143 else if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
145 append([value = std::move(rvalue)](WideMessageBuffer& msgBuf)
152 static_assert(
false,
"operator<<(std::ostream&) overload must be provided");
154 if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
156 append([value = std::move(rvalue)](WideMessageBuffer& msgBuf)
161 else if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
163 append([value = std::move(rvalue)](CharMessageBuffer& msgBuf)
169 static_assert(
false,
"operator<<(std::wostream&) overload must be provided");
172 append([value = std::move(rvalue)](LogCharMessageBuffer& msgBuf)
199#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
201 using FmtArgStore = fmt::dynamic_format_arg_store<fmt::format_context>;
202 template <
typename... Args>
203 void setMessage(fmt::format_string<Args...> fmt_str, Args&&... args)
206 ( store.push_back(std::forward<Args>(args)), ...);
207 initializeForFmt(std::move(fmt_str), std::move(store));
210#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
213 template <
typename... Args>
214 void setMessage(fmt::wformat_string<Args...> fmt_str, Args&&... args)
217 ( store.push_back(std::forward<Args>(args)), ...);
218 initializeForFmt(std::move(fmt_str), std::move(store));
227 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(Private, m_priv)
234 void append(
const MessageBufferAppender& f);
236#if LOG4CXX_WCHAR_T_API
242 void append(
const WideMessageBufferAppender& f);
245 using MessageBufferAppender = std::function<void(LogCharMessageBuffer&)>;
250 void append(
const MessageBufferAppender& f);
253#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
254 void initializeForFmt(StringViewType&& format_string, FmtArgStore&& args);
256#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
257 void initializeForFmt(WideStringViewType&& format_string, WideFmtArgStore&& args);
269#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 10000
289#define LOG4CXX_DEBUG_ASYNC(logger, message) do { \
290 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
291 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
292 logger->addDebugEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
294#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
314#define LOG4CXX_DEBUG_FMT_ASYNC(logger, fmt, ...) do { \
315 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
316 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
317 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
318 logger->addDebugEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
321#define LOG4CXX_DEBUG_ASYNC(logger, message)
322#define LOG4CXX_DEBUG_FMT_ASYNC(logger, message)
325#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 5000
337#define LOG4CXX_TRACE_ASYNC(logger, message) do { \
338 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
339 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
340 logger->addTraceEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
342#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
355#define LOG4CXX_TRACE_FMT_ASYNC(logger, fmt, ...) do { \
356 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
357 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
358 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
359 logger->addTraceEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
363#define LOG4CXX_TRACE_ASYNC(logger, message)
364#define LOG4CXX_TRACE_FMT_ASYNC(logger, message)
367#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 20000
384#define LOG4CXX_INFO_ASYNC(logger, message) do { \
385 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
386 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
387 logger->addInfoEvent(std::move(buf << message), LOG4CXX_LOCATION);\
392#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
409#define LOG4CXX_INFO_FMT_ASYNC(logger, fmt, ...) do { \
410 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
411 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
412 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
413 logger->addInfoEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
417#define LOG4CXX_INFO_ASYNC(logger, message)
418#define LOG4CXX_INFO_FMT_ASYNC(logger, message)
421#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 30000
436#define LOG4CXX_WARN_ASYNC(logger, message) do { \
437 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
438 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
439 logger->addWarnEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
441#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
457#define LOG4CXX_WARN_FMT_ASYNC(logger, fmt, ...) do { \
458 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
459 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
460 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
461 logger->addWarnEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
465#define LOG4CXX_WARN_ASYNC(logger, message)
466#define LOG4CXX_WARN_FMT_ASYNC(logger, message)
469#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 40000
484#define LOG4CXX_ERROR_ASYNC(logger, message) do { \
485 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
486 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
487 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
489#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
505#define LOG4CXX_ERROR_FMT_ASYNC(logger, fmt, ...) do { \
506 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
507 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
508 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
509 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
519#define LOG4CXX_ASSERT_ASYNC(logger, condition, message) do { \
520 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
521 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
523 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
525#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
536#define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, fmt, ...) do { \
537 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
539 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
540 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
541 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
545#define LOG4CXX_ERROR_ASYNC(logger, message)
546#define LOG4CXX_ERROR_FMT_ASYNC(logger, message)
547#define LOG4CXX_ASSERT_ASYNC(logger, condition, message)
548#define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, message)
551#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 50000
563#define LOG4CXX_FATAL_ASYNC(logger, message) do { \
564 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
565 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
566 logger->addFatalEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
568#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
581#define LOG4CXX_FATAL_FMT_ASYNC(logger, fmt, ...) do { \
582 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
583 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
584 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
585 logger->addFatalEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
589#define LOG4CXX_FATAL_ASYNC(logger, message)
590#define LOG4CXX_FATAL_FMT_ASYNC(logger, message)
This class is used by the LOG4CXX_INFO_ASYNC and similar macros to support insertion operators.
Definition asyncbuffer.h:56
bool empty() const
Has no item been added to this?
fmt::dynamic_format_arg_store< fmt::format_context > FmtArgStore
Definition asyncbuffer.h:201
~AsyncBuffer()
Release resources.
fmt::basic_string_view< wchar_t > WideStringViewType
Definition asyncbuffer.h:211
fmt::dynamic_format_arg_store< fmt::wformat_context > WideFmtArgStore
Definition asyncbuffer.h:212
AsyncBuffer(AsyncBuffer &&other)
A new buffer with the content of other.
void setMessage(fmt::format_string< Args... > fmt_str, Args &&... args)
Definition asyncbuffer.h:203
void renderMessage(LogCharMessageBuffer &msg) const
Add text version of buffered values to msg.
AsyncBuffer()
An empty buffer.
void setMessage(fmt::wformat_string< Args... > fmt_str, Args &&... args)
Definition asyncbuffer.h:214
AsyncBuffer & operator<<(const T &value)
Append a function to this buffer that will convert value to text.
Definition asyncbuffer.h:76
void clear()
Remove all message appenders.
fmt::basic_string_view< char > StringViewType
Definition asyncbuffer.h:200
This class is used by the LOG4CXX_INFO and similar macros to support insertion operators in the messa...
Definition log4cxx/helpers/messagebuffer.h:40
This class is designed to support insertion operations in the message argument to the LOG4CXX_INFO an...
Definition log4cxx/helpers/messagebuffer.h:405
log4cxx::helpers::UniCharMessageBuffer & operator<<(log4cxx::helpers::UniCharMessageBuffer &mb, const QString &msg)
Definition log4cxx-qt/messagebuffer.h:24