[libcamera-devel,3/5] libcamera: base: log: Log to std::cerr if log file can't be opened
diff mbox series

Message ID 20220525222503.6460-4-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • libcamera: Add colors to the log
Related show

Commit Message

Laurent Pinchart May 25, 2022, 10:25 p.m. UTC
If the log file specified through LIBCAMERA_LOG_FILE can't be opened,
logging is currently completely disabled. This doesn't match the
documented behaviour that tells std::cerr is used instead. Fix it to
match the documentation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/base/log.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Umang Jain May 29, 2022, 11:32 a.m. UTC | #1
Hello,

Thank you for the patch.

On 5/26/22 00:25, Laurent Pinchart via libcamera-devel wrote:
> If the log file specified through LIBCAMERA_LOG_FILE can't be opened,
> logging is currently completely disabled. This doesn't match the
> documented behaviour that tells std::cerr is used instead. Fix it to
> match the documentation.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>


Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>

> ---
>   src/libcamera/base/log.cpp | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 9ae62368a54d..26f1420703b9 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -517,6 +517,8 @@ void Logger::logSetLevel(const char *category, const char *level)
>    */
>   Logger::Logger()
>   {
> +	logSetStream(&std::cerr);
> +
>   	parseLogFile();
>   	parseLogLevels();
>   }
> @@ -533,10 +535,8 @@ Logger::Logger()
>   void Logger::parseLogFile()
>   {
>   	const char *file = utils::secure_getenv("LIBCAMERA_LOG_FILE");
> -	if (!file) {
> -		logSetStream(&std::cerr);
> +	if (!file)
>   		return;
> -	}
>   
>   	if (!strcmp(file, "syslog")) {
>   		logSetTarget(LoggingTargetSyslog);
Nicolas Dufresne via libcamera-devel May 31, 2022, 3:29 a.m. UTC | #2
Hi Laurent,

On Thu, May 26, 2022 at 01:25:01AM +0300, Laurent Pinchart via libcamera-devel wrote:
> If the log file specified through LIBCAMERA_LOG_FILE can't be opened,
> logging is currently completely disabled. This doesn't match the
> documented behaviour that tells std::cerr is used instead. Fix it to
> match the documentation.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/libcamera/base/log.cpp | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 9ae62368a54d..26f1420703b9 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -517,6 +517,8 @@ void Logger::logSetLevel(const char *category, const char *level)
>   */
>  Logger::Logger()
>  {
> +	logSetStream(&std::cerr);
> +
>  	parseLogFile();
>  	parseLogLevels();
>  }
> @@ -533,10 +535,8 @@ Logger::Logger()
>  void Logger::parseLogFile()
>  {
>  	const char *file = utils::secure_getenv("LIBCAMERA_LOG_FILE");
> -	if (!file) {
> -		logSetStream(&std::cerr);
> +	if (!file)
>  		return;
> -	}
>  
>  	if (!strcmp(file, "syslog")) {
>  		logSetTarget(LoggingTargetSyslog);

Patch
diff mbox series

diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
index 9ae62368a54d..26f1420703b9 100644
--- a/src/libcamera/base/log.cpp
+++ b/src/libcamera/base/log.cpp
@@ -517,6 +517,8 @@  void Logger::logSetLevel(const char *category, const char *level)
  */
 Logger::Logger()
 {
+	logSetStream(&std::cerr);
+
 	parseLogFile();
 	parseLogLevels();
 }
@@ -533,10 +535,8 @@  Logger::Logger()
 void Logger::parseLogFile()
 {
 	const char *file = utils::secure_getenv("LIBCAMERA_LOG_FILE");
-	if (!file) {
-		logSetStream(&std::cerr);
+	if (!file)
 		return;
-	}
 
 	if (!strcmp(file, "syslog")) {
 		logSetTarget(LoggingTargetSyslog);