Skip to content

Commit

Permalink
getLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
tblanarik committed Nov 17, 2024
1 parent 18d6194 commit 276de84
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
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"])
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)
Expand Down
3 changes: 2 additions & 1 deletion spotbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down

0 comments on commit 276de84

Please sign in to comment.