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
30#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
68#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
69#if LOG4CXX_LOGCHAR_IS_UTF8
70 if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
77#if LOG4CXX_WCHAR_T_API
78 else if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
87 static_assert(
false,
"operator<<(std::ostream&) overload must be provided");
89 if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
96 else if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
104 static_assert(
false,
"operator<<(std::wostream&) overload must be provided");
107 append([value](LogCharMessageBuffer& msgBuf)
115#ifdef __cpp_init_captures
120 template <
typename T>
123#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
124#if LOG4CXX_LOGCHAR_IS_UTF8
125 if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
127 append([value = std::move(rvalue)](CharMessageBuffer& msgBuf)
132#if LOG4CXX_WCHAR_T_API
133 else if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
135 append([value = std::move(rvalue)](WideMessageBuffer& msgBuf)
142 static_assert(
false,
"operator<<(std::ostream&) overload must be provided");
144 if constexpr (
requires(std::wostream& buf, T v) { buf << v; })
146 append([value = std::move(rvalue)](WideMessageBuffer& msgBuf)
151 else if constexpr (
requires(std::ostream& buf, T v) { buf << v; })
153 append([value = std::move(rvalue)](CharMessageBuffer& msgBuf)
159 static_assert(
false,
"operator<<(std::wostream&) overload must be provided");
162 append([value = std::move(rvalue)](LogCharMessageBuffer& msgBuf)
189#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
191 using FmtArgStore = fmt::dynamic_format_arg_store<fmt::format_context>;
192 template <
typename... Args>
193 void setMessage(fmt::format_string<Args...> fmt_str, Args&&... args)
196 ( store.push_back(std::forward<Args>(args)), ...);
197 initializeForFmt(std::move(fmt_str), std::move(store));
200#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
203 template <
typename... Args>
204 void setMessage(fmt::wformat_string<Args...> fmt_str, Args&&... args)
207 ( store.push_back(std::forward<Args>(args)), ...);
208 initializeForFmt(std::move(fmt_str), std::move(store));
217 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(Private, m_priv)
218#if defined(__cpp_concepts) && 202002 <= __cpp_concepts
224 void append(
const MessageBufferAppender& f);
226#if LOG4CXX_WCHAR_T_API
232 void append(
const WideMessageBufferAppender& f);
235 using MessageBufferAppender = std::function<void(LogCharMessageBuffer&)>;
240 void append(
const MessageBufferAppender& f);
243#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
244 void initializeForFmt(StringViewType&& format_string, FmtArgStore&& args);
246#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
247 void initializeForFmt(WideStringViewType&& format_string, WideFmtArgStore&& args);
259#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 10000
279#define LOG4CXX_DEBUG_ASYNC(logger, message) do { \
280 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
281 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
282 logger->addDebugEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
284#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
304#define LOG4CXX_DEBUG_FMT_ASYNC(logger, fmt, ...) do { \
305 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
306 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
307 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
308 logger->addDebugEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
311#define LOG4CXX_DEBUG_ASYNC(logger, message)
312#define LOG4CXX_DEBUG_FMT_ASYNC(logger, message)
315#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 5000
327#define LOG4CXX_TRACE_ASYNC(logger, message) do { \
328 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
329 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
330 logger->addTraceEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
332#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
345#define LOG4CXX_TRACE_FMT_ASYNC(logger, fmt, ...) do { \
346 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
347 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
348 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
349 logger->addTraceEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
353#define LOG4CXX_TRACE_ASYNC(logger, message)
354#define LOG4CXX_TRACE_FMT_ASYNC(logger, message)
357#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 20000
374#define LOG4CXX_INFO_ASYNC(logger, message) do { \
375 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
376 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
377 logger->addInfoEvent(std::move(buf << message), LOG4CXX_LOCATION);\
382#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
399#define LOG4CXX_INFO_FMT_ASYNC(logger, fmt, ...) do { \
400 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
401 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
402 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
403 logger->addInfoEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
407#define LOG4CXX_INFO_ASYNC(logger, message)
408#define LOG4CXX_INFO_FMT_ASYNC(logger, message)
411#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 30000
426#define LOG4CXX_WARN_ASYNC(logger, message) do { \
427 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
428 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
429 logger->addWarnEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
431#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
447#define LOG4CXX_WARN_FMT_ASYNC(logger, fmt, ...) do { \
448 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
449 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
450 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
451 logger->addWarnEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
455#define LOG4CXX_WARN_ASYNC(logger, message)
456#define LOG4CXX_WARN_FMT_ASYNC(logger, message)
459#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 40000
474#define LOG4CXX_ERROR_ASYNC(logger, message) do { \
475 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
476 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
477 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
479#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
495#define LOG4CXX_ERROR_FMT_ASYNC(logger, fmt, ...) do { \
496 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
497 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
498 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
499 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
509#define LOG4CXX_ASSERT_ASYNC(logger, condition, message) do { \
510 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
511 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
513 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
515#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
526#define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, fmt, ...) do { \
527 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
529 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
530 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
531 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
535#define LOG4CXX_ERROR_ASYNC(logger, message)
536#define LOG4CXX_ERROR_FMT_ASYNC(logger, message)
537#define LOG4CXX_ASSERT_ASYNC(logger, condition, message)
538#define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, message)
541#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 50000
553#define LOG4CXX_FATAL_ASYNC(logger, message) do { \
554 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
555 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
556 logger->addFatalEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
558#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
571#define LOG4CXX_FATAL_FMT_ASYNC(logger, fmt, ...) do { \
572 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
573 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
574 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
575 logger->addFatalEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
579#define LOG4CXX_FATAL_ASYNC(logger, message)
580#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:46
bool empty() const
Has no item been added to this?
fmt::dynamic_format_arg_store< fmt::format_context > FmtArgStore
Definition asyncbuffer.h:191
~AsyncBuffer()
Release resources.
fmt::basic_string_view< wchar_t > WideStringViewType
Definition asyncbuffer.h:201
fmt::dynamic_format_arg_store< fmt::wformat_context > WideFmtArgStore
Definition asyncbuffer.h:202
AsyncBuffer(AsyncBuffer &&other)
A new buffer with the content of other.
void setMessage(fmt::format_string< Args... > fmt_str, Args &&... args)
Definition asyncbuffer.h:193
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:204
AsyncBuffer & operator<<(const T &value)
Append a function to this buffer that will convert value to text.
Definition asyncbuffer.h:66
void clear()
Remove all message appenders.
fmt::basic_string_view< char > StringViewType
Definition asyncbuffer.h:190
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