A function decorator for beautiful and complete logging
Project description
Secure Logger
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
- Use the same virtual environment that you use for edx-platform
- Ensure that your Python interpreter to 3.8x
- install black: https://pypi.org/project/black/
- install flake8: https://flake8.pycqa.org/en/latest/
- install flake8-coding: https://pypi.org/project/flake8-coding/
# 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
Release history Release notifications | RSS feed
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.1.tar.gz
(19.0 kB
view details)
Built Distribution
File details
Details for the file secure-logger-0.1.1.tar.gz
.
File metadata
- Download URL: secure-logger-0.1.1.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23d2c1ab0b063f86c8f1622a4f566511ba1f62aa90615c86873dfb282b05fb9d |
|
MD5 | 2508c7ccdbe84944aa81526ffd8785b8 |
|
BLAKE2b-256 | dc3b7f902854ca27eb8aceb8fc82f36ad801c8e0a10d536c2406e2c48cfc00b2 |
Provenance
File details
Details for the file secure_logger-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: secure_logger-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 278799b39dc39fbeb6d8472e8dd2a930bee2ee033d3ed1e840d269eb81bb582a |
|
MD5 | 25839694d0aa758ec300245ec73d99a2 |
|
BLAKE2b-256 | 19a868b2998b94823e9c380660414c7c57a3439b4bc4822b754e4c712fb1855c |