loguru
loguru copied to clipboard
How to suppress logs from imported C dynamic libraries
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
- redirect these logs from third-party library to loguru-logger
- 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.
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.