Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Readme
.. image:: https://travis-ci.org/AFriemann/mdc.svg?branch=master :target: https://travis-ci.org/AFriemann/mdc
This is thought to be an easy to use, import and go, library for Mapped Diagnostic Context style logging.
Logs should include all necessary fields collected by the python logging library. Helper methods are provided to add context fields where required.
NOTE 1.2.0
: recent changes will result in changed json output if using the MDCHandler
class:
.. code:: python
with MDC(foobar="baz"): ... logging.warning("test") { "message": "test", "foobar": "baz" }
this is a temporary solution to avoid breaking existing APIs. Please excuse any issues this might cause. In the future output handling should be done on the client side to avoid any possible breakage. The MDCHandler class will eventually be removed.
PyPi:
.. code:: bash
$ pip install --user mdc
From source:
.. code:: bash
$ pip install --user .
Add a handler to the root logger or set the base handler with logging.basicConfig:
.. code:: python
import logging from mdc import MDCHandler
use the MDCHandler only
logging.basicConfig(level=logging.DEBUG, handlers=[MDCHandler()])
the MDC contextmanager
with MDC(foo='bar'): ... logging.warning('foobar') { ..., "mdc": { "foo": "bar" }, "extra": {}, ... }
the with_mdc decorator
@with_mdc(test='123') ... def foobar(ctx): ... logging.warning('some warning')
foobar() { ..., "mdc": { "test": "123" }, "extra": {}, ... }
logging with extra fields
logging.error('some error', extra=dict(foo='bar')) { ..., "mdc": {}, "extra": { "foo": "bar" }, ... }
By default log messages will include the following fields:
.. code:: json
{ "message": "deleting context b8321b4f-19ff-4c98-b011-5a97178e7ad6", "logger": "mdc", "timestamp": "2018-03-07T21:39:12.010851", "level": "DEBUG", "mdc": { "foo": "bar", "index": 76 }, "extra": {}, "python": { "module": "init", "function": "MDC", "path": "/home/user/git/mdc/mdc/init.py", "file": "init.py", "line": 56, "process": { "name": "MainProcess", "id": 31678 }, "thread": { "name": "MainThread", "id": 140433289192768 } } }
Running tests:
.. code:: bash
$ tox
FAQs
Mapped Diagnostic Context (MDC) library for python
We found that mdc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.