Passed
Push — master ( c9f8b6...d30d39 )
by Daniel
02:04
created

LoggingNeeds.initiate_logger()   A

Complexity

Conditions 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nop 2
dl 0
loc 21
rs 9.7
c 0
b 0
f 0
1
2
import logging
3
import logging.handlers as handlers
4
5
6
class LoggingNeeds:
7
    logger = None
8
9
    def initiate_logger(self, logger_file_name):
10
        # initiate Logging
11
        self.logger = logging.getLogger('thm')
12
        # set logging level to desired level only if specified
13
        if logger_file_name == 'None':
14
            self.logger.setLevel(logging.NOTSET)
15
        else:
16
            self.logger.setLevel(logging.DEBUG)
17
            # defining log file and setting rotating logic
18
            log_handler = handlers.TimedRotatingFileHandler(logger_file_name,
19
                                                            when = 'h',
20
                                                            interval = 1,
21
                                                            backupCount = 5,
22
                                                            encoding = 'utf-8',
23
                                                            utc = False)
24
            # Here we define our formatter
25
            log_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
26
            # Here we set our logHandler's formatter
27
            log_handler.setFormatter(log_formatter)
28
            # pairing the handler with logging
29
            self.logger.addHandler(log_handler)
30