log.py 779 B

123456789101112131415161718192021222324252627
  1. """Grab the global logger instance."""
  2. # Copyright (c) IPython Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. import logging
  5. _logger = None
  6. def get_logger():
  7. """Grab the global logger instance.
  8. If a global Application is instantiated, grab its logger.
  9. Otherwise, grab the root logger.
  10. """
  11. global _logger
  12. if _logger is None:
  13. from .config import Application
  14. if Application.initialized():
  15. _logger = Application.instance().log
  16. else:
  17. _logger = logging.getLogger('traitlets')
  18. # Add a NullHandler to silence warnings about not being
  19. # initialized, per best practice for libraries.
  20. _logger.addHandler(logging.NullHandler())
  21. return _logger