I have a timer trigger function that downloads ml models. I want to log the name of these models an see this output in azure monitor . Below is an example of how I am using the logging library. This is just a snippet of code. For clarification the keys variable gets all the model names from a particular json file which I loaded earlier.
import datetime
import logging
import azure.functions as func
from azureml.core import Model
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
keys = model_file.keys()
logging.info("downloading the following models:")
for key in keys:
logging.info(key)
model_obj = Model(ws, key)
model_path = model_obj.download(target_dir=downloaded_models_path)
print(model_path)
logging.info(
"download_ml_models timer trigger function ran at %s", utc_timestamp)
I want the logs to display the actual info of the models I have logged. However, from below you can see azure monitor just displays the function was successfully executed
I tried below method to log the Downloaded model name in my TimerTrigger.
My init.py:-
Also, In your current code. Modify the logging line in your code to include the real names of the models you are downloading if you want to view this output in Azure Monitor. Simply replace the line
logging.info(key)
withlogging.info(f"downloading model: key")
. This will record the model's name as it is downloaded.