P1sec / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
GNU Lesser General Public License v2.1
381 stars 132 forks source link

move various print() to a proper logging mechanism #144

Open p1-bmu opened 3 years ago

p1-bmu commented 3 years ago

Various print() exists throughout pycrate, that should be moved to a proper logging mechanism, in order to not eventually pollute stdout. All logging should be done with the log() function in ./pycrate_core/utils.py, and this log function should do a proper logging instead of just a print. This should apply to all part of the library, except the pycrate_corenet part which has already a specific handling for logs, and the tools which have to print.

Places where explicit print() should be changed to log():

benmaddison commented 3 years ago

Various print() exists throughout pycrate, that should be moved to a proper logging mechanism, in order to not eventually pollute stdout. All logging should be done with the log() function in ./pycrate_core/utils.py, and this log function should do a proper logging instead of just a print.

It's more work, but better to call log(...) directly in the module where the event occurs.

The reason for this is with the boilerplate (in every module):

import logging

log = logging.getLogger(__name__)

Then the log object will have a name matching the name of the module, which makes it easy to see where in the library the message was generated.

If you centralise the call, everything will look like it came from pycrate_core.utils

p1-bmu commented 3 years ago

Yes, I realize this while reading the logging module doc and tested it. This will require changes in many files : I'll do it when I a have proper time.