Skip to content

Module dcm2bids.logger⚓︎

Setup logging configuration

None

View Source
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# -*- 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⚓︎

1
2
3
4
def setup_logging(
    logLevel,
    logFile=None
)

Setup logging configuration

View Source
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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: 2022-06-17
Back to top