Add hardering
This commit is contained in:
@@ -1,15 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from logging.handlers import RotatingFileHandler
|
||||
from pathlib import Path
|
||||
|
||||
_LOG_FILE_MODE = 0o644
|
||||
|
||||
|
||||
def _prepare_log_file(path: Path) -> None:
|
||||
"""Crée le fichier de log s'il n'existe pas et fixe ses permissions à 644."""
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not path.exists():
|
||||
path.touch()
|
||||
os.chmod(path, _LOG_FILE_MODE)
|
||||
|
||||
|
||||
def setup_logging(log_file: Path) -> logging.Logger:
|
||||
logger = logging.getLogger("securecheck")
|
||||
if logger.handlers:
|
||||
return logger
|
||||
|
||||
_prepare_log_file(log_file)
|
||||
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.propagate = False
|
||||
formatter = logging.Formatter(
|
||||
@@ -24,6 +37,8 @@ def setup_logging(log_file: Path) -> logging.Logger:
|
||||
|
||||
|
||||
def attach_run_handler(logger: logging.Logger, run_log_file: Path) -> RotatingFileHandler:
|
||||
_prepare_log_file(run_log_file)
|
||||
|
||||
formatter = logging.Formatter(
|
||||
fmt="%(asctime)s | %(levelname)s | %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
|
||||
Reference in New Issue
Block a user