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:
- logger_name
string- this should be your app/job name - basicConfig
string- this should be the level of logs you wish to be displayed to console. Ex: If set toINFO or DEBUG(with debug being incredibly granular) all log messages no matter the level will be logged. If set toCRITICAL, only critical messages will be logged. - send_to_azure
boolean- defaulted toTrue. Sends your logs to Azure app insights. =======from path.to.logger_utils import Logger_Helperlogger = Logger_Helper("Logger_Test", <InsightsToken>, "INFO")
Class initialization
When initializing our logger class, we have three parameters and one optional:
- Logger_name :required
string- this should be your app/job name - App insights token :required - Your instrementation key only if you pass the string you will receive an
exception. - Level :required
string- this should be the level of logs you wish to be displayed to console. Ex: If set toINFO or DEBUG(with debug being incredibly granular) all log messages no matter the level will be logged. If set toCRITICAL, only critical messages will be logged. - Send_to_azure: optional
boolean- defaulted toTrue. Sends your logs to Azure app insights.
dev-pypi
Method Parameters
example: logger.info('your message')
<<<<<<< HEAD
- message
dictorstring- the message you want to send to Azure app insights/logged in your app. ======= - message
any- the message you want to send to Azure app insights/logged in your app.
dev-pypi
- structured
boolean- defaulted toTrue. When set toTrueyourmessageswill 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 jobsdeployments/{job}.yamlto use JSON viafluentbit.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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file it_eng_python_logger_utils_dev_pypi1-0.32.1.tar.gz.
File metadata
- Download URL: it_eng_python_logger_utils_dev_pypi1-0.32.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1851ee80582f0160f7c9961f723205c443ccfdbf41038d65f658ceee760a2ae8
|
|
| MD5 |
67c4c7c78e236990ed493269cc44c389
|
|
| BLAKE2b-256 |
4f8c74d4ff3c97afec80b49d609eec75ec96c1a218a6245548a7fce3bac80023
|
File details
Details for the file it_eng_python_logger_utils_dev_pypi1-0.32.1-py3-none-any.whl.
File metadata
- Download URL: it_eng_python_logger_utils_dev_pypi1-0.32.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c37a16483050f5ab716ef2a8860f642e3f39d594e10fac74e52d1c33b72a6c7d
|
|
| MD5 |
c95ce104344b7ab471b2a8080dca9e26
|
|
| BLAKE2b-256 |
d791686e9a75a6943b4ef0e0762bfe4af84e52e7853e0d9a3fab7ca302b4beed
|