cmind.utils.logging_utils

Logging Utilities Various functionality related to logging outputs for the C-MIND processing pipelines

cmind_func_info cmind_logger cmind_init_logging log_cmd

Functions

cmind_func_info([logger, multiline_output, ...]) Print the calling function name and its arguments
cmind_init_logging([verbose, logger, child_name]) Initialize CMIND module logging
cmind_logger([log_level_console, ...]) configures a logger
log_cmd(shell_cmd[, verbose, logger, ...]) wrapper around subprocess.check_output
logger_info(logger) Print a logger’s name, handlers, and levels
cmind.utils.logging_utils.cmind_func_info(logger=None, multiline_output=True, remove_functions_from_list=True)[source]

Print the calling function name and its arguments

Parameters:

logger : logging.Logger, optional

if unspecified print to console rather than logger

multiline_output : bool, optional

also print with one argument per line for easier reading

remove_functions_from_list : bool, optional

if True, do not print the functions and modules imported by the current frame

cmind.utils.logging_utils.cmind_init_logging(verbose=True, logger=None, child_name=None)[source]

Initialize CMIND module logging

Parameters:

verbose : str, optional

if True the module_logger level will be set to DEBUG, otherwise ERROR

logger : logging.Logger or str

if this is a string, it should be the name of the desired logfile

child_name : str, optional

if present, the logger will have the name: logger.name + child_name. child_name defaults to the calling function name. If logger=None, the generated logger will have the name “child_name if it was specified”

Returns:

module_logger : logging.Logger

logger to be used within the CMIND module

cmind.utils.logging_utils.cmind_logger(log_level_console='INFO', logger_name='CMIND', logfile=None, log_level_file='DEBUG', file_mode='a', console_format_string=None, file_format_string=None, capture_warnings=True, datefmt='%m-%d-%y %H:%M')[source]

configures a logger

Parameters:

log_level_console : optional, {None,’DEBUG’,’INFO’,’WARNING’,’ERROR’,’CRITICAL’}

desired logging level for output to the console

logfile : optional, str

file to log to

log_level_file : optional, {‘DEBUG’,’INFO’,’WARNING’,’ERROR’,’CRITICAL’}

desired logging level for output to the file

file_mode : optional, {‘w’,’a’}

overwrite or append to logfile

console_format_string : optional, string or None

console log formatting string to be passed on to logging.Formatter()

file_format_string : optional, string or None

file log formatting string to be passed on to logging.Formatter()

capture_warnings : bool

control whether logging captures warnings

datefmt : str, optional

optional custom date formatting to be passed on to logging.Formatter()

Returns

——-

logger : logger

logger for use in logging by cmind applications

cmind.utils.logging_utils.log_cmd(shell_cmd, verbose=False, logger=None, print_stdout=None, stderr_to_stdout=False, print_cmd_header=False, env_dict=None, auto_retry=False, log_error=True)[source]

wrapper around subprocess.check_output

Parameters:

shell_cmd : str

string representing the shell command to be run

verbose : boolean, optional

if True, print the shell_cmd to standard out

logfile : str or file handle

if logfile: print the shell_cmd to the logfile as well

print_stdout : boolean, optional

if True, also print out the standard output of the shell commands

stderr_to_stdout : boolean, optional

if True, redirect stderr to stdout (recommend setting to False)

print_cmd_header : boolean, optional

if True, print “Executing shell command” header

env_dict : dict, optional

if present, append/override the specified environment variables

auto_retry : bool, optional

if True, will retry the command once after failure

Returns:

stdout : str

Standard output of the command

cmind.utils.logging_utils.logger_info(logger)[source]

Print a logger’s name, handlers, and levels

Parameters:

logger : logging.Logger

logger to print details about.