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 included with package
opencensus-ext-azure
requests
opencensus-ext-requests
Quick set up (dev)
pip3 install it-eng-python-logger-utils-dev
Import the logger_utils.py library
from it_eng_python_logger_utils.logger_utils import LoggerHelper
logger = LoggerHelper("Logger_Test", <app_insights_token> or "", "INFO")
logger.info("Hello wurld!")
When deployed to moda we should be pulling the octofactory packe
octofactory package here
Contribute
- Make your changes (remember to update the version to
1.x.xin thesetup.py) - Build your package
make build - Bootstrap your package
make bootstrap - Test your package
python3 test/test.py - Be a good housekeeper
make cleanup - Upload your package
make upload - Username is
__token__, password is the token stored in 1password underAPI Token. - Test out your package by pulling from pypi
- Win
If you're getting a lot of installs from cache, an optional suggestion is to clear your pip cache so you know you're working with a fresh version install of the package and dependencies. But this is totally optional and only suggested if you're running into consitency issues.
To find your pip cache - pip3 cache dir
ex: rm -rf /Users/dinnermonster/Library/Caches/pip
Class instantiation
When initializing our logger class, we have three parameters and one optional:
- Logger_name :required
string- this should be your app/job name - Level :optional
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. - App insights token :optional
string- Your instrementation key only if you pass the connection string you will receive anexception. - Send_to_azure: optional
boolean- defaulted toTrue. Sends your logs to Azure app insights if you have an instrumentation key initilized.
Method Parameters
example: logger.info('your message')
- message
any- the message you want to send to Azure app insights/logged in your app. - 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
Troubleshooting
If you're not usre if your package is getting installed correct, you can check the package contents with: pip show -f <package>
Uninstall all packages
pip freeze | cut -d "@" -f1 | xargs pip uninstall -y
rm -rf /Users/dinnermonster/Library/Caches/pip
Project details
Release history Release notifications | RSS feed
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_pypi-1.5.0.tar.gz.
File metadata
- Download URL: it_eng_python_logger_utils_dev_pypi-1.5.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
445e4d170507f9dfce1002d4be80fce0fbbefc345fcaf3d4fc685ae643c30558
|
|
| MD5 |
382d8def167c31b59fb84ae4786357d1
|
|
| BLAKE2b-256 |
48cad27ac90450b1efab090fd7d0b11d9f53196c9f67ef86b7d2bce1fd7eab37
|
File details
Details for the file it_eng_python_logger_utils_dev_pypi-1.5.0-py3-none-any.whl.
File metadata
- Download URL: it_eng_python_logger_utils_dev_pypi-1.5.0-py3-none-any.whl
- Upload date:
- Size: 4.5 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 |
8351f4b82109aa0cc6d10d42e46e0f86d68696c11f111c6d41a0f9179d5fed4f
|
|
| MD5 |
26f0a09381662e6e395a02f001029bdc
|
|
| BLAKE2b-256 |
5e39ee991cca922b785d1e93cd865fd1fd9b23e961139a126966341133d37c38
|