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