summaryrefslogtreecommitdiff
path: root/include/sal
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2020-07-01 18:06:28 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-07-07 14:15:04 +0200
commitb9d93fc47b2489764e251a11572fccef872df4e9 (patch)
tree068a20b6fde20359b87bd98ebcee31f6efbd0ed4 /include/sal
parent372b109f4d90dca7bb53f93bc597ce1dd8ba5898 (diff)
Allow making SAL_LOG based output fatal
This introduces the [+-]FATAL marker for SAL_LOG. This way you can set part of the matching SAL_LOG string to std::abort on match. The example "SAL_LOG=+FATAL+WARN.vcl.scheduler-FATAL+INFO" will abort for any "+WARN.vcl.scheduler" match, but will just print all additional "+INFO" logs. Change-Id: Ib77f194a78f5165e6c885c82374ae41293815ee9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97651 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'include/sal')
-rw-r--r--include/sal/log.hxx61
1 files changed, 46 insertions, 15 deletions
diff --git a/include/sal/log.hxx b/include/sal/log.hxx
index 00d533ab5495..6bb0d1b43d3d 100644
--- a/include/sal/log.hxx
+++ b/include/sal/log.hxx
@@ -26,11 +26,20 @@
/// @cond INTERNAL
+enum sal_detail_LogAction
+{
+ SAL_DETAIL_LOG_ACTION_IGNORE,
+ SAL_DETAIL_LOG_ACTION_LOG,
+ SAL_DETAIL_LOG_ACTION_FATAL
+};
+
extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_log(
sal_detail_LogLevel level, char const * area, char const * where,
char const * message, sal_uInt32 backtraceDepth);
-extern "C" SAL_DLLPUBLIC sal_Bool SAL_CALL sal_detail_log_report(
+// the return value is actually "enum sal_detail_LogAction", but due to ABI
+// compatibility, it's left as the original "sal_Bool" / "unsigned char".
+extern "C" SAL_DLLPUBLIC unsigned char SAL_CALL sal_detail_log_report(
sal_detail_LogLevel level, char const * area);
namespace sal { namespace detail {
@@ -113,22 +122,38 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
} }
+// to prevent using a local variable, which can eventually shadow,
+// resulting in compiler warnings (or even errors with -Werror)
+#define SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream) \
+ if (sizeof ::sal::detail::getResult( \
+ ::sal::detail::StreamStart() << stream) == 1) \
+ { \
+ ::sal_detail_log( \
+ (level), (area), (where), \
+ ::sal::detail::unwrapStream( \
+ ::sal::detail::StreamStart() << stream), \
+ 0); \
+ } else { \
+ ::std::ostringstream sal_detail_stream; \
+ sal_detail_stream << stream; \
+ ::sal::detail::log( \
+ (level), (area), (where), sal_detail_stream, 0); \
+ }
+
#define SAL_DETAIL_LOG_STREAM(condition, level, area, where, stream) \
do { \
- if ((condition) && sal_detail_log_report(level, area)) { \
- if (sizeof ::sal::detail::getResult( \
- ::sal::detail::StreamStart() << stream) == 1) \
+ if (condition) \
+ { \
+ switch (sal_detail_log_report(level, area)) \
{ \
- ::sal_detail_log( \
- (level), (area), (where), \
- ::sal::detail::unwrapStream( \
- ::sal::detail::StreamStart() << stream), \
- 0); \
- } else { \
- ::std::ostringstream sal_detail_stream; \
- sal_detail_stream << stream; \
- ::sal::detail::log( \
- (level), (area), (where), sal_detail_stream, 0); \
+ case SAL_DETAIL_LOG_ACTION_IGNORE: break; \
+ case SAL_DETAIL_LOG_ACTION_LOG: \
+ SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream); \
+ break; \
+ case SAL_DETAIL_LOG_ACTION_FATAL: \
+ SAL_DETAIL_LOG_STREAM_PRIVATE_(level, area, where, stream); \
+ std::abort(); \
+ break; \
} \
} \
} while (false)
@@ -235,7 +260,7 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
<switch> ::= <sense><item>
<sense> ::= "+"|"-"
<item> ::= <flag>|<level>("."<area>)?
- <flag> ::= "TIMESTAMP"|"RELATIVETIMER"
+ <flag> ::= "TIMESTAMP"|"RELATIVETIMER"|"FATAL"
<level> ::= "INFO"|"WARN"
@endverbatim
@@ -252,6 +277,12 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
the level switch(es)) to be prefixed by a relative timestamp in
seconds since the first output line like 1.312.
+ The "+FATAL" flag will cause later matching rules to log and call
+ std::abort. This can be disabled at some later point by using the
+ "-FATAL" flag before specifying additional rules. The flag will just
+ abort on positive rules, as it doesn't seem to make sense to abort
+ on ignored output.
+
If both +TIMESTAMP and +RELATIVETIMER are specified, they are
output in that order.