Skip to content

Module dcm2bids.logger

Setup logging configuration

View Source
# -*- coding: utf-8 -*-

"""Setup logging configuration"""

import logging

def setup_logging(logLevel, logFile=None):

    """ Setup logging configuration"""

    logging.basicConfig()

    logger = logging.getLogger()

    # Check level

    level = getattr(logging, logLevel.upper(), None)

    if not isinstance(level, int):

        raise ValueError("Invalid log level: {}".format(logLevel))

    logger.setLevel(level)

    # Set FileHandler

    if logFile:

        formatter = logging.Formatter(logging.BASIC_FORMAT)

        handler = logging.FileHandler(logFile)

        handler.setFormatter(formatter)

        handler.setLevel("DEBUG")

        logger.addHandler(handler)

Functions

setup_logging

def setup_logging(
    logLevel,
    logFile=None
)

Setup logging configuration

View Source
def setup_logging(logLevel, logFile=None):

    """ Setup logging configuration"""

    logging.basicConfig()

    logger = logging.getLogger()

    # Check level

    level = getattr(logging, logLevel.upper(), None)

    if not isinstance(level, int):

        raise ValueError("Invalid log level: {}".format(logLevel))

    logger.setLevel(level)

    # Set FileHandler

    if logFile:

        formatter = logging.Formatter(logging.BASIC_FORMAT)

        handler = logging.FileHandler(logFile)

        handler.setFormatter(formatter)

        handler.setLevel("DEBUG")

        logger.addHandler(handler)

Last update: 2023-07-13
Created: 2023-07-13