Skip to main content

A logger util helper for Azure app insights and structured logging

Project description

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

Requirements included with package

opencensus-ext-azure requests opencensus-ext-requests

Contribute

  1. Make your changes (remember to update the version to 1.x.x in the setup.py)
  2. Build your package make build
  3. Bootstrap your package make bootstrap
  4. Test your package python3 test/test.py
  5. Be a good housekeeper make cleanup
  6. Upload your package make upload
  7. Test out your package by pulling from pypi
  8. 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/<user>/Library/Caches/pip

Class instantiation

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. Level :optional 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. App insights token :optional string- Your instrementation key only if you pass the connection string you will receive an exception.
  4. Send_to_azure: optional boolean - defaulted to True. Sends your logs to Azure app insights if you have an instrumentation key initilized.

Method Parameters

example: logger.info('your message')

  1. message any - the message you want to send to Azure app insights/logged in your app.
  2. 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

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


Download files

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

Source Distribution

it_eng_python_logger_utils_dev_pypi-1.6.0.tar.gz (4.0 kB view details)

Uploaded Source

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_pypi-1.6.0.tar.gz.

File metadata

File hashes

Hashes for it_eng_python_logger_utils_dev_pypi-1.6.0.tar.gz
Algorithm Hash digest
SHA256 b1f45693dc4b4d13f5617628d8c889c3d67092608de267edb34d67475a75f8a9
MD5 609a6ef4ffe0a98246210ae7758d12f4
BLAKE2b-256 e47ffcd4432a2159be4cc8a0046f15287fb16cc79485466d735122214313b6ee

See more details on using hashes here.

File details

Details for the file it_eng_python_logger_utils_dev_pypi-1.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for it_eng_python_logger_utils_dev_pypi-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9251b17d17e388a6870ef77b0a9f41322fdcb6ec81427745e6af3980e86832ed
MD5 e597568dac934541572272e6a3ecfe4d
BLAKE2b-256 ffad81812d17a895cee57155e044ccae92451289ed2f7aded587ef0efc3658cd

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