Skip to main content

Logging handler module that writes the logs to Kusto database.

Project description

Log2Kusto

log2kusto is a Python logging handler library for saving the generated log records to a Kusto database table.

Installation

Use the package manager [pip](link will be updated) to install foobar.

pip install log2kusto

Requirments

  • Python logging library
  • An MS internal library for providing credentials to authenticate to Kusto (working on making it open source.)

Usage

import logging
from log2kusto.kusto_handler import KustoHandler

class CustomFormatter(logging.Formatter):
    def __init__(self, fmt=None, datefmt=None, style='%', validate=True, attributes_list=[]):
        super().__init__(fmt, datefmt, style, validate)
        self.attributes = attributes_list

    def format(self, record):
        print("in format")
        for attr in self.attributes:
            print(attr)
            if not hasattr(record, attr):
                setattr(record, attr, '')
        return super().format(record)

#https://docs.python.org/3/library/logging.html#logrecord-attributes
logrecord_attributes_list = ['asctime', 'levelname', 'filename', 'funcName', 'module', 'message']
custom_attributes_list = ['env', 'domain']
all_attributes_list = logrecord_attributes_list + custom_attributes_list
formatter = CustomFormatter('%(' + ((')s' + " ; " + '%(').join(all_attributes_list)) + ')s', "%Y-%m-%d %H:%M:%S", \
                            attributes_list=all_attributes_list)

kusto_handler = KustoHandler(<kusto cluster name>, <kusto database>, <kusto table name>, all_attributes_list)
kusto_handler.setLevel(logging.INFO)
kusto_handler.setFormatter(formatter)

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(kusto_handler)

d = {'env':'stage', 'domain':'xyz'}
while True:
    log = input("> ")
    if log.strip().lower() != "quit":
        logger.warn(log)
        logger.info(log, extra=d)
    else:
        break

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License
[MIT](https://choosealicense.com/licenses/mit/)

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

log2kusto-0.1.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

log2kusto-0.1.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: log2kusto-0.1.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for log2kusto-0.1.3.tar.gz
Algorithm Hash digest
SHA256 dd56e05a6e54e09e25a44f1b68949883db1532cc09c9d978f35c49e6fe2043a5
MD5 9ee95b4efa5f9cb8cb2d95794f11127b
BLAKE2b-256 6bc6ccdaed4ba6eef4c9c8aa4a240c7860b56ccf3abb5723b7ad0d2ea470955e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: log2kusto-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for log2kusto-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0b3ab4bc6bc2b6fd29f15b5c2bf56ab6656771b7b248df5ff3cba1dfdc08a343
MD5 23573c31bb71b72c51c75ded1d3c4f92
BLAKE2b-256 96cb9c0be392fe7d3413b4194316b7b07bb81452d87bf545f626e168ef4a2832

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