Projekt

Obecné

Profil

Stáhnout (1.56 KB) Statistiky
| Větev: | Tag: | Revize:
1
import inspect
2
import logging
3
from pathlib import Path
4

    
5
from src.constants import LOG_NAME
6

    
7

    
8
class Logger:
9

    
10
    @staticmethod
11
    def get_names():
12
        stack = inspect.stack()
13

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

    
20
        return file_name, class_name, function_name
21

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

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

    
34
    @staticmethod
35
    def warning(message: str):
36
        names = Logger.get_names()
37
        app_logger = logging.getLogger(LOG_NAME)
38
        app_logger.warning(f'{Path(names[0]).name}[{names[1]}{names[2]}()]: {message}')
39

    
40
    @staticmethod
41
    def error(message: str):
42
        names = Logger.get_names()
43
        app_logger = logging.getLogger(LOG_NAME)
44
        app_logger.error(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
45

    
46
    @staticmethod
47
    def critical(message: str):
48
        names = Logger.get_names()
49
        app_logger = logging.getLogger(LOG_NAME)
50
        app_logger.critical(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
(3-3/6)