Passed
Push — development/test ( 02e03c...b2a2db )
by Daniel
01:09
created

sources.common.LoggingNeeds   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A LoggingNeeds.initiate_logger() 0 22 2
1
"""
2
LoggingNeeds
3
4
This library sets all required parameters for a rotating LOG file
5
"""
6
# package for Log management
7
import logging
8
import logging.handlers as handlers
9
10
11
class LoggingNeeds:
12
    logger = None
13
14
    def initiate_logger(self, logger_file_name, logger_internal_name):
15
        # initiate Logging
16
        self.logger = logging.getLogger(logger_internal_name)
17
        # set logging level to desired level only if specified
18
        if logger_file_name == 'None':
19
            self.logger.setLevel(logging.NOTSET)
20
        else:
21
            self.logger.setLevel(logging.DEBUG)
22
            # defining log file and setting rotating logic
23
            log_handler = handlers.TimedRotatingFileHandler(logger_file_name,
24
                                                            when='h',
25
                                                            interval=1,
26
                                                            backupCount=5,
27
                                                            encoding='utf-8',
28
                                                            utc=False)
29
            # Here we define our formatter
30
            string_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
31
            log_formatter = logging.Formatter(string_format)
32
            # Here we set our logHandler's formatter
33
            log_handler.setFormatter(log_formatter)
34
            # pairing the handler with logging
35
            self.logger.addHandler(log_handler)
36