raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
842 stars 179 forks source link

disable logging when taking picture #1074

Open LeifSec opened 1 month ago

LeifSec commented 1 month ago

Following issue I want to switch off logging / set logging level to ERROR for calling a function

camera.switch_mode_and_capture_image(
                camera_config=self.__settings.still_configuration,
                name="main",
                wait=None,
                signal_function=None)

. So I did:

if "picamera2" not in logging.Logger.manager.loggerDict.keys():
            raise ValueError("not in tt")
logger = logging.getLogger("picamera2")
logger.setLevel(logging.ERROR)
camera.switch_mode_and_capture_image(....
logger.setLevel(old_level)

Unfortunately there is still this INFO level logging:

163:48:59.073898409] [27530]  INFO Camera camera.cpp:1183 configuring streams: (0) 1536x864-BGR888 (1) 4608x2592-SBGGR10_CSI2P
[163:48:59.097958056] [27500]  INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 4608x2592-SBGGR10_1X10 - Selected unicam format: 4608x2592-pBAA
[163:48:59.516137626] [27530]  INFO Camera camera.cpp:1183 configuring streams: (0) 1536x864-XBGR8888 (1) 2304x1296-SBGGR10_CSI2P
[163:48:59.525447463] [27500]  INFO RPI vc4.cpp:621 Sensor: /base/soc/i2c0mux/i2c@1/imx708@1a - Selected sensor format: 2304x1296-SBGGR10_1X10 - Selected unicam format: 2304x1296-pBAA

I am using imx708 camera and latest Raspberian 12 software.

davidplowman commented 1 month ago

Yes, this is all libcamera logging and it can be quite chatty. It might be easiest just to put something like export LIBCAMERA_LOG_LEVELS=*:3 in your .bashrc...

LeifSec commented 1 month ago

export LIBCAMERA_LOG_LEVELS=*:3works - thank you very much. But as I need it in the code (to disable it just for that call of switch_mode_and_capture_image ) I need something like:

os.environ["LIBCAMERA_LOG_LEVELS"] = "*:3"
camera.switch_mode_and_capture_image(...`
os.environ["LIBCAMERA_LOG_LEVELS"] = "*:old_level"

But this does not work.

davidplowman commented 1 month ago

Yes, libcamera probably only reads that environment variable when it starts up. So far as I know, there's no Python interface to libcamera's logging system after that. So I don't really have a workaround for you there. Can you say which of the logging messages are actually useful? I'm wondering whether you can turning them all off, and add your own logging for your application.

LeifSec commented 1 month ago

Maybe also INFO Camera camera.cpp:1183 configuring streams: ( ... is usefull in some cases.

But I am taking pictures for two reasons

For both I want to get error messages. For the main application maybe also info messages are usefull. But for the live stream they info messages are spamming my log.

davidplowman commented 1 month ago

Unfortunately, so far as I know, there's no way to adjust the logging at runtime. But note that by choosing the logging level appropriately, you can still get warnings and errors. When it comes to configuring streams, you can easily print out the details of the configuration you got, for the purpose of double-checking what's going on.