Skip to content

Commit

Permalink
Change logging to self.log
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmartradio committed Feb 16, 2024
1 parent 6451895 commit e9dad4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
4 changes: 0 additions & 4 deletions python/lsst/ap/association/diaPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import numpy as np
import pandas as pd
import logging

from lsst.daf.base import DateTime
import lsst.dax.apdb as daxApdb
Expand All @@ -51,9 +50,6 @@
PackageAlertsTask)
from lsst.ap.association.ssoAssociation import SolarSystemAssociationTask

_log = logging.getLogger("lsst." + __name__)
_log.setLevel(logging.DEBUG)


class DiaPipelineConnections(
pipeBase.PipelineTaskConnections,
Expand Down
24 changes: 8 additions & 16 deletions python/lsst/ap/association/packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
from lsst.utils.timer import timeMethod
import fastavro

"""Methods for packaging Apdb and Pipelines data into Avro alerts.
"""

_log = logging.getLogger("lsst." + __name__)
_log.setLevel(logging.DEBUG)


class PackageAlertsConfig(pexConfig.Config):
"""Config class for AssociationTask.
Expand All @@ -71,13 +65,13 @@ class PackageAlertsConfig(pexConfig.Config):

doProduceAlerts = pexConfig.Field(
dtype=bool,
doc="Turn on alert production to kafka if true. Set to false by default",
doc="Turn on alert production to kafka if true and if confluent_kafka is in the environment.",
default=False,
)

doWriteAlerts = pexConfig.Field(
dtype=bool,
doc="Write alerts to disk if true. Set to true by default",
doc="Write alerts to disk if true.",
default=True,
)

Expand All @@ -94,7 +88,6 @@ def __init__(self, **kwargs):
super().__init__(**kwargs)
self.alertSchema = alertPack.Schema.from_uri(self.config.schemaFile)
os.makedirs(self.config.alertWriteLocation, exist_ok=True)

if self.config.doProduceAlerts:

self.password = os.getenv("AP_KAFKA_PRODUCER_PASSWORD")
Expand Down Expand Up @@ -127,10 +120,9 @@ def __init__(self, **kwargs):
from confluent_kafka import KafkaException
self.kafka_exception = KafkaException
import confluent_kafka
except ImportError as error:
error.add_note("Could not import confluent_kafka. Alerts will not be sent "
"to the alert stream")
_log.error(error)
except ImportError as e:
e.add_note("Alerts will not be sent to the alert stream.")
self.log.error(e)

if not self.password:
raise ValueError("Kafka password environment variable was not set.")
Expand Down Expand Up @@ -278,7 +270,7 @@ def produceAlerts(self, alerts, ccdVisitId):
self.producer.flush()

except self.kafka_exception as e:
_log.error('Kafka error: {}, message was {} bytes'.format(e, sys.getsizeof(alert_bytes)))
self.log.error('Kafka error: {}, message was {} bytes'.format(e, sys.getsizeof(alert_bytes)))

with open(os.path.join(self.config.alertWriteLocation,
f"{ccdVisitId}_{alert['alertId']}.avro"), "wb") as f:
Expand Down Expand Up @@ -567,7 +559,7 @@ def _deserialize_confluent_wire_header(raw):

def _delivery_callback(self, err, msg):
if err:
_log.debug('%% Message failed delivery: %s\n' % err)
self.log.debug('%% Message failed delivery: %s\n' % err)
else:
_log.debug('%% Message delivered to %s [%d] @ %d\n' %
self.log.debug('%% Message delivered to %s [%d] @ %d\n' %
(msg.topic(), msg.partition(), msg.offset()))

Check failure on line 565 in python/lsst/ap/association/packageAlerts.py

View workflow job for this annotation

GitHub Actions / call-workflow / lint

E128

continuation line under-indented for visual indent

0 comments on commit e9dad4b

Please sign in to comment.