Skip to content

Commit 8cd68c4

Browse files
committed
Move logging config to logger module
1 parent bd92e5c commit 8cd68c4

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

clinvar_gk_pilot/gcs.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import logging
21
import queue
32
import subprocess
43
import threading
@@ -8,10 +7,9 @@
87
import requests
98
from google.cloud import storage
109

10+
from clinvar_gk_pilot.logger import logger
1111
from clinvar_gk_pilot.utils import make_progress_logger
1212

13-
_logger = logging.getLogger("clinvar_gk_pilot")
14-
1513

1614
def _get_gcs_client() -> storage.Client:
1715
if getattr(_get_gcs_client, "client", None) is None:
@@ -37,12 +35,12 @@ def copy_file_to_bucket(
3735
"""
3836
Upload the contents of file `local_file_uri` on local filesystem, to `remote_blob_uri` in
3937
"""
40-
_logger.info(f"Uploading {local_file_uri} to {remote_blob_uri}")
38+
logger.info(f"Uploading {local_file_uri} to {remote_blob_uri}")
4139
if client is None:
4240
client = _get_gcs_client()
4341
blob = parse_blob_uri(remote_blob_uri, client=client)
4442
blob.upload_from_filename(client=client, filename=local_file_uri)
45-
_logger.info(f"Finished uploading {local_file_uri} to {remote_blob_uri}")
43+
logger.info(f"Finished uploading {local_file_uri} to {remote_blob_uri}")
4644

4745

4846
def blob_writer(
@@ -89,15 +87,15 @@ def http_download_requests(
8987
"""
9088
Download the contents of `http_uri` to `local_path` using requests.get
9189
"""
92-
_logger.info(f"Downloading {http_uri} to {local_path}")
90+
logger.info(f"Downloading {http_uri} to {local_path}")
9391

9492
bytes_read = 0
9593
response = requests.get(http_uri, stream=True, timeout=10)
9694
response.raise_for_status()
9795
opened_file_size = int(response.headers.get("Content-Length"))
9896

9997
log_progress = make_progress_logger(
100-
logger=_logger,
98+
logger=logger,
10199
fmt="Read {elapsed_value} bytes in {elapsed:.2f} seconds. Total bytes read: {current_value}/{max_value}.",
102100
max_value=opened_file_size,
103101
)
@@ -118,7 +116,7 @@ def http_download_requests(
118116

119117
if len(chunk) == 0:
120118
wait_time = 10
121-
_logger.warning(
119+
logger.warning(
122120
f"Received an empty chunk from {http_uri} at byte {bytes_read}. Pausing {wait_time} seconds"
123121
)
124122
time.sleep(wait_time)
@@ -163,22 +161,21 @@ def file_stat(path: Path, q: queue.Queue):
163161
break
164162
except queue.Empty:
165163
if not path.exists():
166-
_logger.info(f"{path} does not exist")
164+
logger.info(f"{path} does not exist")
167165
else:
168-
_logger.info(f"{path} size: {path.stat().st_size}")
166+
logger.info(f"{path} size: {path.stat().st_size}")
169167
time.sleep(10)
170168

171169
t_stat_stop = queue.Queue()
172-
t_stat = threading.Thread(
173-
target=file_stat, args=(Path(local_path), t_stat_stop))
170+
t_stat = threading.Thread(target=file_stat, args=(Path(local_path), t_stat_stop))
174171
t_stat.start()
175172

176173
for _ in range(2):
177174
for pipe, line in iter(q.get, None):
178-
_logger.info(f"{pipe}: {line.decode('utf-8')}")
175+
logger.info(f"{pipe}: {line.decode('utf-8')}")
179176

180177
returncode = p.wait()
181-
_logger.info(f"curl return code: {returncode}")
178+
logger.info(f"curl return code: {returncode}")
182179

183180
t_stat_stop.put(None)
184181

clinvar_gk_pilot/main.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import argparse
22
import json
3-
import logging
43
import sys
54
from typing import List
65

76
import requests
87

9-
with open("log_conf.json", "r") as f:
10-
conf = json.load(f)
11-
logging.config.dictConfig(conf)
8+
from clinvar_gk_pilot.logger import logger
129

1310

1411
def parse_args(args: List[str]) -> dict:
@@ -63,4 +60,4 @@ def validate_response(resp):
6360

6461

6562
def main(argv=sys.argv):
66-
pass
63+
logger.info("Starting main")

0 commit comments

Comments
 (0)