{"id":1653,"url":"https://patchwork.libcamera.org/api/1.1/patches/1653/?format=json","web_url":"https://patchwork.libcamera.org/patch/1653/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190711102418.29661-1-paul.elder@ideasonboard.com>","date":"2019-07-11T10:24:17","name":"[libcamera-devel,v2,1/2] libcamera: logging: add logging API for applications","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3166beb08bb484d5927509a5036df3a0bf41715f","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1653/mbox/","series":[{"id":417,"url":"https://patchwork.libcamera.org/api/1.1/series/417/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=417","date":"2019-07-11T10:24:17","name":"[libcamera-devel,v2,1/2] libcamera: logging: add logging API for applications","version":2,"mbox":"https://patchwork.libcamera.org/series/417/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1653/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1653/checks/","tags":{},"headers":{"Return-Path":"<paul.elder@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 6AD4C60C3A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Jul 2019 12:24:29 +0200 (CEST)","from neptunite.amanokami.net (softbank126163157105.bbtec.net\n\t[126.163.157.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B147CCC;\n\tThu, 11 Jul 2019 12:24:27 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562840669;\n\tbh=5ptHZ/YjI1SlSrKlhA2PE/2eLeSICGlVS2i4vl4mA+U=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=KbrQSvj3xhc+qIkoVslSkaiSYguDr2AIdG2DvDSS3D1O6nEM9XpmYzWsO1XZw7VUB\n\t2Ck6eUKRP0c85/8syUpUAzxI6TqrvGxjoossus5RWvLse5UZUvc9YdYCerBY8ckY6z\n\tsMx7mXZaRATAGHb77MUGS1UdFkbAYwtAoLQwek98=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 11 Jul 2019 19:24:17 +0900","Message-Id":"<20190711102418.29661-1-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 1/2] libcamera: logging: add logging\n\tAPI for applications","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":"Thu, 11 Jul 2019 10:24:29 -0000"},"content":"Currently the log file and the log level can only be set via environment\nvariables, but applications may also want to set the log file and the\nlog level at run time. Provide an API for this.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nChanges in v2:\n- add documentation\n- actually set the log level\n\n include/libcamera/logging.h   | 17 +++++++++++\n include/libcamera/meson.build |  1 +\n src/libcamera/log.cpp         | 54 +++++++++++++++++++++++++++++++++++\n 3 files changed, 72 insertions(+)\n create mode 100644 include/libcamera/logging.h","diff":"diff --git a/include/libcamera/logging.h b/include/libcamera/logging.h\nnew file mode 100644\nindex 0000000..47c5e49\n--- /dev/null\n+++ b/include/libcamera/logging.h\n@@ -0,0 +1,17 @@\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_LOGGING_H__\n+#define __LIBCAMERA_LOGGING_H__\n+\n+namespace libcamera {\n+\n+void logSetFile(const char *file);\n+void logSetLevel(const char *category, const char *level);\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_LOGGING_H__ */\ndiff --git a/include/libcamera/meson.build b/include/libcamera/meson.build\nindex 972513f..920eb5f 100644\n--- a/include/libcamera/meson.build\n+++ b/include/libcamera/meson.build\n@@ -9,6 +9,7 @@ libcamera_api = files([\n     'geometry.h',\n     'ipa/ipa_interface.h',\n     'ipa/ipa_module_info.h',\n+    'logging.h',\n     'object.h',\n     'request.h',\n     'signal.h',\ndiff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\nindex 0ba276e..dca4936 100644\n--- a/src/libcamera/log.cpp\n+++ b/src/libcamera/log.cpp\n@@ -69,6 +69,9 @@ private:\n \tvoid parseLogLevels();\n \tstatic LogSeverity parseLogLevel(const std::string &level);\n \n+\tfriend void logSetFile(const char *file);\n+\tfriend void logSetLevel(const char *category, const char *level);\n+\n \tfriend LogCategory;\n \tvoid registerCategory(LogCategory *category);\n \tvoid unregisterCategory(LogCategory *category);\n@@ -80,6 +83,57 @@ private:\n \tstd::ostream *output_;\n };\n \n+/**\n+ * \\brief Set the log file\n+ * \\param[in] file\n+ */\n+void logSetFile(const char *file)\n+{\n+\tif (std::string(file).empty())\n+\t\treturn;\n+\n+\tLogger *logger = Logger::instance();\n+\tstd::ofstream &file_ = logger->file_;\n+\tfile_.close();\n+\tfile_.open(file);\n+\tif (file_.good())\n+\t\tlogger->output_ = &file_;\n+}\n+\n+/**\n+ * \\brief Set the log level\n+ * \\param[in] category Logging category\n+ * \\param[in] level Log level\n+ *\n+ * This function sets the log level of \\a category to \\a level.\n+ * \\a level should be one of the following strings:\n+ * - \"DEBUG\"\n+ * - \"INFO\"\n+ * - \"WARN\"\n+ * - \"ERROR\"\n+ * - \"FATAL\"\n+ *\n+ * \"*\" is not a valid \\a category for this function.\n+ */\n+void logSetLevel(const char *category, const char *level)\n+{\n+\tLogger *logger = Logger::instance();\n+\tstd::string cat(category);\n+\tstd::string lev(level);\n+\n+\t/* Both the category and the level must be specified. */\n+\tif (cat.empty() || lev.empty())\n+\t\treturn;\n+\n+\tLogSeverity severity = Logger::parseLogLevel(lev);\n+\tif (severity == LogInvalid)\n+\t\treturn;\n+\n+\tfor (LogCategory *c : logger->categories_)\n+\t\tif (!strcmp(c->name(), category))\n+\t\t\tc->setSeverity(severity);\n+}\n+\n /**\n  * \\brief Retrieve the logger instance\n  *\n","prefixes":["libcamera-devel","v2","1/2"]}