Skip to main content

MoonHub.ai logging manager to push logs into GCP Cloud Logging

Project description

Logger

Purpose

This Logging Manager is to be used as a standardized system and structure to enable logging on different product offerings. We intend the logs to not only enable debugging platform exceptions, but to provide visibility, analytics and reporting on the health, engagement and usage of our products and systems.

How to use this Package in your Code

1. Install pip Package

execute following command to install pip package

python -m pip install mh-logger

2. Import and Use

Following is the sample code to use this package in your code. simply import and start logging.

from mh_logger import LoggingManager

logger = LoggingManager("TestLogger")


def test_logging_function():
    logger.info("this is a sample log", json_params={"hello", "world"})


test_logging_function()

Sample Stream Log Output:

2023-03-16 20:22:36,561 [INFO] - TestLogger: this is a sample log - JSON Payload: {'hello', 'world'}

Set following environment variable if you want to push logs to GCP Cloud Logging service while testing locally.

SERVICE_ACCOUNT_KEY_PATH=path-to-service-account-key-file\moonhub-search-66f471d68099.json

you can exclude unwanted keys from json payload by setting following environment variable. where each list index contains the name of key that needs to be excluded from json payload while logging.

EXCLUDE_KEYS=["query", "response"]

Steps to Create and Upload Package

1. Create Token (First Time Only)

  • Goto pypi.org and create your login
  • Go to api-tokens and create your API token to securely upload your packages.
  • Copy and save your token in a safe place on your disk.

2. Install Dependencies (First Time Only)

Install following

python -m pip install --upgrade build
python -m pip install --upgrade twine

3. Build Package

execute following command

python -m build

Once the process above is completed, a new directory is generated called dist/ with two files in it. The .tag.tz file is the source archive and the .whl* file is the built archive. These files represent the distribution archives of our Python package which will be uploaded to the Python Package Index and installed by pip in the following sections.

4. Check and Upload Package to PyPi Server

twine is a python package that goes through a checklist of items to see if your distribution/package is compatible for publishing.

Check if your distribution is all set to go .

execute following command to check distributions before upload

twine check dist/*

execute following command to upload latest distribution

twine upload --skip-existing --repository-url https://upload.pypi.org/legacy/ dist/*

MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

mh-logger-0.0.18.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

mh_logger-0.0.18-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file mh-logger-0.0.18.tar.gz.

File metadata

  • Download URL: mh-logger-0.0.18.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for mh-logger-0.0.18.tar.gz
Algorithm Hash digest
SHA256 c7f4d59e0d61b128668eb55c2cbd4d37dc34a875fc617b2ca954bfe385455752
MD5 1dc7c98f93da5054da2d78ff14c9bf50
BLAKE2b-256 4c88935a7fb041b8d4fc46d5185503905a42bdd50a735f8c93f5f0138fa12c2c

See more details on using hashes here.

File details

Details for the file mh_logger-0.0.18-py3-none-any.whl.

File metadata

  • Download URL: mh_logger-0.0.18-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for mh_logger-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 d51212be0b22462cd101347fb945bfd76e0edd46738dfb3aa7c511fa7c438b98
MD5 967c740b38a97518112c82d86650d9f4
BLAKE2b-256 7e3f1dcd2ee7c83108193cfd0ee023cbdac89ee1559863a60948d374c7587642

See more details on using hashes here.

Supported by

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