| 354 | |
| 355 | |
| 356 | class LogNameCreator: |
| 357 | def __init__(self, filename_pattern=None, date_format=None) -> None: |
| 358 | self._date_format = date_format if date_format else '%y%m%d_%H%M%S' |
| 359 | if not filename_pattern: |
| 360 | filename_pattern = '${SCRIPT}_${AUDIT_NAME}_${DATE}' |
| 361 | self._filename_template = Template(filename_pattern) |
| 362 | |
| 363 | def create_filename(self, |
| 364 | execution_id, |
| 365 | all_audit_names, |
| 366 | script_name, |
| 367 | start_time, |
| 368 | custom_logging_config: Optional[LoggingConfig], |
| 369 | parameter_configs, |
| 370 | parameter_value_wrappers): |
| 371 | |
| 372 | audit_name = get_audit_name(all_audit_names) |
| 373 | audit_name = file_utils.to_filename(audit_name) |
| 374 | |
| 375 | date_string = ms_to_datetime(start_time).strftime(self._resolve_date_format(custom_logging_config)) |
| 376 | |
| 377 | username = audit_utils.get_audit_username(all_audit_names) |
| 378 | |
| 379 | mapping = { |
| 380 | 'ID': execution_id, |
| 381 | 'USERNAME': username, |
| 382 | 'HOSTNAME': get_first_existing(all_audit_names, audit_utils.PROXIED_HOSTNAME, audit_utils.HOSTNAME, |
| 383 | default='unknown-host'), |
| 384 | 'IP': get_first_existing(all_audit_names, audit_utils.PROXIED_IP, audit_utils.IP), |
| 385 | 'DATE': date_string, |
| 386 | 'AUDIT_NAME': audit_name, |
| 387 | 'SCRIPT': script_name |
| 388 | } |
| 389 | |
| 390 | filename = self._resolve_filename_template(custom_logging_config).safe_substitute(mapping) |
| 391 | filename = model_helper.fill_parameter_values(parameter_configs, filename, parameter_value_wrappers) |
| 392 | if not filename.lower().endswith('.log'): |
| 393 | filename += '.log' |
| 394 | |
| 395 | filename = filename.replace(" ", "_").replace("/", "_") |
| 396 | |
| 397 | return filename |
| 398 | |
| 399 | def _resolve_date_format(self, custom_logging_config: Optional[LoggingConfig]): |
| 400 | if custom_logging_config and custom_logging_config.date_format: |
| 401 | return custom_logging_config.date_format |
| 402 | return self._date_format |
| 403 | |
| 404 | def _resolve_filename_template(self, custom_logging_config: Optional[LoggingConfig]): |
| 405 | if custom_logging_config and custom_logging_config.filename_pattern: |
| 406 | return Template(custom_logging_config.filename_pattern) |
| 407 | return self._filename_template |
| 408 | |
| 409 | |
| 410 | class ExecutionLoggingController: |
no outgoing calls