diff --git a/app.py b/app.py index 65d94d6..aa34891 100644 --- a/app.py +++ b/app.py @@ -5,9 +5,9 @@ import tables import discord_http from azure.monitor.opentelemetry import configure_azure_monitor -from opentelemetry import trace app = Flask(__name__) -configure_azure_monitor() +configure_azure_monitor(logger_name="spotbot") +logger = logging.getLogger("spotbot") endpoint = os.environ.get('SECRET_ENDPOINT') @app.route(f'/{endpoint}', methods=["POST"]) @@ -15,7 +15,7 @@ def run(): try: sb.SpotBot(request, tables.HamAlertTable(), discord_http.DiscordHttp()).process() except Exception as _excpt: - logging.error(f"Exception occurred: {_excpt}") + logger.error(f"Exception occurred: {_excpt}") return make_response(f"Exception occurred: {_excpt}", 500) else: return make_response("Accepted", 202) diff --git a/spotbot.py b/spotbot.py index d85fbf4..66a532a 100644 --- a/spotbot.py +++ b/spotbot.py @@ -9,9 +9,10 @@ def __init__(self, http_req, table, discord_http): self.ham = HamAlertMessage(http_req.get_json()) self.table = table self.discord_http = discord_http + self.logger = logging.getLogger("spotbot") def process(self): - logging.info('Processing HamAlert message') + self.logger.info('Processing HamAlert message') previous_message, message_id = self.get_last_message() if previous_message: previous_message = self.strikethrough_mesage(previous_message) diff --git a/tables.py b/tables.py index 83ce344..1d7cb82 100644 --- a/tables.py +++ b/tables.py @@ -9,6 +9,7 @@ def __init__(self): table_name = os.getenv('TABLE_NAME') table_service_client = TableServiceClient.from_connection_string(conn_str=connection_string) self.table_client = table_service_client.get_table_client(table_name=table_name) + self.logger = logging.getLogger("spotbot") def initialize_table(self): connection_string = os.getenv('AzureWebJobsStorage') @@ -19,7 +20,7 @@ def initialize_table(self): def query_for_entity(self, callsign): entities = [ent for ent in self.table_client.query_entities(f"PartitionKey eq '{callsign}' and RowKey eq '{callsign}'")] if len(entities) > 0: - logging.info(f"Entity already exists for {callsign}") + self.logger.info(f"Entity already exists for {callsign}") return entities[0] if len(entities) > 0 else None def upsert_entity(self, callsign, messageId):