log.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2013-2021, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. """
  12. Logging module for PyInstaller.
  13. """
  14. __all__ = ['getLogger', 'INFO', 'WARN', 'DEBUG', 'TRACE', 'ERROR', 'FATAL']
  15. import logging
  16. from logging import DEBUG, ERROR, FATAL, INFO, WARN, getLogger
  17. TRACE = logging.TRACE = DEBUG - 5
  18. logging.addLevelName(TRACE, 'TRACE')
  19. FORMAT = '%(relativeCreated)d %(levelname)s: %(message)s'
  20. logging.basicConfig(format=FORMAT, level=logging.INFO)
  21. logger = getLogger('PyInstaller')
  22. def __add_options(parser):
  23. levels = ('TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')
  24. parser.add_argument(
  25. '--log-level',
  26. choices=levels,
  27. metavar="LEVEL",
  28. default='INFO',
  29. dest='loglevel',
  30. help='Amount of detail in build-time console messages. LEVEL may be one of %s (default: %%(default)s).' %
  31. ', '.join(levels),
  32. )
  33. def __process_options(parser, opts):
  34. try:
  35. level = getattr(logging, opts.loglevel.upper())
  36. except AttributeError:
  37. parser.error('Unknown log level `%s`' % opts.loglevel)
  38. else:
  39. logger.setLevel(level)