Sagemaker-python-sdk: Importing the sagemaker module change the logging setup

Created on 18 Apr 2019  路  3Comments  路  Source: aws/sagemaker-python-sdk

System Information

  • Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans): NA
  • Framework Version: NA
  • Python Version: 3.6.3
  • CPU or GPU: NA
  • Python SDK Version: sagemaker-1.18.14.post1 (current version served by pip install sagemaker)
  • Are you using a custom image: no

Describe the problem

Simply importing the sagemaker module alterates the logging module configuration.

Minimal repro / logs

Consider the following code:

import logging

logging.basicConfig(level='DEBUG',
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M')

logging.debug("debug")
logging.info('info')
logging.error('error')
logging.warning("WARNING")

When ran, will output:

04-18 09:15 root         DEBUG    debug
04-18 09:15 root         INFO     info
04-18 09:15 root         ERROR    error
04-18 09:15 root         WARNING  WARNING

as expected. Now, the modified code, the only difference being the import of the sagemaker module:

import logging
import sagemaker

logging.basicConfig(level='DEBUG',
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M')

logging.debug("debug")
logging.info('info')
logging.error('error')
logging.warning("WARNING")

will output:

WARNING:root:pandas failed to import. Analytics features will be impaired or broken.
ERROR:root:error
WARNING:root:WARNING

The logging level and formatting has been overwritten (the warning about pandas is not the problem I'm pointing at).

pending release bug

All 3 comments

I think the problem arise because:

  • I import sagemaker before first calling logging.basicConfig
  • in multiple places in the sagemaker code, I see:
logging.basicConfig()
LOGGER = logging.getLogger('sagemaker')
LOGGER.setLevel(logging.INFO)

which does call logging.basicConfig(). According to the python documentation about logging:

This function does nothing if the root logger already has handlers configured for it.

I don't think a module should configure any logging parameters (i.e.: only the line LOGGER = logging.getLogger('sagemaker') should remain).

Workaround: do not import sagemaker before calling logging.basicConfig() at a higher level.

hi @eprochasson, thanks for the detailed bug report! I've created a PR to address this bug: #757

the changes have now been released. closing this issue.

Was this page helpful?
0 / 5 - 0 ratings