eclipse-kuksa / kuksa-python-sdk

The Python SDK for Eclipse KUKSA
Apache License 2.0
3 stars 5 forks source link

Improvement: Usage of logger instead of print #25

Closed sboett-dev closed 2 months ago

sboett-dev commented 2 months ago

This Python package includes several print statements, e.g. here. It is not possible to set the logging level.

It would be nice to be able to set the usual logging levels: critical, error, warning, info, debug.

Example

During implementations with multiple connects and disconnects, the console gets spammed with

gRPC channel disconnected.
gRPC channel connected.
gRPC channel disconnected.
gRPC channel connected.
gRPC channel disconnected.
gRPC channel connected.

Thanks!

SebastianSchildt commented 2 months ago

Good point. We will come around to this eventually. Meanwhile of course, PRs welcome. I assume, the standard logging module (https://docs.python.org/3/library/logging.html) would be the preferred solution

erikbosch commented 2 months ago

We already use logging in some downstream projects like

https://github.com/eclipse-kuksa/kuksa-can-provider/blob/main/dbcfeeder.py https://github.com/eclipse-kuksa/kuksa-dds-provider/blob/main/ddsprovider.py

Also in the "library parts" of the package we often already use logging.

https://github.com/eclipse-kuksa/kuksa-python-sdk/blob/main/kuksa-client/kuksa_client/grpc/__init__.py

So I think it is mostly the CLI-parts that use print, but it would indeed be good to integrate the logging framework there as well. One could discuss if we should add logging formatting to this repo, so that for example we can remove ColorFormatter from https://github.com/eclipse-kuksa/kuksa-can-provider/blob/main/dbcfeeder.py#L101 and instead have it as a KuksaDefaultFormatter that all providers and the CLI could use.

erikbosch commented 2 months ago

I will make an attempt on fixing this one