db_sync_tool.utility.log   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 20
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A init_logger() 0 17 3
A get_logger() 0 8 2
1
#!/usr/bin/env python3
2
# -*- coding: future_fstrings -*-
3
4
"""
5
Log script
6
"""
7
8
import logging
9
from db_sync_tool.utility import system
10
11
#
12
# GLOBALS
13
#
14
15
logger = None
0 ignored issues
show
Coding Style Naming introduced by
Constant name "logger" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\Wa-z]*|__.*__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
16
17
18
#
19
# FUNCTIONS
20
#
21
22
23
def init_logger():
24
    """
25
    Initialize the logger instance
26
    :return:
27
    """
28
    global logger
0 ignored issues
show
Coding Style introduced by
Usage of the global statement should be avoided.

Usage of global can make code hard to read and test, its usage is generally not recommended unless you are dealing with legacy code.

Loading history...
Coding Style Naming introduced by
Constant name "logger" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\Wa-z]*|__.*__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
29
    logger = logging.getLogger('db_sync_tool')
30
    logger.setLevel(logging.DEBUG)
31
32
    if system.config:
33
        if 'log_file' in system.config:
34
            fh = logging.FileHandler(system.config['log_file'])
0 ignored issues
show
Coding Style Naming introduced by
Variable name "fh" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
35
            fh.setLevel(logging.DEBUG)
36
            logger.addHandler(fh)
37
            formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
38
            fh.setFormatter(formatter)
39
            logger.addHandler(fh)
40
41
42
def get_logger():
43
    """
44
    Return the logger instance
45
    :return:
46
    """
47
    if logger is None:
48
        init_logger()
49
    return logger
50