Revize 1bdc90c0
Přidáno uživatelem David Friesecký před téměř 4 roky(ů)
app.py | ||
---|---|---|
80 | 80 |
injector = Injector(modules) |
81 | 81 |
FlaskInjector(app=application, modules=modules) |
82 | 82 |
|
83 |
configuration.configure_logging() |
|
84 |
|
|
83 | 85 |
# There's a little dependency on the CryptoService, which is not a pretty thing from |
84 | 86 |
# architectural point of view. However it is only a minimal piece of code and |
85 | 87 |
# it makes sense to do it in this way instead of trying to run openssl via subprocess here |
src/config/configuration.py | ||
---|---|---|
5 | 5 |
from injector import singleton |
6 | 6 |
|
7 | 7 |
from src.constants import DEFAULT_CONNECTION_STRING, TEST_DATABASE_FILE, DEFAULT_SERVER_BASE_URL |
8 |
from src.constants import LOG_FILE_LOCATION, LOG_FORMAT |
|
8 | 9 |
|
9 | 10 |
DATABASE_SECTION = "Database" |
10 | 11 |
DATABASE_CONNECTION_STRING = "ConnectionString" |
... | ... | |
12 | 13 |
SERVER_SECTION = "Server" |
13 | 14 |
SERVER_BASE_URL = "ServerBaseURL" |
14 | 15 |
|
15 |
LOG_FILE = "application.log" |
|
16 |
LOG_FORMAT = "%(levelname)-8s %(asctime)s - %(message)s" |
|
17 |
|
|
18 | 16 |
|
19 | 17 |
class Configuration: |
20 | 18 |
""" |
... | ... | |
68 | 66 |
binder.bind(Configuration, to=app_configuration, scope=singleton) |
69 | 67 |
|
70 | 68 |
|
71 |
def configure_logging(self):
|
|
72 |
logging.basicConfig(filename=LOG_FILE, |
|
69 |
def configure_logging(): |
|
70 |
logging.basicConfig(filename=LOG_FILE_LOCATION.shortest_relative_path(),
|
|
73 | 71 |
filemode='a+', |
74 | 72 |
format=LOG_FORMAT, |
75 | 73 |
level=logging.DEBUG) |
src/constants.py | ||
---|---|---|
6 | 6 |
DATABASE_FILE_LOCATION = FileAnchor("aswi2021jmsd", DATABASE_FILE) |
7 | 7 |
DATETIME_FORMAT = "%d.%m.%Y %H:%M:%S" |
8 | 8 |
|
9 |
LOG_FILE = "log/application.log" |
|
10 |
LOG_FILE_LOCATION = FileAnchor("aswi2021jmsd", LOG_FILE) |
|
11 |
LOG_FORMAT = "%(levelname)-8s %(asctime)s - %(message)s" |
|
12 |
|
|
9 | 13 |
REV_REASON_UNSPECIFIED = "unspecified" |
10 | 14 |
|
11 | 15 |
# Types of certificates |
src/utils/logger.py | ||
---|---|---|
1 |
import inspect |
|
1 | 2 |
import logging |
3 |
from pathlib import Path |
|
2 | 4 |
|
3 | 5 |
|
4 | 6 |
class Logger: |
5 | 7 |
|
6 | 8 |
@staticmethod |
7 |
def debug(layer: str, message: str): |
|
8 |
logging.debug(f'{layer}: {message}') |
|
9 |
def get_names(): |
|
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__ |
|
13 |
function_name = stack[2][0].f_code.co_name |
|
14 |
|
|
15 |
return file_name, class_name, function_name |
|
16 |
|
|
17 |
@staticmethod |
|
18 |
def debug(message: str): |
|
19 |
names = Logger.get_names() |
|
20 |
logging.debug(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}') |
|
9 | 21 |
|
10 | 22 |
@staticmethod |
11 |
def info(layer: str, message: str): |
|
12 |
logging.info(f'{layer}: {message}') |
|
23 |
def info(message: str): |
|
24 |
names = Logger.get_names() |
|
25 |
logging.info(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}') |
|
13 | 26 |
|
14 | 27 |
@staticmethod |
15 |
def warning(layer: str, message: str): |
|
16 |
logging.warning(f'{layer}: {message}') |
|
28 |
def warning(message: str): |
|
29 |
names = Logger.get_names() |
|
30 |
logging.warning(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}') |
|
17 | 31 |
|
18 | 32 |
@staticmethod |
19 |
def error(layer: str, message: str): |
|
20 |
logging.error(f'{layer}: {message}') |
|
33 |
def error(message: str): |
|
34 |
names = Logger.get_names() |
|
35 |
logging.error(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}') |
|
21 | 36 |
|
22 | 37 |
@staticmethod |
23 |
def critical(layer: str, message: str): |
|
24 |
logging.critical(f'{layer}: {message}') |
|
38 |
def critical(message: str): |
|
39 |
names = Logger.get_names() |
|
40 |
logging.critical(f'{Path(names[0]).name}[{names[1]}.{names[2]}()]: {message}') |
Také k dispozici: Unified diff
Re #8570 - Setted configuration of logging