14#ifndef INCLUDED_SAL_LOG_HXX
15#define INCLUDED_SAL_LOG_HXX
33enum sal_detail_LogAction
35 SAL_DETAIL_LOG_ACTION_IGNORE,
36 SAL_DETAIL_LOG_ACTION_LOG,
37 SAL_DETAIL_LOG_ACTION_FATAL
41 sal_detail_LogLevel level,
char const * area,
char const * where,
42 char const * message, sal_uInt32 backtraceDepth);
44extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_set_log_selector(
char const *logSelector);
48extern "C" SAL_DLLPUBLIC unsigned char SAL_CALL sal_detail_log_report(
49 sal_detail_LogLevel level,
char const * area);
54 sal_detail_LogLevel level,
char const * area,
char const * where,
55 std::ostringstream
const & stream, sal_uInt32 backtraceDepth)
65 sal_detail_log(level, area, where,
stream.str().c_str(), backtraceDepth);
74 StreamString(
char const * s): string(s) {}
82 typedef struct {
char a[2]; } Result;
85inline StreamString operator <<(
86 SAL_UNUSED_PARAMETER StreamStart
const &,
char const * s)
88 return StreamString(s);
91template<
typename T >
inline StreamIgnore operator <<(
92 SAL_UNUSED_PARAMETER StreamStart
const &, SAL_UNUSED_PARAMETER T
const &)
95#if defined _MSC_VER && _MSC_VER < 1700
96 return StreamIgnore();
100template<
typename T >
inline StreamIgnore operator <<(
101 SAL_UNUSED_PARAMETER StreamString
const &, SAL_UNUSED_PARAMETER T
const &)
104#if defined _MSC_VER && _MSC_VER < 1700
105 return StreamIgnore();
109template<
typename T >
inline StreamIgnore operator <<(
110 SAL_UNUSED_PARAMETER StreamIgnore
const &, SAL_UNUSED_PARAMETER T
const &)
113#if defined _MSC_VER && _MSC_VER < 1700
114 return StreamIgnore();
118template<
typename T >
typename T::Result getResult(T
const &);
120inline char const * unwrapStream(StreamString
const & s) {
return s.string; }
122inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore
const &) {
124#if defined _MSC_VER && _MSC_VER < 1700
133#define SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream) \
134 if (sizeof ::sal::detail::getResult( \
135 ::sal::detail::StreamStart() << stream) == 1) \
138 (level), (area), (where), \
139 ::sal::detail::unwrapStream( \
140 ::sal::detail::StreamStart() << stream), \
143 ::std::ostringstream sal_detail_stream; \
144 sal_detail_stream << stream; \
145 ::sal::detail::log( \
146 (level), (area), (where), sal_detail_stream, 0); \
149#define SAL_DETAIL_LOG_STREAM(condition, level, area, where, stream) \
151 if (SAL_UNLIKELY(condition)) \
153 switch (sal_detail_log_report(level, area)) \
155 case SAL_DETAIL_LOG_ACTION_IGNORE: break; \
156 case SAL_DETAIL_LOG_ACTION_LOG: \
157 SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream); \
159 case SAL_DETAIL_LOG_ACTION_FATAL: \
160 SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream); \
179#define SAL_WHERE SAL_DETAIL_WHERE
195#if defined _LIBCPP_VERSION \
196 || (defined _GLIBCXX_RELEASE \
197 && (_GLIBCXX_RELEASE >= 12 || (_GLIBCXX_RELEASE == 11 && __GLIBCXX__ > 20210428))) \
198 || (defined _MSC_VER && _MSC_VER >= 1915)
199#define SAL_STREAM(stream) \
200 (::std::ostringstream() << stream).str()
202#define SAL_STREAM(stream) \
203 (dynamic_cast< ::std::ostringstream & >(::std::ostringstream() << stream).str())
343#define SAL_INFO(area, stream) \
344 SAL_DETAIL_LOG_STREAM( \
345 SAL_DETAIL_ENABLE_LOG_INFO, ::SAL_DETAIL_LOG_LEVEL_INFO, area, \
353#define SAL_INFO_IF(condition, area, stream) \
354 SAL_DETAIL_LOG_STREAM( \
355 SAL_DETAIL_ENABLE_LOG_INFO && (condition), \
356 ::SAL_DETAIL_LOG_LEVEL_INFO, area, SAL_WHERE, stream)
363#define SAL_WARN(area, stream) \
364 SAL_DETAIL_LOG_STREAM( \
365 SAL_DETAIL_ENABLE_LOG_WARN, ::SAL_DETAIL_LOG_LEVEL_WARN, area, \
373#define SAL_WARN_IF(condition, area, stream) \
374 SAL_DETAIL_LOG_STREAM( \
375 SAL_DETAIL_ENABLE_LOG_WARN && (condition), \
376 ::SAL_DETAIL_LOG_LEVEL_WARN, area, SAL_WHERE, stream)
384#define SAL_DEBUG(stream) \
385 SAL_DETAIL_LOG_STREAM( \
386 SAL_LOG_TRUE, ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, stream)
395#define SAL_DEBUG_IF(condition, stream) \
396 SAL_DETAIL_LOG_STREAM( \
397 (condition), ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, stream)
413#define SAL_DEBUG_BACKTRACE(stream, backtraceDepth) \
415 if (sizeof ::sal::detail::getResult( \
416 ::sal::detail::StreamStart() << stream) == 1) \
419 ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, \
420 ::sal::detail::unwrapStream( \
421 ::sal::detail::StreamStart() << stream), \
424 ::std::ostringstream sal_detail_stream; \
425 sal_detail_stream << stream; \
426 ::sal::detail::log( \
427 ::SAL_DETAIL_LOG_LEVEL_DEBUG, NULL, NULL, sal_detail_stream, \
Reference< XOutputStream > stream