[libcamera-devel] [PATCH 0/5] libcamera: Add colors to the log

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu May 26 00:24:58 CEST 2022


Hello,

This patch series addresses a shortcoming of libcamera compared to
GStreamer or PipeWire, namely colored logs.

This was attempted by Marco Felsch in "[PATCH] libcamera: log: add
colors to log levels" but suffered from coloring message
unconditionally for streams, regardless of whether the stream was backed
by a TTY, a file or something else.

This turned out impossible to solve automatically (as far as I can tell)
as the C++ stream API doesn't expose the underlying file descriptor.
I've thus taken another approach, by exposing coloring through the
libcamera logger API and only enabling it automatically when logging to
std::cerr. This can be disabled with the new LIBCAMERA_LOG_NO_COLOR
environment variable.

Laurent Pinchart (5):
  libcamera: base: log: Remove unnecessary local variable
  libcamera: base: log: Replace stderr with std::cerr in documentation
  libcamera: base: log: Log to std::cerr if log file can't be opened
  libcamera: base: log: Add coloring to the log output
  libcamera: base: log: Color the log prefix

 Documentation/environment_variables.rst |  21 ++-
 include/libcamera/base/log.h            |   5 +-
 include/libcamera/logging.h             |   4 +-
 src/libcamera/base/log.cpp              | 168 +++++++++++++++++-------
 src/libcamera/camera_manager.cpp        |   2 +-
 5 files changed, 144 insertions(+), 56 deletions(-)


base-commit: 3e7f54a3128d8143afb200d626d3b208d493623a
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list