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
27 #include <fmt/xchar.h>
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);
261 #if LOG4CXX_ABI_VERSION <= 15
262 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
263 void initializeForFmt(StringViewType&& format_string, FmtArgStore&& args);
265 #if LOG4CXX_WCHAR_T_API || LOG4CXX_LOGCHAR_IS_WCHAR
266 void initializeForFmt(WideStringViewType&& format_string, WideFmtArgStore&& args);
279 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 10000
299 #define LOG4CXX_DEBUG_ASYNC(logger, message) do { \
300 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
301 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
302 logger->addDebugEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
304 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
324 #define LOG4CXX_DEBUG_FMT_ASYNC(logger, fmt, ...) do { \
325 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isDebugEnabledFor(logger))) {\
326 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
327 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
328 logger->addDebugEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
331 #define LOG4CXX_DEBUG_ASYNC(logger, message)
332 #define LOG4CXX_DEBUG_FMT_ASYNC(logger, message)
335 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 5000
347 #define LOG4CXX_TRACE_ASYNC(logger, message) do { \
348 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
349 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
350 logger->addTraceEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
352 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
365 #define LOG4CXX_TRACE_FMT_ASYNC(logger, fmt, ...) do { \
366 if (LOG4CXX_UNLIKELY(::LOG4CXX_NS::Logger::isTraceEnabledFor(logger))) {\
367 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
368 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
369 logger->addTraceEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
373 #define LOG4CXX_TRACE_ASYNC(logger, message)
374 #define LOG4CXX_TRACE_FMT_ASYNC(logger, message)
377 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 20000
394 #define LOG4CXX_INFO_ASYNC(logger, message) do { \
395 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
396 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
397 logger->addInfoEvent(std::move(buf << message), LOG4CXX_LOCATION);\
402 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
419 #define LOG4CXX_INFO_FMT_ASYNC(logger, fmt, ...) do { \
420 if (::LOG4CXX_NS::Logger::isInfoEnabledFor(logger)) {\
421 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
422 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
423 logger->addInfoEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
427 #define LOG4CXX_INFO_ASYNC(logger, message)
428 #define LOG4CXX_INFO_FMT_ASYNC(logger, message)
431 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 30000
446 #define LOG4CXX_WARN_ASYNC(logger, message) do { \
447 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
448 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
449 logger->addWarnEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
451 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
467 #define LOG4CXX_WARN_FMT_ASYNC(logger, fmt, ...) do { \
468 if (::LOG4CXX_NS::Logger::isWarnEnabledFor(logger)) {\
469 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
470 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
471 logger->addWarnEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
475 #define LOG4CXX_WARN_ASYNC(logger, message)
476 #define LOG4CXX_WARN_FMT_ASYNC(logger, message)
479 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 40000
494 #define LOG4CXX_ERROR_ASYNC(logger, message) do { \
495 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
496 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
497 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
499 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
515 #define LOG4CXX_ERROR_FMT_ASYNC(logger, fmt, ...) do { \
516 if (::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
517 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
518 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
519 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
529 #define LOG4CXX_ASSERT_ASYNC(logger, condition, message) do { \
530 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
531 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
533 logger->addErrorEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
535 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
546 #define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, fmt, ...) do { \
547 if (!(condition) && ::LOG4CXX_NS::Logger::isErrorEnabledFor(logger)) {\
549 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
550 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
551 logger->addErrorEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
555 #define LOG4CXX_ERROR_ASYNC(logger, message)
556 #define LOG4CXX_ERROR_FMT_ASYNC(logger, message)
557 #define LOG4CXX_ASSERT_ASYNC(logger, condition, message)
558 #define LOG4CXX_ASSERT_FMT_ASYNC(logger, condition, message)
561 #if !defined(LOG4CXX_THRESHOLD) || LOG4CXX_THRESHOLD <= 50000
573 #define LOG4CXX_FATAL_ASYNC(logger, message) do { \
574 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
575 ::LOG4CXX_NS::helpers::AsyncBuffer buf; \
576 logger->addFatalEvent(std::move(buf << message), LOG4CXX_LOCATION); }} while (0)
578 #if LOG4CXX_ASYNC_BUFFER_SUPPORTS_FMT
591 #define LOG4CXX_FATAL_FMT_ASYNC(logger, fmt, ...) do { \
592 if (::LOG4CXX_NS::Logger::isFatalEnabledFor(logger)) {\
593 ::LOG4CXX_NS::helpers::AsyncBuffer buf;\
594 buf.setMessage(fmt LOG4CXX_FMT_VA_ARG(__VA_ARGS__));\
595 logger->addFatalEvent(std::move(buf), LOG4CXX_LOCATION); }} while (0)
599 #define LOG4CXX_FATAL_ASYNC(logger, message)
600 #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 & operator<<(const T &value)
Append a function to this buffer that will convert value to text.
Definition: asyncbuffer.h:76
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
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
std::basic_ostream< char > & operator<<(CharMessageBuffer &os, const V &val)
Definition: log4cxx/helpers/messagebuffer.h:208