From patchwork Tue Mar 26 11:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 19806 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 65AB2BD160 for ; Tue, 26 Mar 2024 11:26:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 186DB63361; Tue, 26 Mar 2024 12:26:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="cCmuAYZ2"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC7A36333E for ; Tue, 26 Mar 2024 12:26:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711452380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wPiQFiIlDaGgBq0SquSq1dWwBimKRK9z13gS7ic6Tn4=; b=cCmuAYZ2t7L6Q8xho3G8THgU+xPjWKIXQxXCddU3oricdE/2Y6WYkqBu5PzvRRa0V0bPL0 1kQ4fK4Mi42UOY5QUwaT0jGFSKXgCCigzgQZkRTnzcBVLB+ZSDSK7fq7ehiNWOx/+U6f5w YVUihPzb41PArZM1sKwNI6h64qmG+fs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-386-S4bfWoVfPVmddN7sH1rbYQ-1; Tue, 26 Mar 2024 07:26:19 -0400 X-MC-Unique: S4bfWoVfPVmddN7sH1rbYQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1A6B9800264 for ; Tue, 26 Mar 2024 11:26:19 +0000 (UTC) Received: from nuthatch.brq.redhat.com (unknown [10.43.17.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AAA43C20; Tue, 26 Mar 2024 11:26:18 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH 06/11] config: Look up log color configuration in configuration file Date: Tue, 26 Mar 2024 12:24:09 +0100 Message-ID: <20240326112419.503286-7-mzamazal@redhat.com> In-Reply-To: <20240326112419.503286-1-mzamazal@redhat.com> References: <20240326112419.503286-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The configuration snippet: configuration: log: color: BOOL In order to use the global configuration access helper for a boolean value, we must make a template from it. To make the template visible, we must implement it in the header file, otherwise undefined reference error would be reported when linking. We don't implement envOption helper for boolean here, because we would have to deal with a specific value interpretation in this particular case. Signed-off-by: Milan Zamazal --- .../libcamera/internal/global_configuration.h | 17 ++++++++++++++++- src/libcamera/base/global_configuration.cpp | 17 +---------------- src/libcamera/base/log.cpp | 2 ++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/libcamera/internal/global_configuration.h b/include/libcamera/internal/global_configuration.h index 41ac57cf..67684762 100644 --- a/include/libcamera/internal/global_configuration.h +++ b/include/libcamera/internal/global_configuration.h @@ -13,6 +13,8 @@ #include "libcamera/internal/yaml_parser.h" +#include "libcamera/base/utils.h" + namespace libcamera { class GlobalConfiguration @@ -28,7 +30,20 @@ public: static unsigned int version(); static Configuration configuration(); - static std::optional option(const char *const confPath); + + /** + * \brief Retrieve string configuration identified by the given string + * ... + */ + template + static std::optional option(const char *const confPath) + { + YamlObject *c = &const_cast(configuration()); + for (auto part : utils::details::StringSplitter(confPath, ".")) + c = &const_cast((*c)[part]); + return c->get(); + } + static std::optional envOption(const char *const envVariable, const char *const confPath); diff --git a/src/libcamera/base/global_configuration.cpp b/src/libcamera/base/global_configuration.cpp index b29f452b..1e7a4caa 100644 --- a/src/libcamera/base/global_configuration.cpp +++ b/src/libcamera/base/global_configuration.cpp @@ -18,8 +18,6 @@ #include "libcamera/internal/yaml_parser.h" -#include "libcamera/base/utils.h" - namespace libcamera { LOG_DEFINE_CATEGORY(Configuration) @@ -119,19 +117,6 @@ GlobalConfiguration::Configuration GlobalConfiguration::get() return (*instance().configuration_); } -/** - * \brief Retrieve string configuration identified by the given string - * ... - */ -std::optional GlobalConfiguration::option( - const char *const confPath) -{ - YamlObject *c = &const_cast(configuration()); - for (auto part : utils::details::StringSplitter(confPath, ".")) - c = &const_cast((*c)[part]); - return c->get(); -} - /** * \brief Retrieve string configuration from the given environment variable or configuration * ... @@ -143,7 +128,7 @@ std::optional GlobalConfiguration::envOption( const char *envValue = utils::secure_getenv(envVariable); if (envValue) return std::optional{ std::string{ envValue } }; - return option(confPath); + return option(confPath); } /** diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index a373d38b..19403378 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -590,6 +590,8 @@ void Logger::logSetLevel(const char *category, const char *level) Logger::Logger() { bool color = !utils::secure_getenv("LIBCAMERA_LOG_NO_COLOR"); + if (color) + color = GlobalConfiguration::option("log.color").value_or(true); logSetStream(&std::cerr, color); parseLogFile();