Skip to content

Commit 1011c7d

Browse files
authored
Make sure logger.getLogger() is used instead of logging directly via logging.debug() (#91)
Ensures that anywhere that `prymer` logs it is using a non-root logger.
1 parent 8c39970 commit 1011c7d

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

prymer/api/picking.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from individual left and primers.
1717
1818
"""
19+
1920
from collections.abc import Sequence
2021
from pathlib import Path
2122
from typing import Iterator

prymer/api/variant_lookup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
from prymer.api.span import Span
8181
from prymer.api.span import Strand
8282

83+
_logger = logging.getLogger(__name__)
84+
8385

8486
@unique
8587
class VariantType(UppercaseStrEnum):
@@ -282,7 +284,7 @@ def query(
282284

283285
variants = self._query(refname=refname, start=start, end=end)
284286
if len(variants) == 0:
285-
logging.debug(f"No variants extracted from region of interest: {refname}:{start}-{end}")
287+
_logger.debug(f"No variants extracted from region of interest: {refname}:{start}-{end}")
286288
if maf is None or maf <= 0.0:
287289
return variants
288290
elif include_missing_mafs: # return variants with a MAF above threshold or missing
@@ -311,7 +313,7 @@ def to_variants(
311313
): # if passing or empty filters
312314
simple_variants = SimpleVariant.build(variant)
313315
if any(v.variant_type == VariantType.OTHER for v in simple_variants):
314-
logging.debug(
316+
_logger.debug(
315317
f"Input VCF file {source_vcf} may contain complex variants: {variant}"
316318
)
317319
simple_vars.extend(simple_variants)
@@ -372,7 +374,7 @@ def _query(self, refname: str, start: int, end: int) -> list[SimpleVariant]:
372374
simple_variants: list[SimpleVariant] = []
373375
for fh, path in zip(self._readers, self.vcf_paths, strict=True):
374376
if not fh.header.contigs.get(refname):
375-
logging.debug(f"Header in VCF file {path} does not contain chromosome {refname}.")
377+
_logger.debug(f"Header in VCF file {path} does not contain chromosome {refname}.")
376378
continue
377379
# pysam.fetch is 0-based, half-open
378380
variants = [variant for variant in fh.fetch(contig=refname, start=start - 1, end=end)]

prymer/primer3/primer3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def close(self) -> bool:
268268
self._fasta.close()
269269
subprocess_close = super().close()
270270
if not subprocess_close:
271-
logging.debug("Did not successfully close underlying subprocess")
271+
logging.getLogger(__name__).debug("Did not successfully close underlying subprocess")
272272
return subprocess_close
273273

274274
def get_design_sequences(self, region: Span) -> tuple[str, str]:

prymer/primer3/primer3_failure_reason.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def parse_failures(
112112
continue
113113
std_reason = Primer3FailureReason.from_reason(reason)
114114
if std_reason is None:
115-
logging.debug(f"Unknown Primer3 failure reason: {reason}")
115+
logging.getLogger(__name__).debug(f"Unknown Primer3 failure reason: {reason}")
116116
by_fail_count[std_reason] += count
117117

118118
return by_fail_count

prymer/util/executable_runner.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def __init__(
7070
)
7171

7272
def __enter__(self) -> Self:
73-
logging.debug(f"Initiating {self._name} with the following params: {self._command}")
73+
logging.getLogger(__name__).debug(
74+
f"Initiating {self._name} with the following params: {self._command}"
75+
)
7476
return self
7577

7678
def __exit__(
@@ -142,15 +144,17 @@ def close(self) -> bool:
142144
True: if the subprocess was terminated successfully
143145
False: if the subprocess failed to terminate or was not already running
144146
"""
147+
log = logging.getLogger(__name__)
148+
145149
if self.is_alive:
146150
self._subprocess.terminate()
147151
self._subprocess.wait(timeout=10)
148152
if not self.is_alive:
149-
logging.debug("Subprocess terminated successfully.")
153+
log.debug("Subprocess terminated successfully.")
150154
return True
151155
else:
152-
logging.debug("Subprocess failed to terminate.")
156+
log.debug("Subprocess failed to terminate.")
153157
return False
154158
else:
155-
logging.debug("Subprocess is not running.")
159+
log.debug("Subprocess is not running.")
156160
return False

0 commit comments

Comments
 (0)