{"id":1657,"url":"https://patchwork.libcamera.org/api/patches/1657/?format=json","web_url":"https://patchwork.libcamera.org/patch/1657/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190711180525.31519-1-paul.elder@ideasonboard.com>","date":"2019-07-11T18:05:24","name":"[libcamera-devel,v3,1/2] libcamera: logging: add logging API for applications","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"5b7fc39b9cf01ead7359e013657916e6088c396d","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1657/mbox/","series":[{"id":419,"url":"https://patchwork.libcamera.org/api/series/419/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=419","date":"2019-07-11T18:05:24","name":"[libcamera-devel,v3,1/2] libcamera: logging: add logging API for applications","version":3,"mbox":"https://patchwork.libcamera.org/series/419/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1657/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1657/checks/","tags":{},"headers":{"Return-Path":"<paul.elder@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 81E2460BC8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 11 Jul 2019 20:05:34 +0200 (CEST)","from neptunite.amanokami.net (softbank126163157105.bbtec.net\n\t[126.163.157.105])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DB1E531C;\n\tThu, 11 Jul 2019 20:05:32 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562868334;\n\tbh=5HolqAh0gr2mPPgiqgeiMNcPLeRa+FqMGTkJge5RmvM=;\n\th=From:To:Cc:Subject:Date:From;\n\tb=tL+f1WgHkzwkxPcQtv4bduDx3m3b3+JdwcRYJs8VJ20lFM/vh6/vbU2lbkLor+Av6\n\tCzLknjncx00Dh5bF6ey8GrUk7CtB5SyT0ieOKKMCashr08HJN+LsEH7HexW2Pmo+9v\n\tKZMP0swf/DlPXNcsRstGRHNqBvt1ubYe8eOWSQL4=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri, 12 Jul 2019 03:05:24 +0900","Message-Id":"<20190711180525.31519-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 v3 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 18:05:34 -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 v3:\n- make setLogFile revert to stderr on empty arg\n- make both setLogFile and setLogLevel ignore empty args (not check for\n  error)\n- better docs for setLogFile\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         | 60 +++++++++++++++++++++++++++++++++++\n 3 files changed, 78 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..c8a048e\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) 2019, Google Inc.\n+ *\n+ * logging.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..11bac80 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,63 @@ private:\n \tstd::ostream *output_;\n };\n \n+/**\n+ * \\brief Set the log file\n+ * \\param[in] file Log file\n+ *\n+ * This functions sets the logging output file to \\a file.\n+ * If \\a file is an empty string, then the output file will be set to stderr.\n+ */\n+void logSetFile(const char *file)\n+{\n+\tLogger *logger = Logger::instance();\n+\n+\tif (!file[0]) {\n+\t\tlogger->file_.close();\n+\t\tlogger->output_ = &std::cerr;\n+\t\treturn;\n+\t}\n+\n+\tstd::ofstream logFile(file);\n+\tif (!logFile.good())\n+\t\treturn;\n+\n+\tif (logger->output_ != &std::cerr)\n+\t\tlogger->file_.close();\n+\tlogger->file_ = std::move(logFile);\n+\tlogger->output_ = &logger->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 shall 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+\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","v3","1/2"]}