Projekt

Obecné

Profil

Stáhnout (1.56 KB) Statistiky
| Větev: | Tag: | Revize:
1 1bdc90c0 David Friesecký
import inspect
2 dbca269d David Friesecký
import logging
3 1bdc90c0 David Friesecký
from pathlib import Path
4 dbca269d David Friesecký
5 ed35ce72 David Friesecký
from src.constants import LOG_NAME
6
7 dbca269d David Friesecký
8
class Logger:
9
10
    @staticmethod
11 1bdc90c0 David Friesecký
    def get_names():
12
        stack = inspect.stack()
13 ca436714 David Friesecký
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 1bdc90c0 David Friesecký
        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 ed35ce72 David Friesecký
        app_logger = logging.getLogger(LOG_NAME)
26
        app_logger.debug(f'{Path(names[0]).name}[{names[1]}{names[2]}()]: {message}')
27 dbca269d David Friesecký
28
    @staticmethod
29 1bdc90c0 David Friesecký
    def info(message: str):
30
        names = Logger.get_names()
31 ed35ce72 David Friesecký
        app_logger = logging.getLogger(LOG_NAME)
32
        app_logger.info(f'{Path(names[0]).name}[{names[1]}{names[2]}()]: {message}')
33 dbca269d David Friesecký
34
    @staticmethod
35 1bdc90c0 David Friesecký
    def warning(message: str):
36
        names = Logger.get_names()
37 ed35ce72 David Friesecký
        app_logger = logging.getLogger(LOG_NAME)
38
        app_logger.warning(f'{Path(names[0]).name}[{names[1]}{names[2]}()]: {message}')
39 dbca269d David Friesecký
40
    @staticmethod
41 1bdc90c0 David Friesecký
    def error(message: str):
42
        names = Logger.get_names()
43 ed35ce72 David Friesecký
        app_logger = logging.getLogger(LOG_NAME)
44
        app_logger.error(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')
45 dbca269d David Friesecký
46
    @staticmethod
47 1bdc90c0 David Friesecký
    def critical(message: str):
48
        names = Logger.get_names()
49 ed35ce72 David Friesecký
        app_logger = logging.getLogger(LOG_NAME)
50
        app_logger.critical(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}')