0

I have a function app hosted in Azure using linux consumption plan.I have written my code in python, so I can't host it on a windows platform.I want to write my logs into a separate file in a folder of a specific container.

This is my specific code block.

today = date.today()

logging.basicConfig(filename='https://invoicecompare.blob.core.windows.net/cont-invoicecompare/{}_logs.log'.format(today),
                filemode='a',
                format='%(asctime)s,%(msecs)d %(name)s %(message)s',
                datefmt='%H:%M:%S',
                level=logging.INFO,
                force=True)  

And this is the error I'm getting.

Result: Failure Exception: FileNotFoundError: [Errno 2] No such file or directory: '/home/site/wwwroot/https:/invoicecompare.blob.core.windows.net/cont-aacinvoicecompare/2023-04-10_logs.log' Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 357, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/loader.py", line 132, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "/home/site/wwwroot/BlobTrigger/init.py", line 17, in logging.basicConfig(filename='https://invoicecompare.blob.core.windows.net/cont-aacinvoicecompare/{}_logs.log'.format(today), File "/usr/local/lib/python3.9/logging/init.py", line 2003, in basicConfig h = FileHandler(filename, mode, File "/usr/local/lib/python3.9/logging/init.py", line 1146, in init StreamHandler.init(self, self._open()) File "/usr/local/lib/python3.9/logging/init.py", line 1175, in _open return open(self.baseFilename, self.mode, encoding=self.encoding,

I tried saving the log file into /temp folder.Then it gave no error.But I want to save the log file permanently. And I can't view the /temp folder or /home/site/wwwroot/ folder because under the development tab, the advanced tools tab can't be seen. see here

Here I found that Advanced Tools (Kudu) is currently not supported for Linux Consumption plans.

Can anyone please give me a solution for this?

My purpose: Save the logs into a file and access it later.

2
  • Adding third party dependencies is not supported in linux consumption plan. Implementing the same one is possible by creating and deploying through VScode instead. @Asu Commented Apr 11, 2023 at 4:17
  • I deployed the code through VS code.But the log file is not created when trying to create it in a container. Commented Apr 11, 2023 at 4:26

1 Answer 1

0

One way to achieve your requirements is to monitor azure function logs using Azure diagnostics.

I have added Azure diagnostics settings from diagnostic settings of Monitoring pane.

enter image description here

enter image description here

Then I tried to access the logs from Log Analytics workspace through logs using FunctionAppLogs query.

enter image description here

you can even export the results as below

enter image description here

However, you can get all logs by navigating to monitor >> Run query in Application Insights where in you can export the results too.

requests | project timestamp, id, operation_Name, success, resultCode, duration, operation_Id, cloud_RoleName, invocationId=customDimensions['InvocationId'] | where timestamp > ago(30d) | where cloud_RoleName =~ '<FuncAPp>' and operation_Name =~ 'HttpTrigger1' | order by timestamp desc | take 20

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Actually I want it as a code using python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.