{"id":16048,"url":"https://patchwork.libcamera.org/api/patches/16048/?format=json","web_url":"https://patchwork.libcamera.org/patch/16048/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220525222503.6460-6-laurent.pinchart@ideasonboard.com>","date":"2022-05-25T22:25:03","name":"[libcamera-devel,5/5] libcamera: base: log: Color the log prefix","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"cc2094bfa871e9025dcdeafed42176bc3eb027b4","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/16048/mbox/","series":[{"id":3140,"url":"https://patchwork.libcamera.org/api/series/3140/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3140","date":"2022-05-25T22:24:58","name":"libcamera: Add colors to the log","version":1,"mbox":"https://patchwork.libcamera.org/series/3140/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/16048/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/16048/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D003DC326F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 May 2022 22:25:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 621616566F;\n\tThu, 26 May 2022 00:25:19 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 34B1E65663\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 26 May 2022 00:25:14 +0200 (CEST)","from pendragon.ideasonboard.com (ip-109-40-242-63.web.vodafone.de\n\t[109.40.242.63])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B53FE130D;\n\tThu, 26 May 2022 00:25:13 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1653517519;\n\tbh=kuB568dBMjp61dX6X9khHhh4gpoISWt6Zsvpbz9V1wk=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=k1JbBwVHLk37NAOqfOcoqN8+9UM7/4BiVmWp/UYjsmxYGD8TEBKax/KFSFANOSPHx\n\tUVcoButgcIaOfRfueSoeaIHIUU0Xc59gMYV0HP3+t1ypUH20Nil9ugEZT2jiC30UMs\n\t0eNqaI64VqxsFPBv51LQlYUVK/ykYfXbLk8qjbjFyaWl19VzP/isHs83MW5nDqAWh7\n\tU8wuKogZpLS9VdP26ERX/eSLjZOnQFdz6agF2QlqRFS532iMpWY6N3g6JTL1ObPV24\n\tSCm9Q9Rrz2/NdZw73zOlSeFOkvcbRNpe2iK07z1iPTEpl/gBDL8QzkcmNJ3n/Q6Ewf\n\trMTIvTvJbshmA==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1653517514;\n\tbh=kuB568dBMjp61dX6X9khHhh4gpoISWt6Zsvpbz9V1wk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=kVEGYEpQovaxO9Vi5xOEE6SJTMeU2V8e2k/RWaM+si+JTzdPPH6EjFntSPbiX3AXX\n\tLyn12KdtnRPZTDfnyQv5v+3m0eSJa2bW1NbVZmv2biKYkVdFEEnnVcSBhLi52RufJ7\n\tLKVmGQB/cHUGHjvEN2nplLXVFbMk3cjbW5NEg3VU="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"kVEGYEpQ\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 26 May 2022 01:25:03 +0300","Message-Id":"<20220525222503.6460-6-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","In-Reply-To":"<20220525222503.6460-1-laurent.pinchart@ideasonboard.com>","References":"<20220525222503.6460-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 5/5] libcamera: base: log: Color the log\n\tprefix","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add coloring to the log prefix to increase log readability.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/base/log.h |  5 ++++-\n src/libcamera/base/log.cpp   | 37 +++++++++++++++++++++++-------------\n 2 files changed, 28 insertions(+), 14 deletions(-)","diff":"diff --git a/include/libcamera/base/log.h b/include/libcamera/base/log.h\nindex 3f065267c914..3fc5ced38a6a 100644\n--- a/include/libcamera/base/log.h\n+++ b/include/libcamera/base/log.h\n@@ -57,7 +57,8 @@ class LogMessage\n {\n public:\n \tLogMessage(const char *fileName, unsigned int line,\n-\t\t   const LogCategory &category, LogSeverity severity);\n+\t\t   const LogCategory &category, LogSeverity severity,\n+\t\t   const std::string &prefix = std::string());\n \n \tLogMessage(LogMessage &&);\n \t~LogMessage();\n@@ -68,6 +69,7 @@ public:\n \tLogSeverity severity() const { return severity_; }\n \tconst LogCategory &category() const { return category_; }\n \tconst std::string &fileInfo() const { return fileInfo_; }\n+\tconst std::string &prefix() const { return prefix_; }\n \tconst std::string msg() const { return msgStream_.str(); }\n \n private:\n@@ -80,6 +82,7 @@ private:\n \tLogSeverity severity_;\n \tutils::time_point timestamp_;\n \tstd::string fileInfo_;\n+\tstd::string prefix_;\n };\n \n class Loggable\ndiff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp\nindex a9f5bbbd36f7..6620a50a5b6f 100644\n--- a/src/libcamera/base/log.cpp\n+++ b/src/libcamera/base/log.cpp\n@@ -219,6 +219,7 @@ void LogOutput::write(const LogMessage &msg)\n \n \tconst char *categoryColor = color_ ? kColorBrightWhite : \"\";\n \tconst char *fileColor = color_ ? kColorBrightBlue : \"\";\n+\tconst char *prefixColor = color_ ? kColorGreen : \"\";\n \tconst char *msgColor = color_ ? kColorReset : \"\";\n \tconst char *severityColor = \"\";\n \tLogSeverity severity = msg.severity();\n@@ -234,8 +235,10 @@ void LogOutput::write(const LogMessage &msg)\n \tswitch (target_) {\n \tcase LoggingTargetSyslog:\n \t\tstr = std::string(log_severity_name(severity)) + \" \"\n-\t\t    + msg.category().name() + \" \" + msg.fileInfo() + \" \"\n-\t\t    + msg.msg();\n+\t\t    + msg.category().name() + \" \" + msg.fileInfo() + \" \";\n+\t\tif (!msg.prefix().empty())\n+\t\t\tstr += msg.prefix() + \": \";\n+\t\tstr += msg.msg();\n \t\twriteSyslog(severity, str);\n \t\tbreak;\n \tcase LoggingTargetStream:\n@@ -244,8 +247,10 @@ void LogOutput::write(const LogMessage &msg)\n \t\t    + std::to_string(Thread::currentId()) + \"] \"\n \t\t    + severityColor + log_severity_name(severity) + \" \"\n \t\t    + categoryColor + msg.category().name() + \" \"\n-\t\t    + fileColor + msg.fileInfo() + \" \"\n-\t\t    + msgColor + msg.msg();\n+\t\t    + fileColor + msg.fileInfo() + \" \";\n+\t\tif (!msg.prefix().empty())\n+\t\t\tstr += prefixColor + msg.prefix() + \": \";\n+\t\tstr += msgColor + msg.msg();\n \t\twriteStream(str);\n \t\tbreak;\n \tdefault:\n@@ -823,14 +828,17 @@ const LogCategory &LogCategory::defaultCategory()\n  * will be displayed\n  * \\param[in] severity The log message severity, controlling how the message\n  * will be displayed\n+ * \\param[in] prefix The log message prefix\n  *\n  * Create a log message pertaining to line \\a line of file \\a fileName. The\n  * \\a severity argument sets the message severity to control whether it will be\n- * output or dropped.\n+ * output or dropped. The \\a prefix optionally identifies the object instance\n+ * logging the message.\n  */\n LogMessage::LogMessage(const char *fileName, unsigned int line,\n-\t\t       const LogCategory &category, LogSeverity severity)\n-\t: category_(category), severity_(severity)\n+\t\t       const LogCategory &category, LogSeverity severity,\n+\t\t       const std::string &prefix)\n+\t: category_(category), severity_(severity), prefix_(prefix)\n {\n \tinit(fileName, line);\n }\n@@ -919,6 +927,12 @@ LogMessage::~LogMessage()\n  * \\return The file info of the message\n  */\n \n+/**\n+ * \\fn LogMessage::prefix()\n+ * \\brief Retrieve the prefix of the log message\n+ * \\return The prefix of the message\n+ */\n+\n /**\n  * \\fn LogMessage::msg()\n  * \\brief Retrieve the message text of the log message\n@@ -966,12 +980,9 @@ Loggable::~Loggable()\n LogMessage Loggable::_log(const LogCategory *category, LogSeverity severity,\n \t\t\t  const char *fileName, unsigned int line) const\n {\n-\tLogMessage msg(fileName, line,\n-\t\t       category ? *category : LogCategory::defaultCategory(),\n-\t\t       severity);\n-\n-\tmsg.stream() << logPrefix() << \": \";\n-\treturn msg;\n+\treturn LogMessage(fileName, line,\n+\t\t\t  category ? *category : LogCategory::defaultCategory(),\n+\t\t\t  severity, logPrefix());\n }\n \n /**\n","prefixes":["libcamera-devel","5/5"]}