diff --git a/jwst/stpipe/core.py b/jwst/stpipe/core.py index 02ae5eb92a..a450411cbb 100644 --- a/jwst/stpipe/core.py +++ b/jwst/stpipe/core.py @@ -3,6 +3,7 @@ """ from functools import wraps import logging +import time from stdatamodels.jwst.datamodels import JwstDataModel from stdatamodels.jwst import datamodels @@ -13,6 +14,12 @@ from .. import __version_commit__, __version__ from ..lib.suffix import remove_suffix +_LOG_FORMATTER = logging.Formatter( + "%(asctime)s.%(msecs)03d - %(name)s - %(levelname)s - %(message)s", + datefmt="%Y-%m-%dT%H:%M:%S", +) +_LOG_FORMATTER.converter = time.gmtime + log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) @@ -24,6 +31,8 @@ class JwstStep(Step): output_ext = string(default='.fits') # Output file type """ + _log_records_formatter = _LOG_FORMATTER + @classmethod def _datamodels_open(cls, init, **kwargs): return datamodels.open(init, **kwargs) @@ -91,6 +100,10 @@ def finalize_result(self, result, reference_files_used): if self.parent is None: log.info(f"Results used CRDS context: {result.meta.ref_file.crds.context_used}") + if hasattr(result, 'cal_logs'): + tmpdict = result.cal_logs.instance + tmpdict[self.class_alias] = '\n'.join(self._log_records) + result.cal_logs = tmpdict def remove_suffix(self, name): return remove_suffix(name) @@ -110,3 +123,12 @@ class JwstPipeline(Pipeline, JwstStep): def finalize_result(self, result, reference_files_used): if isinstance(result, JwstDataModel): log.info(f"Results used CRDS context: {crds_client.get_context_used(result.crds_observatory)}") + + if hasattr(result, 'cal_logs'): + tmpdict = result.cal_logs.instance + tmpdict[self.class_alias] = '\n'.join(self._log_records) + + for _, step in self.step_defs.items(): + if step.class_alias in tmpdict.keys(): + del tmpdict[step.class_alias] + result.cal_logs = tmpdict