Skip to main content

A function decorator for beautiful and complete logging

Project description

Secure Logger

Source code PyPI releases License: AGPL v3 hack.d Lawrence McDaniel

A Python decorator to generate redacted and nicely formatted log entries of class instantiations, class method calls and standard Python function calls. Redacts function parameter values and dict values based on a customizable list.

Redacts the following values by default:

DEFAULT_SENSITIVE_KEYS = [
    "password",
    "token",
    "client_id",
    "client_secret",
    "Authorization",
    "secret",
    "aws_access_key_id",
    "aws_secret_access_key",
]

Installation

pip install secure-logger

Usage

from secure_logger.decorators import secure_logger

MY_SENSITIVE_KEYS = ["top-secret-password", "equally-secret-value",]

class TestClass(object):

    @secure_logger(sensitive_keys=MY_SENSITIVE_KEYS, indent=4)
    def test_2(self, test_dict, test_list):
        pass

test_dict = {
    'insensitive_key': 'you-can-see-me',
    'top-secret-password': 'i-am-hidden',
    'equally-secret-value': 'so-am-i'
}
test_list = ['foo', 'bar']
o = TestClass()
o.test_2(test_dict=test_dict, test_list=test_list)

Generates log entries of this style and form:

INFO:secure_logger: __main__.TestClass().test_2()  keyword args: {
    "test_dict": {
        "insensitive_key": "you-can-see-me",
        "top-secret-password": "*** -- REDACTED -- ***",
        "equally-secret-value": "*** -- REDACTED -- ***"
    },
    "test_list": [
        "foo",
        "bar"
    ]
}

Contributing

Pull requests are welcome, and you can also contact Lawrence McDaniel directly.

Getting Started With Local development

# Run these from within your edx-platform virtual environment
python3 -m venv venv
source venv/bin/activate

pip install -r requirements/local.txt
pip install pre-commit black flake8
pre-commit install

Local development good practices

  • run black on modified code before committing.
  • run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
  • run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
  • run pre-commit run --all-files before pushing. see: https://pre-commit.com/

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

secure-logger-0.1.2.tar.gz (18.6 kB view hashes)

Uploaded Source

Built Distribution

secure_logger-0.1.2-py3-none-any.whl (17.4 kB view hashes)

Uploaded Python 3

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