Skip to content

Commit

Permalink
remove MultilineLogger, split logs with \n into multiple messages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Oct 1, 2024
2 parents 8f72709 + a20997e commit b652ef8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
3 changes: 2 additions & 1 deletion romancal/associations/association.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def validate(cls, asn):
try:
jsonschema.validate(asn_data, asn_schema)
except (AttributeError, jsonschema.ValidationError) as err:
logger.debug("Validation failed:\n%s", err)
logger.debug("Validation failed:")
logger.debug("%s", err)
raise AssociationNotValidError("Validation failed") from err
return True

Expand Down
2 changes: 1 addition & 1 deletion romancal/associations/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def generate(pool, rules, version_id=None, finalize=True):
logger.debug("New process lists: %d", total_reprocess)
logger.debug("Updated process queue: %s", process_queue)
logger.debug("# associations: %d", len(associations))
logger.debug("Seconds to process: %.2f\n", timer() - time_start)
logger.debug("Seconds to process: %.2f", timer() - time_start)

# Finalize found associations
logger.debug("# associations before finalization: %d", len(associations))
Expand Down
23 changes: 0 additions & 23 deletions romancal/associations/lib/log_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import sys
from collections import defaultdict
from functools import partialmethod
from logging.config import dictConfig

__all__ = ["log_config"]
Expand Down Expand Up @@ -130,28 +129,6 @@ def format(self, record):
}


class MultilineLogger(logging.getLoggerClass()):
"""Split multilines so that each line is logged separately"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def log(self, level, msg, *args, **kwargs):
if self.isEnabledFor(level):
for line in msg.split("\n"):
self._log(level, line, args, **kwargs)

debug = partialmethod(log, logging.DEBUG)
info = partialmethod(log, logging.INFO)
warning = partialmethod(log, logging.WARNING)
error = partialmethod(log, logging.ERROR)
critical = partialmethod(log, logging.CRITICAL)
fatal = critical


logging.setLoggerClass(MultilineLogger)


def log_config(name=None, user_name=None, logger_config=None, config=None, merge=True):
"""Setup logging with defaults
Expand Down
7 changes: 3 additions & 4 deletions romancal/flux/flux_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,18 @@ def apply_flux_correction(model):
VARIANCES = ("var_rnoise", "var_poisson", "var_flat")

if model.data.unit == model.meta.photometry.conversion_megajanskys.unit:
message = (
log.info(
f"Input data is already in flux units of {model.meta.photometry.conversion_megajanskys.unit}."
"\nFlux correction already applied."
)
log.info(message)
log.info("Flux correction already applied.")
return

if model.data.unit != LV2_UNITS:
message = (
f"Input data units {model.data.unit} are not in the expected units of {LV2_UNITS}"
"\nAborting flux correction"
)
log.error(message)
[log.error(line) for line in message.splitlines()]
raise ValueError(message)

# Apply the correction.
Expand Down

0 comments on commit b652ef8

Please sign in to comment.