Skip to content

Commit 11b115b

Browse files
authored
chore: improve logs on operations api (#1220)
1 parent b4ec3b1 commit 11b115b

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,24 @@
4848
)
4949
from .request_validator import validate_request
5050

51-
logging.basicConfig(level=logging.INFO)
52-
5351

5452
class OperationsApiImpl(BaseOperationsApi):
5553
"""Implementation of the operations API."""
5654

5755
def process_feed(self, feed) -> GtfsFeedResponse | GtfsRtFeedResponse:
5856
"""Process a feed into the appropriate response type using fromOrm methods."""
59-
logging.info(f"Processing feed {feed.stable_id} with type {feed.data_type}")
57+
logging.debug("Processing feed %s with type %s", feed.stable_id, feed.data_type)
6058

6159
if feed.data_type == "gtfs":
6260
result = GtfsFeedImpl.from_orm(feed)
63-
logging.info(f"Successfully processed GTFS feed {feed.stable_id}")
61+
logging.debug("Successfully processed GTFS feed %s", feed.stable_id)
6462
return result
6563
elif feed.data_type == "gtfs_rt":
6664
result = GtfsRtFeedImpl.from_orm(feed)
67-
logging.info(f"Successfully processed GTFS-RT feed {feed.stable_id}")
65+
logging.debug("Successfully processed GTFS-RT feed %s", feed.stable_id)
6866
return result
6967

68+
logging.error("Unsupported feed type: %s", feed.data_type)
7069
raise ValueError(f"Unsupported feed type: {feed.data_type}")
7170

7271
@with_db_session
@@ -188,8 +187,9 @@ async def _update_feed(
188187
)
189188

190189
logging.info(
191-
f"Feed ID: {update_request_feed.id} attempting to update with the following request: "
192-
f"{update_request_feed}"
190+
"Feed ID: %s attempting to update with the following request: %s",
191+
update_request_feed.id,
192+
update_request_feed,
193193
)
194194
impl_class = (
195195
UpdateRequestGtfsFeedImpl
@@ -207,22 +207,23 @@ async def _update_feed(
207207
db_session.flush()
208208
refreshed = refresh_materialized_view(db_session, t_feedsearch.name)
209209
logging.info(
210-
f"Materialized view {t_feedsearch.name} refreshed: {refreshed}"
210+
"Materialized view %s refreshed: %s", t_feedsearch.name, refreshed
211211
)
212212
db_session.commit()
213213
logging.info(
214-
f"Feed ID: {update_request_feed.id} updated successfully with the following changes: "
215-
f"{diff.values()}"
214+
"Feed ID: %s updated successfully with the following changes: %s",
215+
update_request_feed.id,
216+
diff.values(),
216217
)
217218
return Response(status_code=200)
218219
else:
219220
logging.info(
220-
f"No changes detected for feed ID: {update_request_feed.id}"
221+
"No changes detected for feed ID: %s", update_request_feed.id
221222
)
222223
return Response(status_code=204)
223224
except Exception as e:
224225
logging.error(
225-
f"Failed to update feed ID: {update_request_feed.id}. Error: {e}"
226+
"Failed to update feed ID: %s. Error: %s", update_request_feed.id, e
226227
)
227228
if isinstance(e, HTTPException):
228229
raise e

functions-python/operations_api/src/feeds_operations/impl/models/basic_feed_impl.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import logging
2-
31
from feeds_operations.impl.models.external_id_impl import ExternalIdImpl
42
from feeds_operations.impl.models.location_impl import LocationImpl
53
from feeds_operations.impl.models.redirect_impl import RedirectImpl
64
from feeds_operations_gen.models.base_feed import BaseFeed
75
from feeds_operations_gen.models.source_info import SourceInfo
86
from shared.database_gen.sqlacodegen_models import Feed
97

10-
logger = logging.getLogger(__name__)
11-
128

139
class BaseFeedImpl(BaseFeed):
1410
"""Base implementation of the feeds models."""

functions-python/operations_api/src/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import asyncio
2222

2323
from middleware.request_context_middleware import RequestContextMiddleware
24-
from shared.helpers.logger import Logger
24+
from shared.helpers.logger import init_logger
2525

26-
Logger.init_logger()
26+
init_logger()
2727

2828
app = FastAPI(
2929
title="Mobility Database Catalog Operations",

functions-python/operations_api/src/middleware/request_context_middleware.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# limitations under the License.
1515
#
1616

17-
import logging
1817
from starlette.types import ASGIApp, Receive, Scope, Send
1918

2019
from middleware.request_context_oauth2 import (
@@ -29,7 +28,6 @@ class RequestContextMiddleware:
2928
"""
3029

3130
def __init__(self, app: ASGIApp) -> None:
32-
self.logger = logging.getLogger()
3331
self.app = app
3432

3533
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:

functions-python/operations_api/src/middleware/request_context_oauth2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def validate_token_with_google(token: str, google_client_id: str) -> dict:
4444
try:
4545
response = get_tokeninfo_response(token)
4646
except Exception as e:
47-
logging.error(f"Token validation failed: {e}")
47+
logging.error("Token validation failed: %s", e)
4848
raise HTTPException(status_code=500, detail="Token validation failed")
4949

5050
if response.status_code != 200:

0 commit comments

Comments
 (0)