mriqc icon indicating copy to clipboard operation
mriqc copied to clipboard

default logging level is not used throughout all mriqc subprocesses when called by CLI

Open jiavila opened this issue 3 years ago • 5 comments

The default logging level is not used throughout all mriqc subprocesses; right now it logs info despite --verbose input defaulting to level 25 (custom state important and above, warning is 30). The nipype subprocess seems to be the issue. See logs excerpt, used mriqc version 0.15.1

mriqc_sample_logs.txt

jiavila avatar Mar 01 '22 15:03 jiavila

I haven't checked, but I'm pretty positive this is easily fixable by enforcing logging levels in https://github.com/nipreps/mriqc/blob/e17d9c6228d290bd85e764b1bc02005b49a3f12a/mriqc/config.py#L639-L643

@mckenziephagen, @celprov, or @ZviBaratz, any appetite to address this one?

oesteban avatar Aug 15 '22 13:08 oesteban

What do you mean by "enforcing logging levels"?

mckenziephagen avatar Aug 15 '22 16:08 mckenziephagen

@mckenziephagen I think it just means that the execution class' log_level paramater will be assigned the appropriate value, @oesteban is that correct? I'm on vacation until beginning of September, but I might be able to come up with a quick PR tomorrow.

ZviBaratz avatar Aug 15 '22 16:08 ZviBaratz

If I understand correctly, I think it might be best to create an environment variable to set the desired log level (e.g. MRIQC_LOG_LEVEL) and then read it within the module (with os.getenv("MRIQC_LOG_LEVEL", DEFAULT_LOG_LEVEL)) and use that in the execution class. Finally, it will need to be added to the forked process' initargs. Does this make sense?

ZviBaratz avatar Aug 15 '22 19:08 ZviBaratz

I would perhaps try to initiate a proper MRIQC config in all subprocesses. To do that, something along the lines of the following should work out:

def _process_initializer(config_file): 
    """Initialize the environment of the child process.""" 
    from mriqc import config
 
    # Disable eTelemetry
    os.environ["NIPYPE_NO_ET"] = "1"
    os.environ["NO_ET"] = "1"
    # Load config
    config.load(config_file)
    # Initalize nipype config
    config.nipype.init()
    # Make sure loggers are started
    config.loggers.init()

    
    os.chdir(config.execution.cwd)
    os.environ["OMP_NUM_THREADS"] = f"{config.nipype.omp_nthreads}" 

oesteban avatar Aug 15 '22 19:08 oesteban