Python logging to Azure

Deadly 提交于 2021-02-05 08:26:28

问题


I am using Python and I was wondering if there is any package/simple way for logging directly to Azure?

I found a package (azure-storage-logging) that would be really nice, however it is not being maintained and not compatible with the new Azure API.

Any help is welcome.


回答1:


You should use Application Insights which will send the logs to Azure Monitor (previously Log Analytics).

https://docs.microsoft.com/en-us/azure/azure-monitor/app/opencensus-python




回答2:


I had the same requirement to log error and debug messages for small application and store the logs to Azure data lake. We did not want to use Azure Insight as our was not a web application and we just needed logs to debug the code.

To solve this I created temp.log file.

logging.basicConfig(filename='temp.log', format='%(asctime)s  %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
    datefmt='%Y-%m-%d:%H:%M:%S')    

At the end of program I uploaded the temp.log to azure using,

DataLakeFileClient.append_data 

local_file = open("temp.log",'r')

file_contents = local_file.read()

file_client.append_data(data=file_contents, offset=0, length=len(file_contents))

file_client.flush_data(len(file_contents))

https://docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-python



来源:https://stackoverflow.com/questions/59074707/python-logging-to-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!