Skip to content

Commit 6a5067c

Browse files
committed
doc: updated\; fix: log to file is disabledcorrectly during update
1 parent 8e12deb commit 6a5067c

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

CHANGES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Changes since 0.5
22
=================
33

4-
None
4+
* API: Logging to file is disabled by default
5+
6+
* ENH: Changing logging options via config works for distributed processing
57

68
Release 0.5 (Mar 10, 2012)
79
==========================

doc/users/config_file.rst

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
Some of the system wide options of Nipype can be configured using a
88
configuration file. Nipype looks for the file in the local folder under the name
9-
``nipype.cfg`` and in ``~/.nipype.cfg`` (in this order). If an option will not
10-
be specified a default value will be assumed. The file is divided into following
11-
sections:
9+
``nipype.cfg`` and in ``~/.nipype/nipype.cfg`` (in this order). If an option
10+
will not be specified a default value will be assumed. The file is divided into
11+
following sections:
1212

1313
Logging
1414
~~~~~~~
@@ -25,7 +25,7 @@ Logging
2525
values: ``INFO`` and ``DEBUG``; default value: ``INFO``)
2626
*log_to_file*
2727
Indicates whether logging should also send the output to a file (possible
28-
values: ``true`` and ``false``; default value: ``true``)
28+
values: ``true`` and ``false``; default value: ``false``)
2929
*log_directory*
3030
Where to store logs. (string, default value: home directory)
3131
*log_size*
@@ -120,43 +120,52 @@ Example
120120
hash_method = timestamp
121121
display_variable = :1
122122

123-
Additionally you can set some config options by setting the workflow.config. This, however, currently does not work for options related to logging levels. Those will be always read from .cfg files.
124-
125-
Workflow.config property has a form of a nested dictionary reflecting the structure of the .cfg file.
123+
Workflow.config property has a form of a nested dictionary reflecting the
124+
structure of the .cfg file.
126125

127126
::
128127
129128
myworkflow = pe.Workflow()
130129
myworkflow.config['execution'] = {'stop_on_first_rerun': 'True',
131130
'hash_method': 'timestamp'}
132131

133-
You can also directly set config options in your workflow script. An
132+
You can also directly set global config options in your workflow script. An
134133
example is shown below. This needs to be called before you import the
135134
pipeline or the logger. Otherwise logging level will not be reset.
136135

137136
::
138137

139-
from nipype.utils.config import config
140-
from StringIO import StringIO
141-
cfg = StringIO("""
142-
[logging]
143-
workflow_level = DEBUG
138+
from nipype import config
139+
cfg = dict(logging=dict(workflow_level = 'DEBUG'),
140+
execution={'stop_on_first_crash': False,
141+
'hash_method': 'content'})
142+
config.update_config(cfg)
144143

145-
[execution]
146-
stop_on_first_crash = false
147-
hash_method = content
148-
""")
149-
150-
config.readfp(cfg)
144+
Enabling logging to file
145+
~~~~~~~~~~~~~~~~~~~~~~~~
146+
147+
By default, logging to file is disabled. One can enable and write the file to
148+
a location of choice as in the example below.
149+
150+
::
151+
152+
import os
153+
from nipype import config, logging
154+
config.update_config({'logging': {'log_directory': os.getcwd(),
155+
'log_to_file': True}})
156+
logging.update_logging(config)
157+
158+
The logging update line is necessary to change the behavior of logging such as
159+
output directory, logging level, etc.,.
151160

152161
Debug configuration
153162
~~~~~~~~~~~~~~~~~~~
154163

155-
To enable debug mode, one can insert the following lines at the beginning of any
156-
script.::
164+
To enable debug mode, one can insert the following lines::
157165

158-
from nipype.utils.config import config
166+
from nipype import config, logging
159167
config.enable_debug_mode()
168+
logging.update_logging(config)
160169

161170
In this mode the following variables are set::
162171

nipype/utils/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ def disable_file_logging(self):
6060

6161
def update_logging(self, config):
6262
self._config = config
63+
self.disable_file_logging()
6364
self._logger.setLevel(logging.getLevelName(config.get('logging',
6465
'workflow_level')))
6566
self._fmlogger.setLevel(logging.getLevelName(config.get('logging',
6667
'filemanip_level')))
6768
self._iflogger.setLevel(logging.getLevelName(config.get('logging',
6869
'interface_level')))
6970
if str2bool(config.get('logging', 'log_to_file')):
70-
self.disable_file_logging()
7171
self.enable_file_logging()
7272

7373
def getLogger(self, name):

0 commit comments

Comments
 (0)