1
|
|
|
from logging import FileHandler, Formatter, Logger |
2
|
|
|
from pathlib import Path |
3
|
|
|
|
4
|
|
|
from ocrd_utils import config, LOG_FORMAT, safe_filename |
5
|
|
|
from .constants import AgentType, NetworkLoggingDirs |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
def configure_file_handler_with_formatter(logger: Logger, log_file: Path, mode: str = "a") -> None: |
9
|
|
|
file_handler = FileHandler(filename=log_file, mode=mode) |
10
|
|
|
file_handler.setFormatter(Formatter(LOG_FORMAT)) |
11
|
|
|
logger.addHandler(file_handler) |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def get_root_logging_dir(module_name: NetworkLoggingDirs) -> Path: |
15
|
|
|
module_log_dir = Path(config.OCRD_NETWORK_LOGS_ROOT_DIR, module_name.value) |
16
|
|
|
module_log_dir.mkdir(parents=True, exist_ok=True) |
17
|
|
|
return module_log_dir |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
def get_cache_locked_pages_logging_file_path() -> Path: |
21
|
|
|
log_file: str = "cache_locked_pages.log" |
22
|
|
|
return Path(get_root_logging_dir(NetworkLoggingDirs.PROCESSING_SERVERS), log_file) |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
def get_cache_processing_requests_logging_file_path() -> Path: |
26
|
|
|
log_file: str = "cache_processing_requests.log" |
27
|
|
|
return Path(get_root_logging_dir(NetworkLoggingDirs.PROCESSING_SERVERS), log_file) |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
def get_mets_server_logging_file_path(mets_path: str) -> Path: |
31
|
|
|
log_file: str = f"{safe_filename(mets_path)}.log" |
32
|
|
|
return Path(get_root_logging_dir(NetworkLoggingDirs.METS_SERVERS), log_file) |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def get_processing_job_logging_file_path(job_id: str) -> Path: |
36
|
|
|
log_file: str = f"{job_id}.log" |
37
|
|
|
return Path(get_root_logging_dir(NetworkLoggingDirs.PROCESSING_JOBS), log_file) |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
def get_processing_server_logging_file_path(pid: int) -> Path: |
41
|
|
|
log_file: str = f"processing_server.{pid}.log" |
42
|
|
|
return Path(get_root_logging_dir(NetworkLoggingDirs.PROCESSING_SERVERS), log_file) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
def get_processing_worker_logging_file_path(processor_name: str, pid: int) -> Path: |
46
|
|
|
log_file: str = f"{AgentType.PROCESSING_WORKER}.{pid}.{processor_name}.log" |
47
|
|
|
return Path(get_root_logging_dir(NetworkLoggingDirs.PROCESSING_WORKERS), log_file) |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
def get_processor_server_logging_file_path(processor_name: str, pid: int) -> Path: |
51
|
|
|
log_file: str = f"{AgentType.PROCESSOR_SERVER}.{pid}.{processor_name}.log" |
52
|
|
|
return Path(get_root_logging_dir(NetworkLoggingDirs.PROCESSOR_SERVERS), log_file) |
53
|
|
|
|