Show a patch.

GET /api/1.1/patches/16132/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 16132,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/16132/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16132/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20220602073405.28168-3-laurent.pinchart@ideasonboard.com>",
    "date": "2022-06-02T07:34:05",
    "name": "[libcamera-devel,v2,2/2] libcamera: base: log: Color the log prefix",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "326bf1d22c11d48cef5d8bf82421a1151186b795",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16132/mbox/",
    "series": [
        {
            "id": 3153,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3153/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3153",
            "date": "2022-06-02T07:34:03",
            "name": "libcamera: Add colors to the log",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3153/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16132/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16132/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 E42D8C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Jun 2022 07:34:15 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C0AF965633;\n\tThu,  2 Jun 2022 09:34:14 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 31D1B65633\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Jun 2022 09:34:13 +0200 (CEST)",
            "from pendragon.ideasonboard.com\n\t(lmontsouris-659-1-41-236.w92-154.abo.wanadoo.fr [92.154.76.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EBFE2895\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Jun 2022 09:34:12 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1654155254;\n\tbh=FlfL6DMQE70U8Vd6TwwD5DQnnz9cNY963YOtjCmwT3M=;\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=tU+mWVi4oipoPGTjtRGO89OqCfT3NkCr5gSd4+Ge+MmqjNuUfOL8Dx4AkFj1I8Sm2\n\tuEAKLAhYG+V2le2IVNL6F/2SNcD6IW3wHSKMXtb6eX0ru6WxSKB2pV9sl1E0xHviFj\n\tCKoEyCp0lT7sO6H53gzAAttU1wxd6QDf6ifEkxuYF0yQutU16GAiR6o656Q1id36FX\n\tbBLRLb6Qjifh+ARA5NR6HEuPNbsquX/gyLeo1QSZQ147YKOPJuEyLtG3KMeppwb5V9\n\t/dyUrtUo5WcAeD7uIHkCMzYuIlvEaN3GirpQwMVsRWO0asCi2nz16vyyy+OPgyrgGj\n\tm3BWtIS8ya/Zw==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1654155253;\n\tbh=FlfL6DMQE70U8Vd6TwwD5DQnnz9cNY963YOtjCmwT3M=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=kbW7BHPVd8IzpljaPsgj5M7CVi0J9oXBJeRFoc+9IF/0VnGbw1XU7+sAb525NZjqK\n\tf6UrChfRi+vuRU1CrqPL4FAbRplxyIzBIBcA6lqIRWpNZqSLt5A2fL1AUxpuD841uG\n\tV6TEa/ZOxSwfsaUneDtszzHewPWQkRNqCSAz6YrY="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"kbW7BHPV\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  2 Jun 2022 10:34:05 +0300",
        "Message-Id": "<20220602073405.28168-3-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220602073405.28168-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20220602073405.28168-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 2/2] libcamera: base: log: Color the\n\tlog prefix",
        "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>\nReviewed-by: Umang Jain <umang.jain@ideasonboard.com>\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n---\n include/libcamera/base/log.h |  5 ++++-\n src/libcamera/base/log.cpp   | 38 ++++++++++++++++++++++++------------\n 2 files changed, 29 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 eefdda4ba177..5c359a22d71b 100644\n--- a/src/libcamera/base/log.cpp\n+++ b/src/libcamera/base/log.cpp\n@@ -189,6 +189,7 @@ namespace {\n  * https://en.wikipedia.org/wiki/ANSI_escape_code#Colors.\n  */\n constexpr const char *kColorReset = \"\\033[0m\";\n+constexpr const char *kColorGreen = \"\\033[0;32m\";\n constexpr const char *kColorBrightRed = \"\\033[1;31m\";\n constexpr const char *kColorBrightGreen = \"\\033[1;32m\";\n constexpr const char *kColorBrightYellow = \"\\033[1;33m\";\n@@ -215,6 +216,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 *resetColor = color_ ? kColorReset : \"\";\n \tconst char *severityColor = \"\";\n \tLogSeverity severity = msg.severity();\n@@ -230,8 +232,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@@ -240,8 +244,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    + resetColor + msg.msg();\n+\t\t    + fileColor + msg.fileInfo() + \" \";\n+\t\tif (!msg.prefix().empty())\n+\t\t\tstr += prefixColor + msg.prefix() + \": \";\n+\t\tstr += resetColor + msg.msg();\n \t\twriteStream(str);\n \t\tbreak;\n \tdefault:\n@@ -819,14 +825,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@@ -915,6 +924,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@@ -962,12 +977,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",
        "v2",
        "2/2"
    ]
}