brightway-lca / brightway2-data

Tools for the management of inventory databases and impact assessment methods. Part of the Brightway LCA framework.
https://docs.brightway.dev/
BSD 3-Clause "New" or "Revised" License
10 stars 24 forks source link

Improve logging #189

Open graham2071 opened 1 month ago

graham2071 commented 1 month ago

Hello, I am using bw2data, bw2io and bw2calc. Those packages use print function for logs, which is a bad practice. Logging is not configurable, no levels, etc.

A first option is to use python logging module.

Better option includes to use structured logging such as structlog. This would allow to enable observability for those who need it.

cmutel commented 1 month ago

Hi @graham2071! Thanks for your comment, you are totally right that we need to improve our logging framework. In fact, we do use logging across all our libraries, but recognize that this needs to be improved, and have already had several technical discussions on what direction we should go towards.

We are a bit reluctant to force all logs to force the use of structlog (other Brightway users prefer unstructured logs), but having it as a default and making it easy to use and well communicated on what we do and how to switch to another framework is absolutely needed. Would you be interested in contributing?

Please let me know where we are using print where a log statement would be more appropriate, I will check it out 😄

graham2071 commented 1 month ago

I first noticed the prints in bw2io.bw2setup, then a search in the repos shows other uses:

bw2data: https://github.com/search?q=repo%3Abrightway-lca%2Fbrightway2-data%20print(&type=code bw2io: https://github.com/search?q=repo%3Abrightway-lca%2Fbrightway2-io%20print(&type=code

I wish I could contribute but quite available right now.

I understand that some users may prefer unstructured logs (though structlog console outputs are really nice). It should be possible to use structlog to wrap logging calls in dedendencies, so using python logging module in brightway should be fine.