From patchwork Mon Jan 7 23:11:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 164 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D5AE760B2F for ; Tue, 8 Jan 2019 00:10:47 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D85AE4E for ; Tue, 8 Jan 2019 00:10:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1546902647; bh=kNEiHO6mGEMjpYrC1VfFDRa+lwkG3MBWL+XDWZWxNGE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Nl3sQA4TgTJ4+sHM67EYvJ5Xqfj4Vax8QPw49XMLzHRElLc3q+tWKES/SIm6pHsEg 8ZrpSLhPaWuDyzKxlQHbqiq8gt5L5oRI/9ZcMJtCH4rpIblDokz9WqyEI3A9aEXCys E/P9A/Kn0xCD/LezngyCwujsvS/HQ5aR8IlcZBuI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 8 Jan 2019 01:11:41 +0200 Message-Id: <20190107231151.23291-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190107231151.23291-1-laurent.pinchart@ideasonboard.com> References: <20190107231151.23291-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/11] libcamera: log: Add a LogFatal log level X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jan 2019 23:10:48 -0000 The LogFatal log level is similar to the LogError level, but additionally abort program execution. This is useful to implement assertion handlers. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/libcamera/include/log.h | 2 ++ src/libcamera/log.cpp | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h index 74439848c6ca..03842be02d0e 100644 --- a/src/libcamera/include/log.h +++ b/src/libcamera/include/log.h @@ -16,6 +16,7 @@ enum LogSeverity { LogInfo, LogWarning, LogError, + LogFatal, }; class LogMessage @@ -30,6 +31,7 @@ public: private: std::ostringstream msgStream; + LogSeverity severity_; }; #define LOG(severity) LogMessage(__FILE__, __LINE__, Log##severity).stream() diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index 44b3a5bbe279..a5823c64eaa6 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -31,6 +32,8 @@ namespace libcamera { * Warning message, signals a potential issue * \var LogError * Error message, signals an unrecoverable issue + * \var LogFatal + * Fatal message, signals an unrecoverable issue and aborts execution */ /** @@ -40,15 +43,19 @@ namespace libcamera { * Return an std::ostream reference to which a message can be logged using the * iostream API. The \a severity controls whether the message is printed or * dropped, depending on the global log level. + * + * If the severity is set to Fatal, execution is aborted and the program + * terminates immediately after printing the message. */ static const char *log_severity_name(LogSeverity severity) { static const char * const names[] = { - " DBG", - "INFO", - "WARN", - " ERR", + " DBG", + " INFO", + " WARN", + " ERR", + "FATAL", }; if (static_cast(severity) < ARRAY_SIZE(names)) @@ -73,6 +80,7 @@ static const char *log_severity_name(LogSeverity severity) */ LogMessage::LogMessage(const char *fileName, unsigned int line, LogSeverity severity) + : severity_(severity) { /* Log the timestamp, severity and file information. */ struct timespec timestamp; @@ -93,6 +101,9 @@ LogMessage::~LogMessage() std::string msg(msgStream.str()); fwrite(msg.data(), msg.size(), 1, stderr); fflush(stderr); + + if (severity_ == LogSeverity::LogFatal) + std::abort(); } /**