summaryrefslogtreecommitdiff
path: root/src/libcamera/log.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-04 17:46:35 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-08 16:23:16 +0200
commit99a3e7bcfb38fea95092dcfff99a6b84f42f456c (patch)
treefd761519380b45f839f17269a22a7312af22e1f6 /src/libcamera/log.cpp
parente256a58bf0cd313f2f4e5a1e3eea67fe3141ea08 (diff)
libcamera: log: Add a LogFatal log level
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/libcamera/log.cpp')
-rw-r--r--src/libcamera/log.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp
index 44b3a5bb..a5823c64 100644
--- a/src/libcamera/log.cpp
+++ b/src/libcamera/log.cpp
@@ -6,6 +6,7 @@
*/
#include <cstdio>
+#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <string.h>
@@ -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<unsigned int>(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();
}
/**