I have an Azure function where I tried multiple ways to write/log, my python script logs to an Azure blob.
However, I can’t seem to make it work, even the documentation leads to a dead end.
This question has been asked before, but it’s a bit outdated.
The azure-storage-logging package also seems deserted.
Here is some example code I use for testing different methods:
import logging
import azure.functions as func
app = func.FunctionApp()
@app.schedule(schedule="*/30 * * * *", arg_name="myTimer", run_on_startup=True,
use_monitor=False)
def func_demo_timer_trigger(myTimer: func.TimerRequest) -> None:
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function executed.')
How would I get this log message in to a blob?
Also, every run there is a log message it should be added to that same file.
(Application insights or related topics are not relevant).
Any tips and or small examples are welcome.
2
Answers
To log data to an Azure Blob Storage container from an Azure Function written in Python, one can use the
azure-storage-blob
library.Ensure that you have the
azure-functions
andazure-storage-blob
libraries installed.You can use below code to get required results:
requirements.txt:
Output:
In blob: