Posts

Showing posts from January, 2021

Write log entries to Azure App Insights

Image
  Images by Markus Spiske from pexels.com As an application developer, I write log entries so that I can monitor what operations that my application is performing, what exceptions are thrown, and the debugging statements to track potential problems in the code. When we are coding in Python , Python 's logging library is used. Log entries are written to the log files in my local filesystem when I am developing the code. And, I want to write them to Azure App Insights when my application is deployed. In this blog, we show how to write log to local filesystem (during development), and Azure App Insights (during production). The requirement is OpenCensus . So we need to install  opencensus-ext-azure . pip install opencensus-ext-azure I will name my Python module as example . I create a file, logger.py under example/logging folder. import logging import os from example.logging.appinsight_handle import AppInsightsHandle from example.logging.file_handle import FileHandle class Logg