Show a patch.

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

{
    "id": 314,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/314/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/314/",
    "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": "<20190121195606.8526-4-laurent.pinchart@ideasonboard.com>",
    "date": "2019-01-21T19:56:05",
    "name": "[libcamera-devel,v2,3/4] libcamera: log: Get log output file from the environment",
    "commit_ref": "457208178c818a571d77978b5204530ef2c18d51",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "a36d1576ff0d826c91d56b464d564f726246b1bd",
    "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/314/mbox/",
    "series": [
        {
            "id": 108,
            "url": "https://patchwork.libcamera.org/api/1.1/series/108/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=108",
            "date": "2019-01-21T19:56:02",
            "name": "Extend the logger with categories and configuration",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/108/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/314/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/314/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<laurent.pinchart@ideasonboard.com>",
        "Received": [
            "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 96D8C60C80\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jan 2019 20:56:12 +0100 (CET)",
            "from pendragon.bb.dnainternet.fi\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 363B0598\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Jan 2019 20:56:12 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1548100572;\n\tbh=ZBIQlpmFV6blC8Lxb42ENmxmm8zQx0Kl4Dg2Hl+zhrU=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=dLLVtAD+5LjPFZYBI9uogPHuP9a1UDHKNx5nLQxfWiQFHXPw8yGrHZdDR2Dp9vHoe\n\tck93rW61kcPORYW8If5TEk+BxKUmr85xwgJ4J1FS01fep9x5/uEud+XuIYp4sBBBMM\n\tal3juM64ZYX5QIrcc3zhFy2rQ3rZFnFoC7g/3vaw=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 21 Jan 2019 21:56:05 +0200",
        "Message-Id": "<20190121195606.8526-4-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.19.2",
        "In-Reply-To": "<20190121195606.8526-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20190121195606.8526-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 3/4] libcamera: log: Get log output\n\tfile from the environment",
        "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": "Mon, 21 Jan 2019 19:56:12 -0000"
    },
    "content": "If the LIBCAMERA_LOG_FILE environment variable is set, open the file it\npoints to and redirect the logger output to it.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/log.cpp | 47 +++++++++++++++++++++++++++++++++++++++++--\n 1 file changed, 45 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\nindex 23bb9edb9d14..241dc5395976 100644\n--- a/src/libcamera/log.cpp\n+++ b/src/libcamera/log.cpp\n@@ -8,7 +8,9 @@\n #include <cstdio>\n #include <cstdlib>\n #include <ctime>\n+#include <fstream>\n #include <iomanip>\n+#include <iostream>\n #include <list>\n #include <string.h>\n #include <unordered_set>\n@@ -37,6 +39,12 @@\n  * message with a level higher than or equal to the configured log level for\n  * their category are output to the log, while other messages are silently\n  * discarded.\n+ *\n+ * By default log messages are output to stderr. They can be redirected to a log\n+ * file by setting the LIBCAMERA_LOG_FILE environment variable to the name of\n+ * the file. The file must be writable and is truncated if it exists. If any\n+ * error occurs when opening the file, the file is ignored and the log is output\n+ * to stderr.\n  */\n \n namespace libcamera {\n@@ -51,9 +59,12 @@ class Logger\n public:\n \tstatic Logger *instance();\n \n+\tvoid write(const std::string &msg);\n+\n private:\n \tLogger();\n \n+\tvoid parseLogFile();\n \tvoid parseLogLevels();\n \tstatic LogSeverity parseLogLevel(const std::string &level);\n \n@@ -63,6 +74,9 @@ private:\n \n \tstd::unordered_set<LogCategory *> categories_;\n \tstd::list<std::pair<std::string, LogSeverity>> levels_;\n+\n+\tstd::ofstream file_;\n+\tstd::ostream *output_;\n };\n \n /**\n@@ -79,14 +93,44 @@ Logger *Logger::instance()\n \treturn &instance;\n }\n \n+/**\n+ * \\brief Write a message to the configured logger output\n+ * \\param[in] msg The message string\n+ */\n+void Logger::write(const std::string &msg)\n+{\n+\toutput_->write(msg.c_str(), msg.size());\n+\toutput_->flush();\n+}\n+\n /**\n  * \\brief Construct a logger\n  */\n Logger::Logger()\n+\t: output_(&std::cerr)\n {\n+\tparseLogFile();\n \tparseLogLevels();\n }\n \n+/**\n+ * \\brief Parse the log output file from the environment\n+ *\n+ * If the LIBCAMERA_LOG_FILE environment variable is set, open the file it\n+ * points to and redirect the logger output to it. Errors are silently ignored\n+ * and don't affect the logger output (set to stderr).\n+ */\n+void Logger::parseLogFile()\n+{\n+\tconst char *file = secure_getenv(\"LIBCAMERA_LOG_FILE\");\n+\tif (!file)\n+\t\treturn;\n+\n+\tfile_.open(file);\n+\tif (file_.good())\n+\t\toutput_ = &file_;\n+}\n+\n /**\n  * \\brief Parse the log levels from the environment\n  *\n@@ -384,8 +428,7 @@ LogMessage::~LogMessage()\n \n \tif (severity_ >= category_.severity()) {\n \t\tstd::string msg(msgStream_.str());\n-\t\tfwrite(msg.data(), msg.size(), 1, stderr);\n-\t\tfflush(stderr);\n+\t\tLogger::instance()->write(msg);\n \t}\n \n \tif (severity_ == LogSeverity::LogFatal)\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "3/4"
    ]
}