microsoft / hi-ml

HI-ML toolbox for deep learning for medical imaging and Azure integration
https://aka.ms/hi-ml
MIT License
253 stars 58 forks source link

Code in published packages should not use `logging.info`, but a package-level logger #445

Open ant0nsc opened 2 years ago

ant0nsc commented 2 years ago

At present, a lot of the code in hi-ml writes out information via a plain call to logging.info. Instead, this should use a package-level logger that can be configured by the user.

Thanks for raising that @Shruthi42

usuyama commented 2 years ago

I agree!

On a related note, I think would be great to use more user-friendly log format e.g. logging.basicConfig(format='[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s', filemode='w')

ant0nsc commented 2 years ago

@usuyama , is your ask mostly about the pathname and linenumber? Also, what's your entrypoint into the hi-ml code?

Shruthi42 commented 2 years ago

@fepegar @ozan-oktay we should keep this in mind for the multimodal subfolder as well.

fepegar commented 1 year ago

@usuyama thanks for suggesting that format. I think it's quite nice. Here's a tiny test (with a little variation):

import logging
logger = logging.getLogger(__name__)
formatter = logging.Formatter('%(asctime)s - %(pathname)s:%(lineno)d - %(levelname)s - %(message)s')
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logger.addHandler(handler)

logger.setLevel(logging.DEBUG)

logger.debug('Hey!')
logger.info('Hey!')
logger.warning('Hey!')
logger.error('Hey!')
logger.critical('Hey!')
2022-11-28 16:02:05,690 - l.py:8 - WARNING - Hey!

Which is quite nicely syntax-highlighted in VS Code:

image