Skip to main content

Wrapper of Logging module for handling database and middlerware scenarios

Project description

Ctlogging

Middleware for loading or generating correlation IDs for each run. Correlation IDs can be added to your logs, making it simple to retrieve all logs generated from a single run.

It also help in logging message in mysql database

When the process starts a correlation ID is set in the contextvar and retrieve using the filter during logging and inject into log record.

1. How to install

Using pip

pip install ctlogging

Using poetry

poetry add ctlogging

2. How to use

There are main three step requires -

  • Initalize the logger at starting point of application

    from ctlogging.config import set_logger_from_yaml, set_logger
    
    logger = set_logger_from_yaml(logconfig_yaml) # using file
    logger = set_logger(config) # using dict
    
  • get logger at module/file level and start logging using logger built-in method

    from ctlogging.config import get_logger
    
    logger = get_logger(__name__)
    logger.info(message...)
    logger.debug(message...)
    
  • for correlation_id, set it at entry level of pipeline

    from uuid import uuid4
    from ctlogging.context import correlation_id
    
    def pipeline():
        uid = uuid4().hex
        correlation_id.set(uid) # uid is string
        "do task....."
    

3. Configuration

using config.yaml file

version: 1
formatters:
  simple:
    format: '%(asctime)s - %(correlation_id)s - %(levelname)s - %(name)s - %(message)s'
filters:
  correlation_id:
    (): ctlogging.CorrelationId
handlers:
  console:
    class: logging.StreamHandler
    level: DEBUG
    formatter: simple
    filters: [correlation_id]
    stream: ext://sys.stdout
  file:
    class : logging.handlers.RotatingFileHandler
    formatter: simple
    filename: extraction.log
    maxBytes: 3000000
    backupCount: 3
    filters: [correlation_id]
  db:
    class : ctlogging.MysqlHandler
    level: DEBUG
    host: localhost
    database: ares
    user: root
    password: root
    port: 3306
loggers:
  root:
    level: DEBUG
    handlers: [console, db]
    propagate: true
root_logger_name: root

3. for Developement

Steps: -

  1. git clone the repo
  2. install poetry from https://python-poetry.org/docs/master/#installing-with-the-official-installer
  3. goto ctlogging directory
  4. poetry install

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

ctlogging-0.1.3.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

ctlogging-0.1.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file ctlogging-0.1.3.tar.gz.

File metadata

  • Download URL: ctlogging-0.1.3.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Windows/10

File hashes

Hashes for ctlogging-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a84651e4e6bef189e1a4fec5578f01bc29c5be96f897c1720bbcb1e837c30d00
MD5 ba3a8180ef71701db32b73f438f3c956
BLAKE2b-256 34458005bed64755b318e351aa4963d7d6c42071c8dfa366e702f2be537b83ba

See more details on using hashes here.

File details

Details for the file ctlogging-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ctlogging-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.10 Windows/10

File hashes

Hashes for ctlogging-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f9ac789c077825ba702b1f91ee9d648a3fe63b253730801be124a579355fd149
MD5 77ca82dea32adf6b3121337645c59c61
BLAKE2b-256 442f323e5cb194af3a94efe523cedc7d1e0ca5a9e88aa8525aba0707469b8b2d

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