loguru icon indicating copy to clipboard operation
loguru copied to clipboard

How to suppress logs from imported C dynamic libraries

Open hlacikd opened this issue 2 years ago • 1 comments

I am using third party library from rknnlite.api import RKNNLite that logs a lot to stdout stderr

[detector] W RKNN: [08:11:27.819] Output(output_0): size_with_stride larger than model origin size, if need run OutputOperator in NPU, please call rknn_create_memory using size_with_stride.
[detector] W RKNN: [08:11:27.880] Output(output_0): size_with_stride larger than model origin size, if need run OutputOperator in NPU, please call rknn_create_memory using size_with_stride.

I need to be able to suppress these logs and have only mine loguru logs created in my script.

How can i do either

  1. redirect these logs from third-party library to loguru-logger
  2. suppress these logs

PS : there are some nasty tricks - https://stackoverflow.com/questions/5081657/how-do-i-prevent-a-c-shared-library-to-print-on-stdout-in-python/14797594#14797594 , trying to modify file descriptors, but this is not a way to go i suppose.

hlacikd avatar Sep 20 '23 08:09 hlacikd

It depends. If these logs are emitted though standard logging, you'll need to install a InterceptHandler. If they are wrote on sys.stderr directly, you'll need to use a wrapper.

Delgan avatar Sep 20 '23 18:09 Delgan