Skip to main content

Utils for logging sensitive data.

Project description

Sensitive Data Logging

Utils for handling sensitive data in logs.

Setup

After installing package to use it's features you need to set default logger and dict configurator class.

Before using and configuring loggers set this things up:

import logging
import logging.config

from sensitive_data_logging.loggers import SensitiveDataLogger
from sensitive_data_logging.configurators import DictConfigurator


logging.setLoggerClass(SensitiveDataLogger)
logging.config.dictConfigClass = DictConfigurator

Configuration

Logger supplied by this package relies on logging dict configuration. In your configuration dict set (or not) variables sensitive_data_in_extra and sensitive_data_in_message. They can be used in every logger we want to secure, and event in root logger.

sensitive_data_in_extra - is list of keys which supplied in loggers extra data should be moved to sensitive_data sensitive_data_in_message - is bool whether move loggers message to sensitive_data or not

logging.config.dictConfig({
    'version': 1,
    'disable_existing_loggers': False,
    'root': {
        'level': 'DEBUG',
        'handlers': ['console'],
    },
    ...
    'loggers': {
        'first_logger': {
            'handlers': ['console'],
        },
        'second_logger': {
            'handlers': ['console'],
            'sensitive_data_in_extra': ['phone_number'],  # Key 'phone_number' from extra data will be moved to sensitive_data
        },
        'third_logger': {
            'handlers': ['console'],
            'sensitive_data_in_message': True,  # Whole message and args will be moved to sensitive_data
        },
    },
})

You can also use sensitive_data_logging.formatters.SensitiveDataFormatter in development environments to prepend sensitive_data to logged message.

Use of logger

With sensitive_data_logging.loggers.SensitiveDataLogger set as default you can use additional keyword argument when logging to explicitly supply sensitive_data:

logger.info('Some log', sensitive_data={'secret': 'value'})

License

The Sensitive Data Logging package is licensed under the FreeBSD License.

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

sensitive-data-logging-1.0.0.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

sensitive_data_logging-1.0.0-py3-none-any.whl (5.5 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