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(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(fmt_str, std::move(store));
227 LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(Private, m_priv)
234 void append(MessageBufferAppender&& f);
236#if LOG4CXX_WCHAR_T_API
242 void append(WideMessageBufferAppender&& f);
245 using MessageBufferAppender = std::function<void(LogCharMessageBuffer&)>;
250 void append(MessageBufferAppender&& f);
253#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
254 void initializeForFmt(
const StringViewType& format_string, FmtArgStore&& args);
256#if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
257 void initializeForFmt(
const WideStringViewType& format_string, WideFmtArgStore&& args);
270#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 10000
290#define LOG4CXX_DEBUG_ASYNC(logger, message) do { \
291 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
292 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
293 logger->addDebugEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
295#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
315#define LOG4CXX_DEBUG_FMT_ASYNC(logger, fmt, ...) do { \
316 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
317 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
318 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
319 logger->addDebugEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
322#define LOG4CXX_DEBUG_ASYNC(logger, message)
323#define LOG4CXX_DEBUG_FMT_ASYNC(logger, message)
326#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 5000
338#define LOG4CXX_TRACE_ASYNC(logger, message) do { \
339 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
340 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
341 logger->addTraceEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
343#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
356#define LOG4CXX_TRACE_FMT_ASYNC(logger, fmt, ...) do { \
357 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
358 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
359 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
360 logger->addTraceEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
364#define LOG4CXX_TRACE_ASYNC(logger, message)
365#define LOG4CXX_TRACE_FMT_ASYNC(logger, message)
368#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 20000
385#define LOG4CXX_INFO_ASYNC(logger, message) do { \
386 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
387 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
388 logger->addInfoEvent(std::move(buf << message), LOG4CXX_LOCATION);\
391#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
408#define LOG4CXX_INFO_FMT_ASYNC(logger, fmt, ...) do { \
409 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
410 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
411 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
412 logger->addInfoEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
416#define LOG4CXX_INFO_ASYNC(logger, message)
417#define LOG4CXX_INFO_FMT_ASYNC(logger, message)
420#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 30000
435#define LOG4CXX_WARN_ASYNC(logger, message) do { \
436 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
437 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
438 logger->addWarnEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
440#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
456#define LOG4CXX_WARN_FMT_ASYNC(logger, fmt, ...) do { \
457 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
458 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
459 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
460 logger->addWarnEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
464#define LOG4CXX_WARN_ASYNC(logger, message)
465#define LOG4CXX_WARN_FMT_ASYNC(logger, message)
468#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 40000
483#define LOG4CXX_ERROR_ASYNC(logger, message) do { \
484 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
485 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
486 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
488#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
504#define LOG4CXX_ERROR_FMT_ASYNC(logger, fmt, ...) do { \
505 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
506 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
507 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
508 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
518#define LOG4CXX_ASSERT_ASYNC(logger, condition, message) do { \
519 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
520 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
522 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
524#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
535#define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, fmt, ...) do { \
536 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
538 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
539 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
540 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
544#define LOG4CXX_ERROR_ASYNC(logger, message)
545#define LOG4CXX_ERROR_FMT_ASYNC(logger, message)
546#define LOG4CXX_ASSERT_ASYNC(logger, condition, message)
547#define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, message)
550#if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 50000
562#define LOG4CXX_FATAL_ASYNC(logger, message) do { \
563 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
564 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
565 logger->addFatalEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
567#if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
580#define LOG4CXX_FATAL_FMT_ASYNC(logger, fmt, ...) do { \
581 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
582 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
583 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
584 logger->addFatalEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
588#define LOG4CXX_FATAL_ASYNC(logger, message)
589#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:221
std::basic_ostream< char > & operator<<(CharMessageBuffer &os, const V &val)
Definition log4cxx/helpers/messagebuffer.h:208