Skip to content

Commit 20612a0

Browse files
authored
Merge pull request #612 from benjaminysmith/SirCAL
Add structured logging to SirCAL
2 parents 0525a97 + e9a69e2 commit 20612a0

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

_delphi_utils_python/delphi_utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .export import create_export_csv
88
from .utils import read_params
99

10+
from .logger import get_structured_logger
1011
from .geomap import GeoMapper
1112
from .smooth import Smoother
1213
from .signal import add_prefix, public_signal

sir_complainsalot/delphi_sir_complainsalot/check_source.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from dataclasses import dataclass
22
from typing import List
3+
from delphi_utils import get_structured_logger
34

45
import covidcast
56
import numpy as np
67
import pandas as pd
78

9+
logger = get_structured_logger(__name__)
10+
811
@dataclass
912
class Complaint:
1013
message: str
@@ -83,6 +86,14 @@ def check_source(data_source, meta, params, grace):
8386
# No gap detection for this source
8487
continue
8588

89+
logger.info("Retrieving signal",
90+
source=data_source,
91+
signal=row["signal"],
92+
start_day=(row["max_time"] -
93+
gap_window).strftime("%Y-%m-%d"),
94+
end_day=row["max_time"].strftime("%Y-%m-%d"),
95+
geo_type=row["geo_type"])
96+
8697
latest_data = covidcast.signal(
8798
data_source, row["signal"],
8899
start_day=row["max_time"] - gap_window,

sir_complainsalot/delphi_sir_complainsalot/run.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
when the module is run with `python -m delphi_sir_complainsalot`.
66
"""
77

8+
import logging
9+
import structlog
810
import sys
911

1012
from itertools import groupby
@@ -13,10 +15,12 @@
1315
from slack.errors import SlackApiError
1416

1517
from delphi_utils import read_params
18+
from delphi_utils import get_structured_logger
1619
import covidcast
1720

1821
from .check_source import check_source
1922

23+
logger = get_structured_logger(__name__)
2024

2125
def run_module():
2226

@@ -30,7 +34,12 @@ def run_module():
3034

3135
if len(complaints) > 0:
3236
for complaint in complaints:
33-
print(complaint)
37+
logger.critical(event="signal out of SLA",
38+
message=complaint.message,
39+
data_source=complaint.data_source,
40+
signal=complaint.signal,
41+
geo_types=complaint.geo_types,
42+
last_updated=complaint.last_updated.strftime("%Y-%m-%d"))
3443

3544
report_complaints(complaints, params)
3645

@@ -46,14 +55,14 @@ def split_complaints(complaints, n=49):
4655
def report_complaints(all_complaints, params):
4756
"""Post complaints to Slack."""
4857
if not params["slack_token"]:
49-
print("\b (dry-run)")
58+
logger.info("(dry-run)")
5059
return
5160

5261
client = WebClient(token=params["slack_token"])
5362

5463
for complaints in split_complaints(all_complaints):
5564
blocks = format_complaints_aggregated_by_source(complaints)
56-
print(f"blocks: {len(blocks)}")
65+
logger.info(f"blocks: {len(blocks)}")
5766
try:
5867
client.chat_postMessage(
5968
channel=params["channel"],

0 commit comments

Comments
 (0)