log.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 getLogger, INFO, WARN, DEBUG, ERROR, FATAL
  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('--log-level',
  25. choices=levels, metavar="LEVEL",
  26. default='INFO',
  27. dest='loglevel',
  28. help=('Amount of detail in build-time console messages. '
  29. 'LEVEL may be one of %s (default: %%(default)s).'
  30. % ', '.join(levels))
  31. )
  32. def __process_options(parser, opts):
  33. try:
  34. level = getattr(logging, opts.loglevel.upper())
  35. except AttributeError:
  36. parser.error('Unknown log level `%s`' % opts.loglevel)
  37. else:
  38. logger.setLevel(level)