Show a patch.

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

{
    "id": 550,
    "url": "https://patchwork.libcamera.org/api/patches/550/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/550/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20190208144540.15529-1-laurent.pinchart@ideasonboard.com>",
    "date": "2019-02-08T14:45:39",
    "name": "[libcamera-devel,1/2] libcamera: log: Allow extending log messages",
    "commit_ref": "8a401ed4119aac4ca994f70cb5540bc1b2c6939a",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "4ddf5046574cbdc5301d18a9224521824d6ab777",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/550/mbox/",
    "series": [
        {
            "id": 173,
            "url": "https://patchwork.libcamera.org/api/series/173/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=173",
            "date": "2019-02-08T14:45:39",
            "name": "[libcamera-devel,1/2] libcamera: log: Allow extending log messages",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/173/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/550/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/550/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 390B66101F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Feb 2019 15:45:45 +0100 (CET)",
            "from pendragon.ideasonboard.com (d51A4137F.access.telenet.be\n\t[81.164.19.127])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B6995F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Feb 2019 15:45:44 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1549637144;\n\tbh=S7QKr3bt37u0JJIVa6LLliKnTdpxqLDVlTrplif6/Lo=;\n\th=From:To:Subject:Date:From;\n\tb=T/0mAGds8QvsN5/QBhuGasHlK6f6M7LK4FZ4beCADiKETIagKpwnCQH5egs55YqrT\n\twnLX9VsUm+gmYDRrar7D4dhLziDJHN0/oRWy4GYoWyfx+JMmTL5I8jHd3QDyHvBdNb\n\tRZSDKMILtMP9hWCDAhaE7crKSJFCg81Fo/yGd/QY=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Fri,  8 Feb 2019 16:45:39 +0200",
        "Message-Id": "<20190208144540.15529-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.19.2",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 1/2] libcamera: log: Allow extending log\n\tmessages",
        "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": "Fri, 08 Feb 2019 14:45:45 -0000"
    },
    "content": "Introduce a base Loggable class that can be inherited from by other\nclasses to support adding per-instance information to the log messages.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/log.h |  23 ++++++-\n src/libcamera/log.cpp       | 124 ++++++++++++++++++++++++++++++++++++\n 2 files changed, 145 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/libcamera/include/log.h b/src/libcamera/include/log.h\nindex ad8f8452c333..8ea5a1eb673a 100644\n--- a/src/libcamera/include/log.h\n+++ b/src/libcamera/include/log.h\n@@ -54,6 +54,7 @@ public:\n \tLogMessage(const char *fileName, unsigned int line,\n \t\t   const LogCategory &category, LogSeverity severity);\n \tLogMessage(const LogMessage &) = delete;\n+\tLogMessage(LogMessage &&);\n \t~LogMessage();\n \n \tstd::ostream &stream() { return msgStream_; }\n@@ -66,13 +67,31 @@ private:\n \tLogSeverity severity_;\n };\n \n+class Loggable\n+{\n+public:\n+\tvirtual ~Loggable();\n+\n+protected:\n+\tvirtual std::string logPrefix() const = 0;\n+\n+\tLogMessage _log(const char *file, unsigned int line,\n+\t\t\tLogSeverity severity);\n+\tLogMessage _log(const char *file, unsigned int line,\n+\t\t\tconst LogCategory &category, LogSeverity severity);\n+};\n+\n+LogMessage _log(const char *file, unsigned int line, LogSeverity severity);\n+LogMessage _log(const char *file, unsigned int line,\n+\t\tconst LogCategory &category, LogSeverity severity);\n+\n #ifndef __DOXYGEN__\n #define _LOG_CATEGORY(name) logCategory##name\n \n #define _LOG1(severity) \\\n-\tLogMessage(__FILE__, __LINE__, Log##severity).stream()\n+\t_log(__FILE__, __LINE__, Log##severity).stream()\n #define _LOG2(category, severity) \\\n-\tLogMessage(__FILE__, __LINE__, _LOG_CATEGORY(category)(), Log##severity).stream()\n+\t_log(__FILE__, __LINE__, _LOG_CATEGORY(category)(), Log##severity).stream()\n \n /*\n  * Expand the LOG() macro to _LOG1() or _LOG2() based on the number of\ndiff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\nindex edeb5eabb264..26ebf410a7a9 100644\n--- a/src/libcamera/log.cpp\n+++ b/src/libcamera/log.cpp\n@@ -405,6 +405,25 @@ LogMessage::LogMessage(const char *fileName, unsigned int line,\n \tinit(fileName, line);\n }\n \n+/**\n+ * \\brief Move-construct a log message\n+ * \\param[in] other The other message\n+ *\n+ * The move constructor is meant to support the _log() functions. Thanks to copy\n+ * elision it will likely never be called, but C++11 only permits copy elision,\n+ * it doesn't enforce it unlike C++17. To avoid potential link errors depending\n+ * on the compiler type and version, and optimization level, the move\n+ * constructor is defined even if it will likely never be called, and ensures\n+ * that the destructor of the \\a other message will not output anything to the\n+ * log by setting the severity to -1.\n+ */\n+LogMessage::LogMessage(LogMessage &&other)\n+\t: msgStream_(std::move(other.msgStream_)), category_(other.category_),\n+\t  severity_(other.severity_)\n+{\n+\tother.severity_ = static_cast<LogSeverity>(-1);\n+}\n+\n void LogMessage::init(const char *fileName, unsigned int line)\n {\n \t/* Log the timestamp, severity and file information. */\n@@ -424,6 +443,10 @@ void LogMessage::init(const char *fileName, unsigned int line)\n \n LogMessage::~LogMessage()\n {\n+\t/* Don't print anything if we have been moved to another LogMessage. */\n+\tif (severity_ == -1)\n+\t\treturn;\n+\n \tmsgStream_ << std::endl;\n \n \tif (severity_ >= category_.severity()) {\n@@ -445,6 +468,107 @@ LogMessage::~LogMessage()\n  * \\return A reference to the log message stream\n  */\n \n+/**\n+ * \\class Loggable\n+ * \\brief Base class to support log message extensions\n+ *\n+ * The Loggable class allows classes to extend log messages without any change\n+ * to the way the LOG() macro is invoked. By inheriting from Loggable and\n+ * implementing the logPrefix() virtual method, a class can specify extra\n+ * information to be automatically added to messages logged from class member\n+ * methods.\n+ */\n+\n+Loggable::~Loggable()\n+{\n+}\n+\n+/**\n+ * \\fn Loggable::logPrefix()\n+ * \\brief Retrieve a string to be prefixed to the log message\n+ *\n+ * This method allows classes inheriting from the Loggable class to extend the\n+ * logger with an object-specific prefix output right before the log message\n+ * contents.\n+ *\n+ * \\return A string to be prefixed to the log message\n+ */\n+\n+/**\n+ * \\brief Create a temporary LogMessage object to log a message\n+ * \\param[in] fileName The file name where the message is logged from\n+ * \\param[in] line The line number where the message is logged from\n+ * \\param[in] severity The log message severity\n+ *\n+ * This method is used as a backeng by the LOG() macro to create a log message\n+ * for locations inheriting from the Loggable class.\n+ *\n+ * \\return A log message\n+ */\n+LogMessage Loggable::_log(const char *fileName, unsigned int line,\n+\t\t\t  LogSeverity severity)\n+{\n+\tLogMessage msg(fileName, line, severity);\n+\n+\tmsg.stream() << logPrefix() << \": \";\n+\treturn msg;\n+}\n+\n+/**\n+ * \\brief Create a temporary LogMessage object to log a message\n+ * \\param[in] fileName The file name where the message is logged from\n+ * \\param[in] line The line number where the message is logged from\n+ * \\param[in] category The log message category\n+ * \\param[in] severity The log message severity\n+ *\n+ * This method is used as a backeng by the LOG() macro to create a log message\n+ * for locations inheriting from the Loggable class.\n+ *\n+ * \\return A log message\n+ */\n+LogMessage Loggable::_log(const char *fileName, unsigned int line,\n+\t\t\t  const LogCategory &category, LogSeverity severity)\n+{\n+\tLogMessage msg(fileName, line, category, severity);\n+\n+\tmsg.stream() << logPrefix() << \": \";\n+\treturn msg;\n+}\n+\n+/**\n+ * \\brief Create a temporary LogMessage object to log a message\n+ * \\param[in] fileName The file name where the message is logged from\n+ * \\param[in] line The line number where the message is logged from\n+ * \\param[in] severity The log message severity\n+ *\n+ * This function is used as a backeng by the LOG() macro to create a log\n+ * message for locations not inheriting from the Loggable class.\n+ *\n+ * \\return A log message\n+ */\n+LogMessage _log(const char *fileName, unsigned int line, LogSeverity severity)\n+{\n+\treturn LogMessage(fileName, line, severity);\n+}\n+\n+/**\n+ * \\brief Create a temporary LogMessage object to log a message\n+ * \\param[in] fileName The file name where the message is logged from\n+ * \\param[in] line The line number where the message is logged from\n+ * \\param[in] category The log message category\n+ * \\param[in] severity The log message severity\n+ *\n+ * This function is used as a backeng by the LOG() macro to create a log\n+ * message for locations not inheriting from the Loggable class.\n+ *\n+ * \\return A log message\n+ */\n+LogMessage _log(const char *fileName, unsigned int line,\n+\t\tconst LogCategory &category, LogSeverity severity)\n+{\n+\treturn LogMessage(fileName, line, category, severity);\n+}\n+\n /**\n  * \\def LOG_DECLARE_CATEGORY(name)\n  * \\hideinitializer\n",
    "prefixes": [
        "libcamera-devel",
        "1/2"
    ]
}