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 app_logger
MY_SENSITIVE_KEYS = ["top-secret-password", "equally-secret-value",]
class TestClass(object):
@app_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)
Output
INFO:app_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.0.tar.gz
(19.0 kB
view hashes)
Built Distribution
Close
Hashes for secure_logger-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f057adc9d410613e7731f8235ecfa16e977321cb10afea01ef997e4f02cd591b |
|
MD5 | 9c5558442ef870b3aa15d9f166a75a2e |
|
BLAKE2b-256 | 798c380e6ae0f732a8d78d6f1c2efd8d5ea5482f74a49615d8820916f3bb614a |