Show a patch.

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

{
    "id": 12198,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/12198/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/12198/",
    "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": "<20210505153318.8519-1-m.felsch@pengutronix.de>",
    "date": "2021-05-05T15:33:18",
    "name": "[libcamera-devel] libcamera: log: add colors to log levels",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "4dad72ed9127397ca0d6c6f874c2bf7f44f09ccf",
    "submitter": {
        "id": 89,
        "url": "https://patchwork.libcamera.org/api/1.1/people/89/?format=api",
        "name": "Marco Felsch",
        "email": "m.felsch@pengutronix.de"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/12198/mbox/",
    "series": [
        {
            "id": 2000,
            "url": "https://patchwork.libcamera.org/api/1.1/series/2000/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2000",
            "date": "2021-05-05T15:33:18",
            "name": "[libcamera-devel] libcamera: log: add colors to log levels",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2000/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/12198/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/12198/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 12F2FBDE7C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  5 May 2021 15:33:29 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8836568909;\n\tWed,  5 May 2021 17:33:28 +0200 (CEST)",
            "from metis.ext.pengutronix.de (metis.ext.pengutronix.de\n\t[IPv6:2001:67c:670:201:290:27ff:fe1d:cc33])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F3F57602BD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  5 May 2021 17:33:26 +0200 (CEST)",
            "from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28])\n\tby metis.ext.pengutronix.de with esmtps\n\t(TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92)\n\t(envelope-from <mfe@pengutronix.de>) id 1leJWg-0004Rq-Ig\n\tfor libcamera-devel@lists.libcamera.org;\n\tWed, 05 May 2021 17:33:26 +0200",
            "from mfe by dude02.hi.pengutronix.de with local (Exim 4.92)\n\t(envelope-from <mfe@pengutronix.de>) id 1leJWg-0002Ns-9s\n\tfor libcamera-devel@lists.libcamera.org;\n\tWed, 05 May 2021 17:33:26 +0200"
        ],
        "From": "Marco Felsch <m.felsch@pengutronix.de>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed,  5 May 2021 17:33:18 +0200",
        "Message-Id": "<20210505153318.8519-1-m.felsch@pengutronix.de>",
        "X-Mailer": "git-send-email 2.29.2",
        "MIME-Version": "1.0",
        "X-SA-Exim-Connect-IP": "2001:67c:670:100:1d::28",
        "X-SA-Exim-Mail-From": "mfe@pengutronix.de",
        "X-SA-Exim-Scanned": "No (on metis.ext.pengutronix.de);\n\tSAEximRunCond expanded to false",
        "X-PTX-Original-Recipient": "libcamera-devel@lists.libcamera.org",
        "Subject": "[libcamera-devel] [PATCH] libcamera: log: add colors to log levels",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add colored logs if the output belongs to a terminal. This makes it easier\nto identitify warnings and/or errors.\n\nSigned-off-by: Marco Felsch <m.felsch@pengutronix.de>\n---\nHi all,\n\nthis is an reworked version of [1]. I used by sob and auther since I did\nmore changes than I kept from [1].\n\n[1] 20210203181746.22028-1-m.cichy@pengutronix.de\n\n src/libcamera/log.cpp | 28 ++++++++++++++++++++++++++++\n 1 file changed, 28 insertions(+)",
    "diff": "diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\nindex 94175ab3..3dffd004 100644\n--- a/src/libcamera/log.cpp\n+++ b/src/libcamera/log.cpp\n@@ -19,6 +19,7 @@\n #include <string.h>\n #include <syslog.h>\n #include <time.h>\n+#include <unistd.h>\n #include <unordered_set>\n \n #include <libcamera/logging.h>\n@@ -98,6 +99,26 @@ static const char *log_severity_name(LogSeverity severity)\n \t\treturn \"UNKWN\";\n }\n \n+static const char *log_severity_color_name(LogSeverity severity)\n+{\n+\tstatic const char *const names[] = {\n+\t\t\"\\033[1m\\033[37mDEBUG\\033[0m\",\n+\t\t\"\\033[1m\\033[32m INFO\\033[0m\",\n+\t\t\"\\033[1m\\033[33m WARN\\033[0m\",\n+\t\t\"\\033[1m\\033[31mERROR\\033[0m\",\n+\t\t\"\\033[1m\\033[35mFATAL\\033[0m\",\n+\t};\n+\n+\t/* Only print colored output if output really belongs to a terminal */\n+\tif (!isatty(fileno(stderr)))\n+\t\treturn log_severity_name(severity);\n+\n+\tif (static_cast<unsigned int>(severity) < std::size(names))\n+\t\treturn names[severity];\n+\telse\n+\t\treturn \"\\033[1m\\033[32mUNKWN\\033[0m\";\n+}\n+\n /**\n  * \\brief Log output\n  *\n@@ -197,6 +218,13 @@ void LogOutput::write(const LogMessage &msg)\n \t\twriteSyslog(msg.severity(), str);\n \t\tbreak;\n \tcase LoggingTargetStream:\n+\t\tstr = \"[\" + utils::time_point_to_string(msg.timestamp()) + \"] [\"\n+\t\t    + std::to_string(Thread::currentId()) + \"] \"\n+\t\t    + log_severity_color_name(msg.severity()) + \" \"\n+\t\t    + msg.category().name() + \" \" + msg.fileInfo() + \" \"\n+\t\t    + msg.msg();\n+\t\twriteStream(str);\n+\t\tbreak;\n \tcase LoggingTargetFile:\n \t\tstr = \"[\" + utils::time_point_to_string(msg.timestamp()) + \"] [\"\n \t\t    + std::to_string(Thread::currentId()) + \"] \"\n",
    "prefixes": [
        "libcamera-devel"
    ]
}