You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
779 B

4 years ago
  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