mirror of https://github.com/docker/compose.git
Merge pull request #5703 from mnottale/log-level
New --log-level option.
This commit is contained in:
commit
6659e99aff
|
@ -100,7 +100,10 @@ def dispatch():
|
||||||
{'options_first': True, 'version': get_version_info('compose')})
|
{'options_first': True, 'version': get_version_info('compose')})
|
||||||
|
|
||||||
options, handler, command_options = dispatcher.parse(sys.argv[1:])
|
options, handler, command_options = dispatcher.parse(sys.argv[1:])
|
||||||
setup_console_handler(console_handler, options.get('--verbose'), options.get('--no-ansi'))
|
setup_console_handler(console_handler,
|
||||||
|
options.get('--verbose'),
|
||||||
|
options.get('--no-ansi'),
|
||||||
|
options.get("--log-level"))
|
||||||
setup_parallel_logger(options.get('--no-ansi'))
|
setup_parallel_logger(options.get('--no-ansi'))
|
||||||
if options.get('--no-ansi'):
|
if options.get('--no-ansi'):
|
||||||
command_options['--no-color'] = True
|
command_options['--no-color'] = True
|
||||||
|
@ -139,7 +142,7 @@ def setup_parallel_logger(noansi):
|
||||||
compose.parallel.ParallelStreamWriter.set_noansi()
|
compose.parallel.ParallelStreamWriter.set_noansi()
|
||||||
|
|
||||||
|
|
||||||
def setup_console_handler(handler, verbose, noansi=False):
|
def setup_console_handler(handler, verbose, noansi=False, level=None):
|
||||||
if handler.stream.isatty() and noansi is False:
|
if handler.stream.isatty() and noansi is False:
|
||||||
format_class = ConsoleWarningFormatter
|
format_class = ConsoleWarningFormatter
|
||||||
else:
|
else:
|
||||||
|
@ -147,10 +150,25 @@ def setup_console_handler(handler, verbose, noansi=False):
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
handler.setFormatter(format_class('%(name)s.%(funcName)s: %(message)s'))
|
handler.setFormatter(format_class('%(name)s.%(funcName)s: %(message)s'))
|
||||||
handler.setLevel(logging.DEBUG)
|
loglevel = logging.DEBUG
|
||||||
else:
|
else:
|
||||||
handler.setFormatter(format_class())
|
handler.setFormatter(format_class())
|
||||||
handler.setLevel(logging.INFO)
|
loglevel = logging.INFO
|
||||||
|
|
||||||
|
if level is not None:
|
||||||
|
levels = {
|
||||||
|
'DEBUG': logging.DEBUG,
|
||||||
|
'INFO': logging.INFO,
|
||||||
|
'WARNING': logging.WARNING,
|
||||||
|
'ERROR': logging.ERROR,
|
||||||
|
'CRITICAL': logging.CRITICAL,
|
||||||
|
}
|
||||||
|
loglevel = levels.get(level.upper())
|
||||||
|
if loglevel is None:
|
||||||
|
raise UserError('Invalid value for --log-level. Expected one of '
|
||||||
|
+ 'DEBUG, INFO, WARNING, ERROR, CRITICAL.')
|
||||||
|
|
||||||
|
handler.setLevel(loglevel)
|
||||||
|
|
||||||
|
|
||||||
# stolen from docopt master
|
# stolen from docopt master
|
||||||
|
@ -171,6 +189,7 @@ class TopLevelCommand(object):
|
||||||
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
|
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
|
||||||
-p, --project-name NAME Specify an alternate project name (default: directory name)
|
-p, --project-name NAME Specify an alternate project name (default: directory name)
|
||||||
--verbose Show more output
|
--verbose Show more output
|
||||||
|
--log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
||||||
--no-ansi Do not print ANSI control characters
|
--no-ansi Do not print ANSI control characters
|
||||||
-v, --version Print version and exit
|
-v, --version Print version and exit
|
||||||
-H, --host HOST Daemon socket to connect to
|
-H, --host HOST Daemon socket to connect to
|
||||||
|
|
|
@ -619,6 +619,20 @@ class CLITestCase(DockerClientTestCase):
|
||||||
assert BUILD_CACHE_TEXT not in result.stdout
|
assert BUILD_CACHE_TEXT not in result.stdout
|
||||||
assert BUILD_PULL_TEXT in result.stdout
|
assert BUILD_PULL_TEXT in result.stdout
|
||||||
|
|
||||||
|
def test_build_log_level(self):
|
||||||
|
self.base_dir = 'tests/fixtures/simple-dockerfile'
|
||||||
|
result = self.dispatch(['--log-level', 'warning', 'build', 'simple'])
|
||||||
|
assert result.stderr == ''
|
||||||
|
result = self.dispatch(['--log-level', 'debug', 'build', 'simple'])
|
||||||
|
assert 'Building simple' in result.stderr
|
||||||
|
assert 'Using configuration file' in result.stderr
|
||||||
|
self.base_dir = 'tests/fixtures/simple-failing-dockerfile'
|
||||||
|
result = self.dispatch(['--log-level', 'critical', 'build', 'simple'], returncode=1)
|
||||||
|
assert result.stderr == ''
|
||||||
|
result = self.dispatch(['--log-level', 'debug', 'build', 'simple'], returncode=1)
|
||||||
|
assert 'Building simple' in result.stderr
|
||||||
|
assert 'non-zero code' in result.stderr
|
||||||
|
|
||||||
def test_build_failed(self):
|
def test_build_failed(self):
|
||||||
self.base_dir = 'tests/fixtures/simple-failing-dockerfile'
|
self.base_dir = 'tests/fixtures/simple-failing-dockerfile'
|
||||||
self.dispatch(['build', 'simple'], returncode=1)
|
self.dispatch(['build', 'simple'], returncode=1)
|
||||||
|
|
Loading…
Reference in New Issue