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
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.
Method Parameters
example: logger.info('your message')
- message
dict
orstring
- the message you want to send to Azure app insights/logged in your app. - structured
boolean
- defaulted toTrue
. When set toTrue
yourmessages
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 jobsdeployments/{job}.yaml
to 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
Hashes for it_eng_python_logger_utils_dev_pypi1-0.29.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e095bad58dbc835700abc10adf8cdfa053686e76f98e5cc069539499759ef6b6 |
|
MD5 | 8d21e5e25471c1a4bd7a77815c09f69f |
|
BLAKE2b-256 | 0c6995c823832d37a2fae8461aae808d41a79fdf057ddce2081e0e0265a6efd5 |
Hashes for it_eng_python_logger_utils_dev_pypi1-0.29.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 464d5e78f4b62481b8d670f8de3f39e5b59ee8937cbaaed728a326b13dc0ada9 |
|
MD5 | 49f1021f073f60996335ffe491556926 |
|
BLAKE2b-256 | 70c1a35bda127ff69d949591dc249139b62110728f97d9e5e0748e26b56c878a |