Skip to main content

An example package

Project description

pdlogger

pdlogger is a python based logger that let's you push your logging.info() calls to an AMQP queue.

Installation

pdlogger is available on pypi. Just do:

pip install pdlogger

Usage

Client application

Once you have installed pdlogger, setup the logger in the initial steps of your application by doing:

import logging
from pdlogger.Logging import AMQPLoggingHandler
from pdlogger.Logging import AMQPLogger
from pdlogger.Logging import EnvVarChecker


logging.setLoggerClass(AMQPLogger)
logger = logging.getLogger("pdlogs")
logger.setLevel(logging.INFO)
handler = AMQPLoggingHandler()
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

Then, in all other modules of your application, just do

import logging
logger = logging.getLogger('pdlogs')
logger.info(<your data here>)

You can either set AMQP_URL, QUEUE_NAME in the environment variables, or they can be passed to the AMQPLoggingHandler like:

AMQPLoggingHandler(amqp_url, queue_name, msg_priority)

logger.info takes the following arguments:

  • msg: Logs that you want to push. Anything that is JSON serializable goes.
  • project_id (Optional): Project ID. Can be left None. E.g. hf38fgf883fg3bs3
  • test_image_id (Optional): Test Image ID. Can be left None. E.g. 73184492
  • application_name (Optional): Application Name. Can be left None. E.g. all-in-1
  • checkpoint_name: Arbitrary string to keep track of where the log is coming from. E.g. opensetThreshApplied, otherRemoved.

Producer

You need atleast 1 consumer running to consume the logs. To run a consumer application, just run:

from pdlogger.Logging import AMQPConsumer
consumer = AMQPConsumer()
consumer.start_consuming()

You can either set AMQP_URL, QUEUE_NAME, SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_DATABASE in the environment variables, or they can be passed to the AMQPConsumer like:

AMQPConsumer(amqp_url, queue_name, sql_host, sql_user, sql_password, sql_database)

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

pdlogger-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdlogger-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file pdlogger-0.1.0.tar.gz.

File metadata

  • Download URL: pdlogger-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.10

File hashes

Hashes for pdlogger-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c21b3f7d0bc46974901ed0b29b1c3bf0c034ff85c5b90f4b1e8838e3c774764d
MD5 186326e033398c36f42c3223312bccf1
BLAKE2b-256 ae3db42b32bd3668a1e45365b49e70e855b9d27f3fec5d5ebeb9d8f6397b6c52

See more details on using hashes here.

File details

Details for the file pdlogger-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pdlogger-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.10

File hashes

Hashes for pdlogger-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84405bff8e951db2a67012b7251f09cafdf35dbb613f006a38b8ee094f16149c
MD5 9cb0260560a1d80f8b87bff481c7ab58
BLAKE2b-256 a35837e780be067c7e7698b0ac48265e1214c5a89fbfd06882ceafdcadf944de

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