Commit 1f09996e authored by shadMod's avatar shadMod 💬

added set_log_config() to set dictConfig()

parent 27834661
Pipeline #353 passed with stage
in 0 seconds
...@@ -29,6 +29,8 @@ from . import pages ...@@ -29,6 +29,8 @@ from . import pages
from . import redirects from . import redirects
from . import utils from . import utils
from logging.config import dictConfig
def create_app(data_path, debug=False): def create_app(data_path, debug=False):
"""Create a new instance of the application""" """Create a new instance of the application"""
...@@ -43,6 +45,7 @@ def create_app(data_path, debug=False): ...@@ -43,6 +45,7 @@ def create_app(data_path, debug=False):
# Prepare the data directory # Prepare the data directory
init_data_directory(data_path) init_data_directory(data_path)
set_log_config(data_path)
# Load the secret key # Load the secret key
with open(os.path.join(data_path, "secret_key")) as fn: with open(os.path.join(data_path, "secret_key")) as fn:
...@@ -113,3 +116,47 @@ def init_data_downloads(data_path, debug=False): ...@@ -113,3 +116,47 @@ def init_data_downloads(data_path, debug=False):
if debug is False: if debug is False:
# mk cache file # mk cache file
download_inst.store_cache_file() download_inst.store_cache_file()
def set_log_config(data_path):
dir_log = os.path.join(data_path, "logs")
os.makedirs(dir_log, exist_ok=True)
dictConfig(
{
"version": 1,
"formatters": {
"default": {
"format": "[%(asctime)s %(levelname)s] %(module)s: %(message)s",
"datefmt": "%d/%m/%Y %H:%M:%S",
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
},
"file": {
"class": "logging.FileHandler",
"filename": os.path.join(dir_log, "access"),
"formatter": "default"
},
"error_file": {
"class": "logging.FileHandler",
"filename": os.path.join(dir_log, "error.log"),
"formatter": "default"
},
},
"root": {
"level": "DEBUG",
"handlers": ["console", "file"]
},
"loggers": {
"errors": {
"level": "ERROR",
"handlers": ["error_file"],
"propagate": False,
}
},
}
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment