diff --git a/src/ocrd_network/logging_utils.py b/src/ocrd_network/logging_utils.py index c201366424..2b9bffa1d0 100644 --- a/src/ocrd_network/logging_utils.py +++ b/src/ocrd_network/logging_utils.py @@ -9,11 +9,22 @@ def configure_file_handler_with_formatter(logger: Logger, log_file: Path, mode: file_handler = FileHandler(filename=log_file, mode=mode) file_handler.setFormatter(Formatter(LOG_FORMAT)) logger.addHandler(file_handler) + try: + log_file.chmod(0o666) + except PermissionError: + # if the file exists the permissions are supposed to already fit + pass def get_root_logging_dir(module_name: NetworkLoggingDirs) -> Path: module_log_dir = Path(config.OCRD_NETWORK_LOGS_ROOT_DIR, module_name.value) - module_log_dir.mkdir(parents=True, exist_ok=True) + try: + module_log_dir.mkdir(parents=True, exist_ok=True) + module_log_dir.chmod(0o777) + except PermissionError: + # if the folder exists the permissions are supposed to already fit + pass + return module_log_dir diff --git a/src/ocrd_utils/config.py b/src/ocrd_utils/config.py index d2a373f187..144c96859f 100644 --- a/src/ocrd_utils/config.py +++ b/src/ocrd_utils/config.py @@ -162,13 +162,23 @@ def _ocrd_download_timeout_parser(val): description="The root directory where all mets server related socket files are created", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_sockets"))) -config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(parents=True, exist_ok=True) +config.OCRD_NETWORK_SOCKETS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) +try: + config.OCRD_NETWORK_SOCKETS_ROOT_DIR.chmod(0o777) +except PermissionError: + # if the folder exists the permissions are supposed to already fit + pass config.add(name="OCRD_NETWORK_LOGS_ROOT_DIR", description="The root directory where all ocrd_network related file logs are stored", parser=lambda val: Path(val), default=(True, Path(gettempdir(), "ocrd_network_logs"))) -config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(parents=True, exist_ok=True) +config.OCRD_NETWORK_LOGS_ROOT_DIR.mkdir(mode=0o777, parents=True, exist_ok=True) +try: + config.OCRD_NETWORK_LOGS_ROOT_DIR.chmod(0o777) +except PermissionError: + # if the folder exists the permissions are supposed to already fit + pass config.add("HOME", description="Directory to look for `ocrd_logging.conf`, fallback for unset XDG variables.", diff --git a/src/ocrd_utils/logging.py b/src/ocrd_utils/logging.py index 6245f99b76..1f45ab72c5 100644 --- a/src/ocrd_utils/logging.py +++ b/src/ocrd_utils/logging.py @@ -34,6 +34,7 @@ import logging.config from pathlib import Path import sys +from os import chmod from .constants import LOG_FORMAT, LOG_TIMEFMT from .config import config @@ -179,6 +180,15 @@ def initLogging(builtin_only=False, force_reinit=False, silent=not config.OCRD_L if not silent: print(f"[LOGGING] Picked up logging config at {config_file}", file=sys.stderr) logging.config.fileConfig(config_file) + # Set permission of processing-server logfile to 666 to prevent possible permission erros while logging + try: + network_logger = logging.getLogger("ocrd_network") + for handler in network_logger.handlers: + if isinstance(handler, logging.FileHandler): + chmod(handler.baseFilename, 0o666) + except PermissionError: + # if the file exists the permissions are supposed to already fit + pass else: if not silent: print("[LOGGING] Initializing logging with built-in defaults", file=sys.stderr)