Skip to content

Commit

Permalink
core: Fix loss of libcamera logging
Browse files Browse the repository at this point in the history
If the LIBCAMERA_LOG_LEVELS env variable is set, it gets overridden by
rpicam-apps when initialising the camera manager. Fix this by not
touching the logging level if the LIBCAMERA_LOG_LEVELS env variable is
set.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed Nov 30, 2023
1 parent 4fc9aba commit b6ee440
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 4 additions & 2 deletions core/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ bool Options::Parse(int argc, char *argv[])
set_subdev_hdr_ctrl(0);
app_->initCameraManager();

bool log_env_set = getenv("LIBCAMERA_LOG_LEVELS");
// Unconditionally set the logging level to error for a bit.
libcamera::logSetLevel("*", "ERROR");
if (!log_env_set)
libcamera::logSetLevel("*", "ERROR");

std::vector<std::shared_ptr<libcamera::Camera>> cameras = app_->GetCameras();
if (camera < cameras.size())
Expand Down Expand Up @@ -342,7 +344,7 @@ bool Options::Parse(int argc, char *argv[])
}

// Reset log level to Info.
if (verbose)
if (verbose && !log_env_set)
libcamera::logSetLevel("*", "INFO");

// Set the verbosity
Expand Down
15 changes: 11 additions & 4 deletions core/rpicam_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,13 @@ void RPiCamApp::OpenCamera()
std::unique_ptr<CameraConfiguration> config = camera_->generateConfiguration({ libcamera::StreamRole::Raw });
const libcamera::StreamFormats &formats = config->at(0).formats();

bool log_env_set = getenv("LIBCAMERA_LOG_LEVELS");
// Suppress log messages when enumerating camera modes.
libcamera::logSetLevel("RPI", "ERROR");
libcamera::logSetLevel("Camera", "ERROR");
if (!log_env_set)
{
libcamera::logSetLevel("RPI", "ERROR");
libcamera::logSetLevel("Camera", "ERROR");
}

for (const auto &pix : formats.pixelformats())
{
Expand All @@ -242,8 +246,11 @@ void RPiCamApp::OpenCamera()
}
}

libcamera::logSetLevel("RPI", "INFO");
libcamera::logSetLevel("Camera", "INFO");
if (!log_env_set)
{
libcamera::logSetLevel("RPI", "INFO");
libcamera::logSetLevel("Camera", "INFO");
}
}

void RPiCamApp::CloseCamera()
Expand Down

0 comments on commit b6ee440

Please sign in to comment.