Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove MultilineLogger, split logs with \n into multiple messages #1377

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 201 in romancal/associations/association.py

View check run for this annotation

Codecov / codecov/patch

romancal/associations/association.py#L200-L201

Added lines #L200 - L201 were not covered by tests
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 @@
VARIANCES = ("var_rnoise", "var_poisson", "var_flat")

if model.data.unit == model.meta.photometry.conversion_megajanskys.unit:
message = (
log.info(

Check warning on line 108 in romancal/flux/flux_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/flux/flux_step.py#L108

Added line #L108 was not covered by tests
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.")

Check warning on line 111 in romancal/flux/flux_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/flux/flux_step.py#L111

Added line #L111 was not covered by tests
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()]

Check warning on line 119 in romancal/flux/flux_step.py

View check run for this annotation

Codecov / codecov/patch

romancal/flux/flux_step.py#L119

Added line #L119 was not covered by tests
raise ValueError(message)

# Apply the correction.
Expand Down