From patchwork Mon Oct 14 08:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harvey Yang X-Patchwork-Id: 21611 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 BD0F8C32F4 for ; Mon, 14 Oct 2024 08:17:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4598E65381; Mon, 14 Oct 2024 10:17:53 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="AB1Ac9aY"; dkim-atps=neutral Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F9BF65369 for ; Mon, 14 Oct 2024 10:17:47 +0200 (CEST) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-20cd76c513cso7498225ad.3 for ; Mon, 14 Oct 2024 01:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728893866; x=1729498666; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BEoLH5qkWhGczJGaMIosPtFECkIOlbkqBdYQmdDgFGg=; b=AB1Ac9aYC/qOl4G0Ylgxrx7ULS1liXcjF5EuIb9kg3MyNYrsp/QVUoVsrac37J+aG4 TgvuCcqEZZJRhbFsZZG5ew09OEuw7z7j2YzK/yfe6rK5+wyHIkH2qXRaO5tJ4XsOJLsM fb8eXOs3WzU0rEEuDzyzKuX7R6VnYrdOdsXDw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728893866; x=1729498666; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BEoLH5qkWhGczJGaMIosPtFECkIOlbkqBdYQmdDgFGg=; b=F9gQSCs9iH139p1ddteaCZqWBqCiaPbROXnPNXBKsvq1nRmrFkwmrecn20IOFJQENO bPrD17asi3LyBLAxDNtmaKif7VSEe+kr9+3VGVTePkLHEnRSVB6S1e0TjkdEje3dADp+ ssB7JqdiYhMWKrBJOSTPOlMgOC4EY+O7K7mRaPUfd5WIeDN1ZD0949pc985IOv91uSwr /Iyj1A21kogJQFOqPQ3y9gIkozQDTApEhhqXQm4wFxH7zGyUPlo3WPExndFllKyrPB0K +6Rtih4+Gd9+OeiPxdRFtlM/2EfUpKUfUDGuViF0asY5wWa4azTqt0byxYZoKi0N3xWv e9Kw== X-Gm-Message-State: AOJu0Yx/RfzPa+TSZqWQRWgxMu7SpifRZTWEyCLenHLGxD4BszJQ9TgV /qEuGIoRBZGSEMufBZ1Dg0ScholbQZLKJg9kSdPqhrlgZ9m3kLmem7EoU64XZKGrew03dHxzVSs = X-Google-Smtp-Source: AGHT+IGvhw4RZ7TEyfcOYAGpHnvC7CbuIXnEjTe/yQHhLOQfh6MktrVUablF2tg0BIbFlq7B+16c7Q== X-Received: by 2002:a17:902:ea11:b0:20c:da98:d752 with SMTP id d9443c01a7336-20cda98da15mr58335505ad.16.1728893865988; Mon, 14 Oct 2024 01:17:45 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (199.211.81.34.bc.googleusercontent.com. [34.81.211.199]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8c21da63sm61077735ad.235.2024.10.14.01.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2024 01:17:45 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Han-Lin Chen , Harvey Yang Subject: [PATCH 2/2] libcamera: log: add logTargetCros for ChromeOS logs Date: Mon, 14 Oct 2024 08:13:55 +0000 Message-ID: <20241014081738.772258-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog In-Reply-To: <20241014081738.772258-1-chenghaoyang@chromium.org> References: <20241014081738.772258-1-chenghaoyang@chromium.org> MIME-Version: 1.0 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" From: Han-Lin Chen ChromeOS logging requires that the logs export to both syslog and std::cerr. Add a logTargetCros for the specific case. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- include/libcamera/logging.h | 1 + src/libcamera/base/log.cpp | 61 +++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/include/libcamera/logging.h b/include/libcamera/logging.h index e1c6341ce..b88acf23b 100644 --- a/include/libcamera/logging.h +++ b/include/libcamera/logging.h @@ -16,6 +16,7 @@ enum LoggingTarget { LoggingTargetSyslog, LoggingTargetFile, LoggingTargetStream, + LoggingTargetCros, }; int logSetFile(const char *path, bool color = false); diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp index 3a656b8f0..930e2329e 100644 --- a/src/libcamera/base/log.cpp +++ b/src/libcamera/base/log.cpp @@ -107,6 +107,7 @@ class LogOutput public: LogOutput(const char *path, bool color); LogOutput(std::ostream *stream, bool color); + LogOutput(bool color); LogOutput(); ~LogOutput(); @@ -144,6 +145,19 @@ LogOutput::LogOutput(std::ostream *stream, bool color) { } +/** + * \brief Construct a log output to both std:err and syslog + * \param[in] color True to output colored messages + * + * Currently this is only needed for CrOS. Therefore, the target is set to + * `LoggingTargetCros`. + */ +LogOutput::LogOutput(bool color) + : stream_(&std::cerr), target_(LoggingTargetCros), color_(color) +{ + openlog("libcamera", LOG_PID, 0); +} + /** * \brief Construct a log output to syslog */ @@ -160,6 +174,7 @@ LogOutput::~LogOutput() delete stream_; break; case LoggingTargetSyslog: + case LoggingTargetCros: closelog(); break; default: @@ -230,17 +245,26 @@ void LogOutput::write(const LogMessage &msg) severityColor = kColorBrightWhite; } + bool toStream = false; + bool toSyslog = false; + switch (target_) { case LoggingTargetSyslog: - str = std::string(log_severity_name(severity)) + " " - + msg.category().name() + " " + msg.fileInfo() + " "; - if (!msg.prefix().empty()) - str += msg.prefix() + ": "; - str += msg.msg(); - writeSyslog(severity, str); + toSyslog = true; break; case LoggingTargetStream: case LoggingTargetFile: + toStream = true; + break; + case LoggingTargetCros: + toSyslog = true; + toStream = true; + break; + default: + break; + } + + if (toStream) { str = "[" + utils::time_point_to_string(msg.timestamp()) + "] [" + std::to_string(Thread::currentId()) + "] " + severityColor + log_severity_name(severity) + " " @@ -250,9 +274,15 @@ void LogOutput::write(const LogMessage &msg) str += prefixColor + msg.prefix() + ": "; str += resetColor + msg.msg(); writeStream(str); - break; - default: - break; + } + + if (toSyslog) { + str = std::string(log_severity_name(severity)) + " " + + msg.category().name() + " " + msg.fileInfo() + " "; + if (!msg.prefix().empty()) + str += msg.prefix() + ": "; + str += msg.msg(); + writeSyslog(severity, str); } } @@ -270,6 +300,10 @@ void LogOutput::write(const std::string &str) case LoggingTargetFile: writeStream(str); break; + case LoggingTargetCros: + writeSyslog(LogDebug, str); + writeStream(str); + break; default: break; } @@ -549,6 +583,9 @@ int Logger::logSetTarget(enum LoggingTarget target) case LoggingTargetNone: std::atomic_store(&output_, std::shared_ptr()); break; + case LoggingTargetCros: + std::atomic_store(&output_, std::make_shared(true)); + break; default: return -EINVAL; } @@ -586,6 +623,12 @@ void Logger::logSetLevel(const char *category, const char *level) */ Logger::Logger() { +#if defined(OS_CHROMEOS) + logSetTarget(LoggingTargetCros); + parseLogLevels(); + return; +#endif + bool color = !utils::secure_getenv("LIBCAMERA_LOG_NO_COLOR"); logSetStream(&std::cerr, color);