Projekt

Obecné

Profil

« Předchozí | Další » 

Revize dbca269d

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

Re #8570 - Implemented logger
- implemented static functions (debug, info, warning, error, critical) (sorted by level)
- used configuration for setting logging library

Zobrazit rozdíly:

src/config/configuration.py
1 1
import os
2 2

  
3 3
import configparser
4
import logging
4 5
from injector import singleton
5 6

  
6 7
from src.constants import DEFAULT_CONNECTION_STRING, TEST_DATABASE_FILE, DEFAULT_SERVER_BASE_URL
......
11 12
SERVER_SECTION = "Server"
12 13
SERVER_BASE_URL = "ServerBaseURL"
13 14

  
15
LOG_FILE = "application.log"
16
LOG_FORMAT = "%(levelname)-8s %(asctime)s - %(message)s"
17

  
14 18

  
15 19
class Configuration:
16 20
    """
......
62 66
                                                                  DEFAULT_SERVER_BASE_URL)
63 67

  
64 68
    binder.bind(Configuration, to=app_configuration, scope=singleton)
69

  
70

  
71
def configure_logging(self):
72
    logging.basicConfig(filename=LOG_FILE,
73
                        filemode='a+',
74
                        format=LOG_FORMAT,
75
                        level=logging.DEBUG)
src/constants.py
60 60
                                  "superseded", "cessationOfOperation",
61 61
                                  "certificateHold", "removeFromCRL",
62 62
                                  "privilegeWithdrawn", "aACompromise"}
63

  
64
LAYER_REPOSITORY = "Repository";
src/utils/logger.py
1
import logging
2

  
3

  
4
class Logger:
5

  
6
    @staticmethod
7
    def debug(layer: str, message: str):
8
        logging.debug(f'{layer}: {message}')
9

  
10
    @staticmethod
11
    def info(layer: str, message: str):
12
        logging.info(f'{layer}: {message}')
13

  
14
    @staticmethod
15
    def warning(layer: str, message: str):
16
        logging.warning(f'{layer}: {message}')
17

  
18
    @staticmethod
19
    def error(layer: str, message: str):
20
        logging.error(f'{layer}: {message}')
21

  
22
    @staticmethod
23
    def critical(layer: str, message: str):
24
        logging.critical(f'{layer}: {message}')

Také k dispozici: Unified diff