Skip to main content

A logger util helper for Azure app insights and structured logging

Project description

Logger Utility

Included with the IT-Offboarding suite is a custom logger library located in ./lib/logger_utils.py that standardizes our logs and sends them to azure app insights. The library utilizes the native python logging library and functions similarly to the native library. When the class is initialized in our scripts, the logger library also logs all API call information automatically and sends them to Azure app insights.

To use

Requirements

opencensus-ext-azure

opencensus-ext-requests

Import the logger_utils.py library

<<<<<<< HEAD from it_eng_python_logger_utils.logger_utils import Logger_Helper logger = Logger_Helper("Logger_Test", "INFO") Set APPI_TOKEN to your app insights instrumentation key in your .env

Class initialization

When initializing our logger class, we have two parameters:

  1. logger_name string - this should be your app/job name
  2. basicConfig string - this should be the level of logs you wish to be displayed to console. Ex: If set to INFO or DEBUG (with debug being incredibly granular) all log messages no matter the level will be logged. If set to CRITICAL, only critical messages will be logged.
  3. send_to_azure boolean - defaulted to True. Sends your logs to Azure app insights. ======= from path.to.logger_utils import Logger_Helper logger = Logger_Helper("Logger_Test", <InsightsToken>, "INFO")

Class initialization

When initializing our logger class, we have three parameters and one optional:

  1. Logger_name :required string - this should be your app/job name
  2. App insights token :required - Your instrementation key only if you pass the string you will receive an exception.
  3. Level :required string - this should be the level of logs you wish to be displayed to console. Ex: If set to INFO or DEBUG (with debug being incredibly granular) all log messages no matter the level will be logged. If set to CRITICAL, only critical messages will be logged.
  4. Send_to_azure: optional boolean - defaulted to True. Sends your logs to Azure app insights.

dev-pypi

Method Parameters

example: logger.info('your message')

<<<<<<< HEAD

  1. message dict or string- the message you want to send to Azure app insights/logged in your app. =======
  2. message any - the message you want to send to Azure app insights/logged in your app.

dev-pypi

  1. structured boolean - defaulted to True. When set to True your messages will structure your log with a default JSON structure which includes information to signify what job the logs came from, the severity and message. The JSON structure allows us to parse Splunk and Azure app insights logs with more clarity and granularity by formatting everything by a JSON key/value. To enable the JSON log structure in splunk, update your jobs deployments/{job}.yaml to use JSON via fluentbit.io/parser: json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file it_eng_python_logger_utils_dev_pypi1-0.32.1.tar.gz.

File metadata

File hashes

Hashes for it_eng_python_logger_utils_dev_pypi1-0.32.1.tar.gz
Algorithm Hash digest
SHA256 1851ee80582f0160f7c9961f723205c443ccfdbf41038d65f658ceee760a2ae8
MD5 67c4c7c78e236990ed493269cc44c389
BLAKE2b-256 4f8c74d4ff3c97afec80b49d609eec75ec96c1a218a6245548a7fce3bac80023

See more details on using hashes here.

File details

Details for the file it_eng_python_logger_utils_dev_pypi1-0.32.1-py3-none-any.whl.

File metadata

File hashes

Hashes for it_eng_python_logger_utils_dev_pypi1-0.32.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c37a16483050f5ab716ef2a8860f642e3f39d594e10fac74e52d1c33b72a6c7d
MD5 c95ce104344b7ab471b2a8080dca9e26
BLAKE2b-256 d791686e9a75a6943b4ef0e0762bfe4af84e52e7853e0d9a3fab7ca302b4beed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page