File tree Expand file tree Collapse file tree 3 files changed +12
-3
lines changed
Expand file tree Collapse file tree 3 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,6 @@ def _get_gtfs_feed(
137137 query = get_gtfs_feeds_query (
138138 db_session = db_session , stable_id = stable_id , include_options_for_joinedload = include_options_for_joinedload
139139 )
140- self .logger .debug ("Query: %s" , str (query .statement .compile (compile_kwargs = {"literal_binds" : True })))
141140 results = query .all ()
142141 if len (results ) == 0 :
143142 return None
Original file line number Diff line number Diff line change 1111from sqlalchemy .orm import sessionmaker
1212import logging
1313
14+ from utils .logger import get_env_logging_level
15+
1416
1517def generate_unique_id () -> str :
1618 """
@@ -99,14 +101,15 @@ def with_db_session(func=None, db_url: str | None = None):
99101 exception occurs, and closed in either case.
100102 - The session is then passed to the decorated function as the 'db_session' keyword argument.
101103 - If 'db_session' is already provided, it simply calls the decorated function with the existing session.
104+ - The echoed SQL queries will be logged if the environment variable LOGGING_LEVEL is set to DEBUG.
102105 """
103106 if func is None :
104107 return lambda f : with_db_session (f , db_url = db_url )
105108
106109 def wrapper (* args , ** kwargs ):
107110 db_session = kwargs .get ("db_session" )
108111 if db_session is None :
109- db = Database (feeds_database_url = db_url )
112+ db = Database (echo_sql = get_env_logging_level () == 'DEBUG' , feeds_database_url = db_url )
110113 with db .start_db_session () as session :
111114 kwargs ["db_session" ] = session
112115 return func (* args , ** kwargs )
Original file line number Diff line number Diff line change 11import asyncio
22import json
33import logging
4+ import os
45from dataclasses import dataclass
56from typing import Final , Optional
67
@@ -127,6 +128,12 @@ async def async_emit(self, record):
127128 self .logger .info (json .dumps (log_record .__dict__ ))
128129
129130
131+ def get_env_logging_level ():
132+ """
133+ Get the logging level from the environment via OS variable LOGGING_LEVEL. Returns INFO if not set.
134+ """
135+ return os .getenv ("LOGGING_LEVEL" , "INFO" )
136+
130137class Logger :
131138 """
132139 Util class for logging information, errors or warnings
@@ -143,7 +150,7 @@ def __init__(self, name):
143150
144151 self .logger = logging .getLogger (name )
145152 self .logger .addHandler (console_handler )
146- self .logger .setLevel (logging . DEBUG )
153+ self .logger .setLevel (get_env_logging_level () )
147154
148155 def get_logger (self ):
149156 """
You can’t perform that action at this time.
0 commit comments