Commit 69a9ba4d authored by shadMod's avatar shadMod 💬

added GroupWritableTimedRotatingFileHandler()

replaced FileHandler with GroupWritableTimedRotatingFileHandler (as requested)
parent 13a78762
Pipeline #364 passed with stage
in 0 seconds
......@@ -16,8 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import flask
import logging.handlers
from . import actions
from . import auth
......@@ -45,7 +45,7 @@ def create_app(data_path, debug=False):
# Prepare the data directory
init_data_directory(data_path)
set_log_config(data_path)
set_log_config(data_path, debug)
# Load the secret key
with open(os.path.join(data_path, "secret_key")) as fn:
......@@ -118,32 +118,52 @@ def init_data_downloads(data_path, debug=False):
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)
class GroupWritableTimedRotatingFileHandler(
logging.handlers.TimedRotatingFileHandler
):
"""
TimedRotatingFileHandler that creates group writable files
"""
def _open(self):
orig_umask = os.umask(0o002)
try:
return super()._open()
finally:
os.umask(orig_umask)
logging.handlers.GroupWritableTimedRotatingFileHandler = (
GroupWritableTimedRotatingFileHandler
)
def set_log_config(data_path: str, debug: bool = False):
DIR_LOG = os.path.join(data_path, "logs")
os.makedirs(DIR_LOG, exist_ok=True)
LOG_LEVEL = "DEBUG" if debug else "INFO"
dictConfig(
{
"version": 1,
"formatters": {
"default": {
"format": "[%(asctime)s %(levelname)s] %(module)s: %(message)s",
"datefmt": "%d/%m/%Y %H:%M:%S",
}
"format": "[%(asctime)s %(module)s] %(levelname)s: %(message)s",
"datefmt": "%d/%m/%Y %H:%M:%S"
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout",
"level": "WARNING",
"class": "logging.StreamHandler"
},
"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"),
"level": "INFO",
"class": "logging.handlers.GroupWritableTimedRotatingFileHandler",
"filename": os.path.join(DIR_LOG, "log"),
"when": "midnight",
"backupCount": 7,
"formatter": "default"
},
},
......@@ -152,10 +172,9 @@ def set_log_config(data_path):
"handlers": ["console", "file"]
},
"loggers": {
"errors": {
"level": "ERROR",
"handlers": ["error_file"],
"propagate": False,
"uitwww": {
"level": LOG_LEVEL,
"handlers": ["file"]
}
},
}
......
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