1
|
|
|
from os import makedirs |
2
|
|
|
from os.path import join |
3
|
|
|
from ocrd_utils import safe_filename |
4
|
|
|
|
5
|
|
|
OCRD_NETWORK_MODULES = [ |
6
|
|
|
"mets_servers", |
7
|
|
|
"processing_jobs", |
8
|
|
|
"processing_servers", |
9
|
|
|
"processing_workers", |
10
|
|
|
"processor_servers" |
11
|
|
|
] |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
def get_root_logging_dir(module_name: str) -> str: |
15
|
|
|
if module_name not in OCRD_NETWORK_MODULES: |
16
|
|
|
raise ValueError(f"Invalid module name: {module_name}, should be one of: {OCRD_NETWORK_MODULES}") |
17
|
|
|
# TODO: Utilize env variable to set the root |
18
|
|
|
module_log_dir = join("/tmp/ocrd_network_logs", module_name) |
19
|
|
|
makedirs(name=module_log_dir, exist_ok=True) |
20
|
|
|
return module_log_dir |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
def get_cache_locked_pages_logging_file_path() -> str: |
24
|
|
|
return join(get_root_logging_dir("processing_servers"), f"cache_locked_pages.log") |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
def get_cache_processing_requests_logging_file_path() -> str: |
28
|
|
|
return join(get_root_logging_dir("processing_servers"), f"cache_processing_requests.log") |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def get_processing_job_logging_file_path(job_id: str) -> str: |
32
|
|
|
return join(get_root_logging_dir("processing_jobs"), f"{job_id}.log") |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def get_processing_server_logging_file_path(pid: int) -> str: |
36
|
|
|
return join(get_root_logging_dir("processing_servers"), f"server.{pid}.log") |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
def get_processing_worker_logging_file_path(processor_name: str, pid: int) -> str: |
40
|
|
|
return join(get_root_logging_dir("processing_workers"), f"worker.{pid}.{processor_name}.log") |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
def get_processor_server_logging_file_path(processor_name: str, pid: int) -> str: |
44
|
|
|
return join(get_root_logging_dir("processor_servers"), f"server.{pid}.{processor_name}.log") |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
def get_mets_server_logging_file_path(mets_path: str) -> str: |
48
|
|
|
return join(get_root_logging_dir("mets_servers"), f"{safe_filename(mets_path)}.log") |
49
|
|
|
|