Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ca436714

Přidáno uživatelem David Friesecký před téměř 4 roky(ů)

Re #8570 - Logger configuration
- implemented dictionary to string in utils
- implemented log functions with parameter message only (name of file, name of class and name of function
are getting automaticaly)

Zobrazit rozdíly:

app.py
9 9
from src.controllers.certificates_controller import CertController
10 10
from src.controllers.crl_ocsp_controller import CrlOcspController
11 11
from src.services.cryptography import CryptographyService, CryptographyException
12
from src.utils.logger import Logger
12 13

  
13 14
app = Flask(__name__)
14 15

  
......
92 93
    :return: boolean flag indicating whether initialization was successful or not
93 94
    """
94 95

  
96
    configuration.configure_logging()
97

  
95 98
    modules = [configuration.configure_env_variable, ConnectionProvider]
96 99
    injector = Injector(modules)
97 100
    FlaskInjector(app=application, modules=modules)
98 101

  
99
    configuration.configure_logging()
100

  
101 102
    # There's a little dependency on the CryptoService, which is not a pretty thing from
102 103
    # architectural point of view. However it is only a minimal piece of code and
103 104
    # it makes sense to do it in this way instead of trying to run openssl via subprocess here
......
105 106
    try:
106 107
        # if version string is returned, OpenSSL is present on the system
107 108
        print(f"Using {cryptography_service.get_openssl_version()}")
109
        Logger.info(f"Using {cryptography_service.get_openssl_version()}")
108 110
        # TODO log the version instead of prining it out
109 111
        return True
110 112
    except CryptographyException:
111 113
        # If getting the version string throws an exception the OpenSSL is not available
112 114
        print("OpenSSL was not located on the system. Application will now exit.")
115
        Logger.error(f"OpenSSL was not located on the system. Application will now exit.")
113 116
        # TODO add logging here
114 117
        return False
115 118

  
......
119 122
    if not initialize_app(app):
120 123
        # TODO log this
121 124
        print("Failed to initialize app, aborting...")
125
        Logger.error(f"Failed to initialize app, aborting...")
122 126
        exit(-1)
123 127

  
124 128
if __name__ == '__main__':
src/constants.py
62 62
CERTIFICATE_REVOCATION_REASONS = {"unspecified", "keyCompromise",
63 63
                                  "CACompromise", "affiliationChanged",
64 64
                                  "superseded", "cessationOfOperation",
65
<<<<<<< HEAD
66
                                  "certificateHold", "removeFromCRL",
67
                                  "privilegeWithdrawn", "aACompromise"}
68

  
69
LAYER_REPOSITORY = "Repository";
70
=======
71 65
                                  "certificateHold", "removeFromCRL"}
72 66

  
73 67

  
......
94 88
organizationalUnitName = optional
95 89

  
96 90
"""
97

  
98
>>>>>>> master
src/utils/logger.py
8 8
    @staticmethod
9 9
    def get_names():
10 10
        stack = inspect.stack()
11
        file_name = inspect.getfile(stack[2][0].f_locals["self"].__class__)
12
        class_name = stack[2][0].f_locals["self"].__class__.__name__
11

  
12
        file_name = inspect.getmodule(inspect.stack()[2][0]).__file__
13
        class_name = ""
14
        if "self" in stack[2][0].f_locals:
15
            class_name = stack[2][0].f_locals["self"].__class__.__name__ + "."
13 16
        function_name = stack[2][0].f_code.co_name
14 17

  
15 18
        return file_name, class_name, function_name
......
17 20
    @staticmethod
18 21
    def debug(message: str):
19 22
        names = Logger.get_names()
20
        logging.debug(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
23
        logging.debug(f'{Path(names[0]).name}[{names[1]}{names[2]}()]: {message}')
21 24

  
22 25
    @staticmethod
23 26
    def info(message: str):
24 27
        names = Logger.get_names()
25
        logging.info(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
28
        logging.info(f'{Path(names[0]).name}[{names[1]}{names[2]}()]: {message}')
26 29

  
27 30
    @staticmethod
28 31
    def warning(message: str):
29 32
        names = Logger.get_names()
30
        logging.warning(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
33
        logging.warning(f'{Path(names[0]).name}[{names[1]}{names[2]}()]: {message}')
31 34

  
32 35
    @staticmethod
33 36
    def error(message: str):
src/utils/util.py
1 1
import datetime
2 2

  
3 3
import six
4
import typing
5 4

  
6 5

  
7 6
def _deserialize(data, klass):
......
139 138
    """
140 139
    return {k: _deserialize(v, boxed_type)
141 140
            for k, v in six.iteritems(data)}
141

  
142

  
143
def dict_to_string(data):
144
    data_str = ""
145
    for key, value in data.items():
146
        data_str += f"\t\t{key}"
147

  
148
        if type(value) is dict:
149
            data_str += " --\n"
150
            for subkey, subvalue in value.items():
151
                data_str += f"\t\t\t{subkey} : {subvalue}\n"
152
        else:
153
            data_str += f" : {value}\n"
154

  
155
    return data_str

Také k dispozici: Unified diff