Skip to content

Commit a882e74

Browse files
authored
Merge pull request #2595 from effigies/fix/debug_mode
FIX: Update logging levels in enable_debug_mode
2 parents f092055 + 785bdf4 commit a882e74

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

doc/users/config_file.rst

+9-2
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,23 @@ Debug configuration
237237

238238
To enable debug mode, one can insert the following lines::
239239

240-
from nipype import config, logging
240+
from nipype import config
241241
config.enable_debug_mode()
242-
logging.update_logging(config)
243242

244243
In this mode the following variables are set::
245244

246245
config.set('execution', 'stop_on_first_crash', 'true')
247246
config.set('execution', 'remove_unnecessary_outputs', 'false')
247+
config.set('execution', 'keep_inputs', 'true')
248248
config.set('logging', 'workflow_level', 'DEBUG')
249249
config.set('logging', 'interface_level', 'DEBUG')
250+
config.set('logging', 'utils_level', 'DEBUG')
251+
252+
The primary loggers (``workflow``, ``interface`` and ``utils``) are also reset
253+
to level ``DEBUG``.
254+
You may wish to adjust these manually using::
250255

256+
from nipype import logging
257+
logging.getLogger(<logger>).setLevel(<level>)
251258

252259
.. include:: ../links_names.txt

doc/users/debug.rst

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ performance issues.
2020
from nipype import config
2121
config.enable_debug_mode()
2222

23-
as the first import of your nipype script. To enable debug logging use::
24-
25-
from nipype import logging
26-
logging.update_logging(config)
23+
as the first import of your nipype script.
2724

2825
.. note::
2926

30-
Turning on debug will rerun your workflows and will rerun them after debugging
31-
is turned off.
27+
Turning on debug will rerun your workflows and will rerun them after
28+
debugging is turned off.
29+
30+
Turning on debug mode will also override log levels specified elsewhere,
31+
such as in the nipype configuration.
32+
``workflow``, ``interface`` and ``utils`` loggers will all be set to
33+
level ```DEBUG``.
3234

3335
#. There are several configuration options that can help with debugging. See
3436
:ref:`config_file` for more details::

nipype/utils/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,14 @@ def set_default_config(self):
147147

148148
def enable_debug_mode(self):
149149
"""Enables debug configuration"""
150+
from .. import logging
150151
self._config.set('execution', 'stop_on_first_crash', 'true')
151152
self._config.set('execution', 'remove_unnecessary_outputs', 'false')
152153
self._config.set('execution', 'keep_inputs', 'true')
153154
self._config.set('logging', 'workflow_level', 'DEBUG')
154155
self._config.set('logging', 'interface_level', 'DEBUG')
156+
self._config.set('logging', 'utils_level', 'DEBUG')
157+
logging.update_logging(self._config)
155158

156159
def set_log_dir(self, log_dir):
157160
"""Sets logging directory

nipype/utils/tests/test_config.py

+49
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,52 @@ def test_cwd_cached(tmpdir):
241241
oldcwd = config.cwd
242242
tmpdir.chdir()
243243
assert config.cwd == oldcwd
244+
245+
246+
def test_debug_mode():
247+
from ... import logging
248+
249+
sofc_config = config.get('execution', 'stop_on_first_crash')
250+
ruo_config = config.get('execution', 'remove_unnecessary_outputs')
251+
ki_config = config.get('execution', 'keep_inputs')
252+
wf_config = config.get('logging', 'workflow_level')
253+
if_config = config.get('logging', 'interface_level')
254+
ut_config = config.get('logging', 'utils_level')
255+
256+
wf_level = logging.getLogger('workflow').level
257+
if_level = logging.getLogger('interface').level
258+
ut_level = logging.getLogger('utils').level
259+
260+
config.enable_debug_mode()
261+
262+
# Check config is updated and logging levels, too
263+
assert config.get('execution', 'stop_on_first_crash') == 'true'
264+
assert config.get('execution', 'remove_unnecessary_outputs') == 'false'
265+
assert config.get('execution', 'keep_inputs') == 'true'
266+
assert config.get('logging', 'workflow_level') == 'DEBUG'
267+
assert config.get('logging', 'interface_level') == 'DEBUG'
268+
assert config.get('logging', 'utils_level') == 'DEBUG'
269+
270+
assert logging.getLogger('workflow').level == 10
271+
assert logging.getLogger('interface').level == 10
272+
assert logging.getLogger('utils').level == 10
273+
274+
# Restore config and levels
275+
config.set('execution', 'stop_on_first_crash', sofc_config)
276+
config.set('execution', 'remove_unnecessary_outputs', ruo_config)
277+
config.set('execution', 'keep_inputs', ki_config)
278+
config.set('logging', 'workflow_level', wf_config)
279+
config.set('logging', 'interface_level', if_config)
280+
config.set('logging', 'utils_level', ut_config)
281+
logging.update_logging(config)
282+
283+
assert config.get('execution', 'stop_on_first_crash') == sofc_config
284+
assert config.get('execution', 'remove_unnecessary_outputs') == ruo_config
285+
assert config.get('execution', 'keep_inputs') == ki_config
286+
assert config.get('logging', 'workflow_level') == wf_config
287+
assert config.get('logging', 'interface_level') == if_config
288+
assert config.get('logging', 'utils_level') == ut_config
289+
290+
assert logging.getLogger('workflow').level == wf_level
291+
assert logging.getLogger('interface').level == if_level
292+
assert logging.getLogger('utils').level == ut_level

0 commit comments

Comments
 (0)