Skip to content
generated from ansys/template

Library that defines a Python logger that can be used in the Microsoft.Extensions.Logging framework.

License

Notifications You must be signed in to change notification settings

ansys/py-mel-logging

Repository files navigation

PyAnsys Microsoft Extensions Logging

PyAnsys Python MIT Black

About

This repository provides a Python module for using a Python logger with the Microsoft.Extensions.Logging framework.

PLEASE NOTE: this project is still a work in progress.

Project Overview

Intended for use with Python libraries that call into .Net code via pythonnet, this library allows for easy registration of a Python logging Handler into the .Net dependency injection framework.

Installation

The py-mel-logging package currently supports Python 3.8 through 3.10 on Windows and Linux. This package is not currently available on PyPI, but will be when it is ready for use. At that time you can install py-mel-logging with:

pip install py-mel-logging

Alternatively, install the latest from py-mel-logging GitHub via:

pip install git+https://github.com/pyansys/py-mel-logging.git

For a local "development" version, install with:

git clone https://github.com/pyansys/py-mel-logging.git
cd py-mel-logging
pip install poetry
poetry install

This creates a new virtual environment, which can be activated with

poetry shell

Documentation

TODO: link to the full sphinx documentation. py-mel-logging For building documentation, you can run the usual rules provided in the Sphinx Makefile, such as:

make -C doc/ html && your_browser_name doc/html/index.html

on Unix, or:

.\doc\make.bat html

on Windows. Make sure the required dependencies are installed with:

pip install -E docs

Usage

Use this library to register a logger in a .NET dependency injection system with the following:

... setup a Python logging handler ...
... setup .Net ...
>>> from py_mel_logging import create_logger_provider
>>> import Microsoft.Extensions.DependencyInjection as DependencyInjection
>>> from Python.Logging import PythonLoggerExtensions
>>> provider = create_logger_provider(logging.WARN, handler)
>>> sc = DependencyInjection.ServiceCollection()
>>> PythonLoggerExtensions.ConfigureServiceCollection(sc, provider)
>>> sp = DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(sc)
... use the ServiceProvider in your application setup ...

Testing

Dependencies required for testing can be installed via:

pip install -E test

The tests can then be run via pytest.

License

py-pacz is licensed under the MIT license.

About

Library that defines a Python logger that can be used in the Microsoft.Extensions.Logging framework.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published