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.0.2.tar.gz (5.0 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.0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pdlogger-0.0.2.tar.gz
Algorithm Hash digest
SHA256 22e54c75a72a370f48dd36c4a0a67b4c2cebf201b5f1f0476ccae3e234c203b1
MD5 f016b0904556b3eed3778fa88d422809
BLAKE2b-256 691524d0e742a50da0a5dbec12de3c38a2620bc0f28242c359eec63114791c31

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pdlogger-0.0.2-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.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94fb1ad8e3e746b824b4a34632429a57f795bb94a2c8453c1fab7ea104d05187
MD5 93866f2e2a164d839c733a69a77141a7
BLAKE2b-256 39356ddba12c32644a387a7e67756fa8a6429b298c38a56525aa3995cc0b9003

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