mask your secrets from your logs
Project description
Masker Logger
Keep Your logs safe!
This formatter ensures the security of your logs and prevents sensitive data leaks.
For example -
Using this Formatter will print this line:
logger.info(f'Dont Give Your {secrets} away')
like this:
Dont Give Your ****** away
Getting started
This formatter utilizes the standard logging.Formatter module.
Before printing each record to any destination (file, stdout, etc.), it ensures sensitive data is masked with asterisks to prevent leaks.
Requirements
| MaskerLogger Version | Python Version |
|---|---|
| 1.0.0+ | 3.10 - 3.13 |
| < 1.0.0 | 3.9 - 3.13 |
Install the library
pip install maskerlogger
Basic Usage
Like any formatter - just init your logger handler with the MaskerLogger formatter.
from maskerlogger import MaskerFormatter
logger = logging.getLogger('logger')
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setFormatter(
MaskerFormatter("%(asctime)s %(name)s %(levelname)s %(message)s"))
logger.addHandler(handler)
skip masking
If, for some reason, you want to disable masking on a specific log line, use the SKIP_MASK mechanism.
from maskerlogger import MaskerFormatter, SKIP_MASK
...
...
logger.info('Line you want to skip', extra=SKIP_MASK)
redact
Here’s a rewritten version suitable for inclusion in a README.md file:
Partial Masking of Secrets
If you prefer to mask only a portion of a secret (rather than its entire length), you can set the redact parameter in the formatter. The redact parameter specifies the percentage of the secret to be masked.
Here’s an example of how to use it:
handler.setFormatter(
MaskerFormatter("%(asctime)s %(name)s %(levelname)s %(message)s",
redact=30))
In this example, 30% of the secret will be masked. Adjust the redact value as needed to suit your requirements.
The Config File
Here's where the magic happens! Our tool is built upon the powerful Gitleaks tool, leveraging its default configuration to scan for sensitive data leaks in repositories. You can find the default configuration here
Use custom config file
To create and use your own config file, set the path when initializing the formatter:
handler.setFormatter(
MaskerFormatter("%(asctime)s %(name)s %(levelname)s %(message)s",
regex_config_path="your/config/gitleaks.toml"))
Good luck!
Brought to you by OX Security
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file maskerlogger-1.1.0.tar.gz.
File metadata
- Download URL: maskerlogger-1.1.0.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
011e89638b62c431be5ac5edd8c2b377006c2b0b40113a5fef30943c8ee8be7a
|
|
| MD5 |
d2043bb06a1ff714335eba0c1779f6d1
|
|
| BLAKE2b-256 |
1776c848f7e09872b096f5093709d00d5ebc0be8cb5036e9bb491db25b0dc1c8
|
Provenance
The following attestation bundles were made for maskerlogger-1.1.0.tar.gz:
Publisher:
publish.yml on oxsecurity/MaskerLogger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
maskerlogger-1.1.0.tar.gz -
Subject digest:
011e89638b62c431be5ac5edd8c2b377006c2b0b40113a5fef30943c8ee8be7a - Sigstore transparency entry: 707362864
- Sigstore integration time:
-
Permalink:
oxsecurity/MaskerLogger@8d80d9e89518b9a0d4614ddda83a86060c700670 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/oxsecurity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d80d9e89518b9a0d4614ddda83a86060c700670 -
Trigger Event:
release
-
Statement type:
File details
Details for the file maskerlogger-1.1.0-py3-none-any.whl.
File metadata
- Download URL: maskerlogger-1.1.0-py3-none-any.whl
- Upload date:
- Size: 29.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4249f0b8651bc9e79bd550b1fbcd038832a27bf51c3e9c221925ebb4ea6f3a3
|
|
| MD5 |
ac76e1f1c3c5b7983f8e8c11858a01b6
|
|
| BLAKE2b-256 |
7eb6df6b8f37b161f063f9cc28b22358be67f737e0e50d5325873e85c9b4d278
|
Provenance
The following attestation bundles were made for maskerlogger-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on oxsecurity/MaskerLogger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
maskerlogger-1.1.0-py3-none-any.whl -
Subject digest:
e4249f0b8651bc9e79bd550b1fbcd038832a27bf51c3e9c221925ebb4ea6f3a3 - Sigstore transparency entry: 707362872
- Sigstore integration time:
-
Permalink:
oxsecurity/MaskerLogger@8d80d9e89518b9a0d4614ddda83a86060c700670 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/oxsecurity
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8d80d9e89518b9a0d4614ddda83a86060c700670 -
Trigger Event:
release
-
Statement type: