Show a patch.

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

{
    "id": 24,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/24/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/24/",
    "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": "<20181204221123.571-3-laurent.pinchart@ideasonboard.com>",
    "date": "2018-12-04T22:11:22",
    "name": "[libcamera-devel,2/3] libcamera: Add initial logger",
    "commit_ref": "edbd2059d8a4bd759302ada4368fa4055638fd7f",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "a664aaecf25e73a6266ab7526cd6ae40254dfd0b",
    "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/24/mbox/",
    "series": [
        {
            "id": 13,
            "url": "https://patchwork.libcamera.org/api/1.1/series/13/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=13",
            "date": "2018-12-04T22:11:20",
            "name": "libcamera: Add initial logger support",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/13/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/24/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/24/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7721360A71\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  4 Dec 2018 23:10:53 +0100 (CET)",
            "from avalon.bb.dnainternet.fi\n\t(dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E62CA546\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  4 Dec 2018 23:10:52 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1543961453;\n\tbh=/W1F+eov4TJl0wJgwzn2U/cPNmmYJ4Z5ysxNHxNk0/U=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=ulJWhvxv3noLR/4tW1i2b/maOUq8AS11sFNiPzefpGi0ZwjwWFnxOaGx7yUhmGyAD\n\tzEOoxxvU2KfbzpVwZ9lE4byFmtWEPRDQjSVUqbL0oJH4YFPwJYV8bABgPwHpPG4GUn\n\tgR7luAZ0gRF43ijKQjm2Ux+hzTQid/SfGOOE6n3M=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed,  5 Dec 2018 00:11:22 +0200",
        "Message-Id": "<20181204221123.571-3-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.19.2",
        "In-Reply-To": "<20181204221123.571-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20181204221123.571-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 2/3] libcamera: Add initial logger",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.23",
        "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>",
        "X-List-Received-Date": "Tue, 04 Dec 2018 22:10:53 -0000"
    },
    "content": "The logger is based on the ostream API, allowing code to log messages in\na native way. It automatically logs the time stamp, severity level, file\nname and line number.\n\nMany important features are missing, such as logging to file, logging\nclasses, and log filtering based on the severity level, file name and\nclass.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/.keep_empty |  0\n src/libcamera/include/log.h       | 38 +++++++++++++++\n src/libcamera/include/utils.h     | 12 +++++\n src/libcamera/log.cpp             | 81 +++++++++++++++++++++++++++++++\n src/libcamera/meson.build         |  5 +-\n 5 files changed, 135 insertions(+), 1 deletion(-)\n delete mode 100644 src/libcamera/include/.keep_empty\n create mode 100644 src/libcamera/include/log.h\n create mode 100644 src/libcamera/include/utils.h\n create mode 100644 src/libcamera/log.cpp",
    "diff": "diff --git a/src/libcamera/include/.keep_empty b/src/libcamera/include/.keep_empty\ndeleted file mode 100644\nindex e69de29bb2d1..000000000000\ndiff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h\nnew file mode 100644\nindex 000000000000..76acd1520868\n--- /dev/null\n+++ b/src/libcamera/include/log.h\n@@ -0,0 +1,38 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * log.h - Logging infrastructure\n+ */\n+#ifndef __LIBCAMERA_LOG_H__\n+#define __LIBCAMERA_LOG_H__\n+\n+#include <sstream>\n+\n+namespace libcamera {\n+\n+enum LogSeverity {\n+\tLogInfo,\n+\tLogWarning,\n+\tLogError,\n+};\n+\n+class LogMessage\n+{\n+public:\n+\tLogMessage(const char *fileName, unsigned int line,\n+\t\t  LogSeverity severity);\n+\tLogMessage(const LogMessage&) = delete;\n+\t~LogMessage();\n+\n+\tstd::ostream& stream() { return msgStream; }\n+\n+private:\n+\tstd::ostringstream msgStream;\n+};\n+\n+#define LOG(severity) LogMessage(__FILE__, __LINE__, Log##severity).stream()\n+\n+};\n+\n+#endif /* __LIBCAMERA_LOG_H__ */\ndiff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\nnew file mode 100644\nindex 000000000000..3ffa6f4ea591\n--- /dev/null\n+++ b/src/libcamera/include/utils.h\n@@ -0,0 +1,12 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * utils.h - Miscellaneous utility functions\n+ */\n+#ifndef __LIBCAMERA_UTILS_H__\n+#define __LIBCAMERA_UTILS_H__\n+\n+#define ARRAY_SIZE(a)\t(sizeof(a) / sizeof(a[0]))\n+\n+#endif /* __LIBCAMERA_UTILS_H__ */\ndiff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\nnew file mode 100644\nindex 000000000000..18ccfa32d8b4\n--- /dev/null\n+++ b/src/libcamera/log.cpp\n@@ -0,0 +1,81 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2018, Google Inc.\n+ *\n+ * log.h - Logging infrastructure\n+ */\n+\n+#include <cstdio>\n+#include <ctime>\n+#include <iomanip>\n+#include <string.h>\n+\n+#include \"log.h\"\n+#include \"utils.h\"\n+\n+/**\n+ * \\file log.h\n+ * \\brief Logging infrastructure\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\enum LogSeverity\n+ * Log message severity\n+ * \\var Info\n+ * Informational message\n+ * \\var Warning\n+ * Warning message, signals a potential issue\n+ * \\var Error\n+ * Error message, signals an unrecoverable issue\n+ */\n+\n+/**\n+ * \\def LOG(severity)\n+ * \\brief Log a message\n+ *\n+ * Return an std::ostream reference to which a message can be logged using the\n+ * iostream API. The \\a severity controls whether the message is printed or\n+ * dropped, depending on the global log level.\n+ */\n+\n+static const char *log_severity_name(LogSeverity severity)\n+{\n+\tstatic const char * const names[] = {\n+\t\t\"INFO\",\n+\t\t\"WARN\",\n+\t\t\" ERR\",\n+\t};\n+\n+\tif ((unsigned int)severity < ARRAY_SIZE(names))\n+\t\treturn names[severity];\n+\telse\n+\t\treturn \"UNKN\";\n+}\n+\n+LogMessage::LogMessage(const char *fileName, unsigned int line,\n+\t\t       LogSeverity severity)\n+{\n+\t/* Log the timestamp, severity and file information. */\n+\tstruct timespec timestamp;\n+\tclock_gettime(CLOCK_MONOTONIC, &timestamp);\n+\tmsgStream << \"[\" << timestamp.tv_sec / (60 * 60) << \":\"\n+\t\t  << std::setw(2) << (timestamp.tv_sec / 60) % 60 << \":\"\n+\t\t  << std::setw(2) << timestamp.tv_sec % 60 << \".\"\n+\t\t  << std::setw(9) << timestamp.tv_nsec << \"]\";\n+\n+\tmsgStream << \" \" << log_severity_name(severity);\n+\tmsgStream << \" \" << basename(fileName) << \":\" << line << \" \";\n+}\n+\n+LogMessage::~LogMessage()\n+{\n+\tmsgStream << std::endl;\n+\n+\tstd::string msg(msgStream.str());\n+\tfwrite(msg.data(), msg.size(), 1, stderr);\n+\tfflush(stderr);\n+}\n+\n+};\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 07d9cd448342..fe38f8b2b5b4 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -1,4 +1,7 @@\n-sources = ['main.cpp']\n+sources = files([\n+    'log.cpp',\n+    'main.cpp',\n+])\n \n includes = [\n     libcamera_includes,\n",
    "prefixes": [
        "libcamera-devel",
        "2/3"
    ]
}