Revize 5678036c
Přidáno uživatelem David Friesecký před téměř 4 roky(ů)
src/utils/logger.py | ||
---|---|---|
1 | 1 |
import inspect |
2 | 2 |
import logging |
3 |
from logging import handlers |
|
4 |
import os |
|
3 | 5 |
from pathlib import Path |
4 | 6 |
|
5 |
from src.constants import LOG_NAME |
|
7 |
from src.config.configuration import Configuration, LOG_LEVEL_MAPPING |
|
8 |
from src.constants import LOG_NAME, LOG_DIR, LOG_FILENAME, LOG_FORMAT |
|
9 |
from src.utils.file_anchor import FileAnchor |
|
10 |
|
|
11 |
|
|
12 |
def configure_logging(config: Configuration): |
|
13 |
if not os.path.exists(FileAnchor(config.root_dir, LOG_DIR).shortest_relative_path()): |
|
14 |
os.makedirs(FileAnchor(config.root_dir, LOG_DIR).shortest_relative_path()) |
|
15 |
|
|
16 |
handler = logging.handlers.TimedRotatingFileHandler( |
|
17 |
os.path.join(FileAnchor(config.root_dir, LOG_DIR).shortest_relative_path(), LOG_FILENAME), |
|
18 |
when='H', interval=1) |
|
19 |
formatter = logging.Formatter(LOG_FORMAT) |
|
20 |
handler.setFormatter(formatter) |
|
21 |
|
|
22 |
# set log level based on config file |
|
23 |
app_logger = logging.getLogger(LOG_NAME) |
|
24 |
app_logger.setLevel(LOG_LEVEL_MAPPING.get(config.log_level, logging.DEBUG)) |
|
25 |
|
|
26 |
app_logger.addHandler(handler) |
|
27 |
|
|
28 |
log = logging.getLogger('werkzeug') |
|
29 |
log.disabled = True |
|
6 | 30 |
|
7 | 31 |
|
8 | 32 |
class Logger: |
Také k dispozici: Unified diff
Re #8880 - Edited config file (inserted RootDir)
- improved creating of logs and db directories