### Quick Start: Basic HushLog Integration Source: https://pypi.org/project/hushlog Demonstrates how to integrate HushLog into a Python logging setup. Configure logging first, then apply the hushlog patch. This example shows PII redaction for email, credit card, and SSN. ```python import logging import hushlog # Configure logging FIRST, then patch logging.basicConfig(level=logging.INFO) hushlog.patch() logger = logging.getLogger(__name__) logger.info("User email: john@example.com") # Output: User email: [EMAIL REDACTED] logger.info("Card: 4111-1111-1111-1111") # Output: Card: [CREDIT_CARD REDACTED] logger.info("SSN: 123-45-6789") # Output: SSN: [SSN REDACTED] ``` -------------------------------- ### Install HushLog using pip Source: https://pypi.org/project/hushlog Use this command to install the hushlog package. It's recommended to do this before configuring your project. ```bash pip install hushlog ``` -------------------------------- ### Install Hushlog using pip Source: https://pypi.org/project/hushlog/1.5.0 Install the hushlog package using pip. This command installs version 1.5.0. ```bash pip install hushlog==1.5.0 ``` -------------------------------- ### Quick Start: Configure and Patch Logging Source: https://pypi.org/project/hushlog/1.5.0 Demonstrates how to configure Python's built-in logging and then apply Hushlog's redaction. Ensure logging is configured before patching. ```python import logging import hushlog # Configure logging FIRST, then patch logging.basicConfig(level=logging.INFO) hushlog.patch() logger = logging.getLogger(__name__) logger.info("User email: john@example.com") # Output: User email: [EMAIL REDACTED] logger.info("Card: 4111-1111-1111-1111") # Output: Card: [CREDIT_CARD REDACTED] logger.info("SSN: 123-45-6789") # Output: SSN: [SSN REDACTED] ``` -------------------------------- ### Install Hushlog using uv Source: https://pypi.org/project/hushlog/1.5.0 Install the hushlog package using the uv package manager. This command adds hushlog to your project dependencies. ```bash uv add hushlog ``` -------------------------------- ### Wrap Loguru Sink with PII Redaction Source: https://pypi.org/project/hushlog/1.5.0 Use `loguru_sink` to wrap any loguru sink for PII redaction. Ensure loguru is installed with the optional dependency: `pip install hushlog[loguru]`. ```python from loguru import logger from hushlog import loguru_sink logger.remove() # Remove default sink logger.add(loguru_sink(print), format="{message}") logger.info("User alice@corp.com logged in") # Output: User [EMAIL REDACTED] logged in ``` -------------------------------- ### Setup RedactingJsonFormatter for Logging Source: https://pypi.org/project/hushlog Use RedactingJsonFormatter as a drop-in JSON formatter for any handler to automatically redact PII in log messages and extra data. ```python import logging from hushlog import RedactingJsonFormatter formatter = RedactingJsonFormatter.from_config() handler = logging.StreamHandler() handler.setFormatter(formatter) logging.getLogger().addHandler(handler) logger = logging.getLogger(__name__) logger.info("Contact user@example.com", extra={"ssn": "078-05-1120"}) # Output: {"message": "Contact [EMAIL REDACTED]", "ssn": "[SSN REDACTED]", ...} ``` -------------------------------- ### Integrate HushLog Redaction with Structlog Processors Source: https://pypi.org/project/hushlog/1.5.0 Incorporate `structlog_processor()` into your structlog pipeline to automatically redact PII in structured log events. Ensure the optional 'structlog' dependency is installed. ```python import structlog from hushlog import structlog_processor structlog.configure( processors=[ structlog.stdlib.add_log_level, structlog_processor(), structlog.dev.ConsoleRenderer(), ], ) logger = structlog.get_logger() logger.info("login", email="alice@corp.com") # Output: email=[EMAIL REDACTED] ``` -------------------------------- ### Configure HushLog with Disabled and Custom Patterns Source: https://pypi.org/project/hushlog Disable specific built-in patterns like 'phone' and add custom patterns such as 'internal_id' using the Config object. ```python from hushlog import Config hushlog.patch(Config( disable_patterns=frozenset({"phone"}), custom_patterns={"internal_id": r"ID-[A-Z]{3}-[0-9]{6}"}, )) ``` -------------------------------- ### Enable Partial Masking in HushLog Source: https://pypi.org/project/hushlog/1.5.0 Configure HushLog to show partial values instead of fully redacting sensitive information. This can be useful for debugging or when a certain level of visibility is acceptable. ```python hushlog.patch(Config(mask_style="partial")) # john@example.com → j***@e***.com # 4111111111111111 → ****-****-****-1111 # 078-05-1120 → ***-**-1120 # (555) 234-5678 → (***) ***-5678 ``` -------------------------------- ### Enable Partial Masking in HushLog Source: https://pypi.org/project/hushlog Configure HushLog to show partial values instead of full redaction by setting mask_style to 'partial'. ```python hushlog.patch(Config(mask_style="partial")) # john@example.com → j***@e***.com # 4111111111111111 → ****-****-****-1111 # 078-05-1120 → ***-**-1120 # (555) 234-5678 → (***) ***-5678 ``` -------------------------------- ### Configure HushLog with Custom Patterns and Disabled Patterns Source: https://pypi.org/project/hushlog/1.5.0 Customize HushLog by disabling built-in patterns or adding your own regular expressions for PII detection. This is useful for tailoring redaction to specific application needs. ```python from hushlog import Config hushlog.patch(Config( disable_patterns=frozenset({"phone"}), custom_patterns={"internal_id": r"ID-[A-Z]{3}-[0-9]{6}"}, )) ``` -------------------------------- ### Integrate HushLog Processor with Structlog Source: https://pypi.org/project/hushlog Use structlog_processor() as a processor in your structlog pipeline to redact PII in log events. ```python import structlog from hushlog import structlog_processor structlog.configure( processors=[ structlog.stdlib.add_log_level, structlog_processor(), structlog.dev.ConsoleRenderer(), ], ) logger = structlog.get_logger() logger.info("login", email="alice@corp.com") # Output: email=[EMAIL REDACTED] ``` -------------------------------- ### Initialize RedactingJsonFormatter for JSON Logging Source: https://pypi.org/project/hushlog/1.5.0 Use RedactingJsonFormatter as a drop-in replacement for standard JSON formatters to automatically redact PII in log messages. It supports integration with Python's logging module. ```python import logging from hushlog import RedactingJsonFormatter formatter = RedactingJsonFormatter.from_config() handler = logging.StreamHandler() handler.setFormatter(formatter) logging.getLogger().addHandler(handler) logger = logging.getLogger(__name__) logger.info("Contact user@example.com", extra={"ssn": "078-05-1120"}) # Output: {"message": "Contact [EMAIL REDACTED]", "ssn": "[SSN REDACTED]", ...} ``` -------------------------------- ### Use Custom Mask Character for Partial Masking Source: https://pypi.org/project/hushlog Customize the mask character used in partial masking by setting mask_character in the Config. ```python hushlog.patch(Config(mask_style="partial", mask_character="#")) # john@example.com → j###@e###.com ``` -------------------------------- ### Remove HushLog Formatters Source: https://pypi.org/project/hushlog Call `unpatch()` to remove HushLog's formatter wrappers and restore original formatters. This is safe to call even if `patch()` was not previously called. ```python import hushlog hushlog.unpatch() ``` -------------------------------- ### Use Custom Mask Character for Partial Masking Source: https://pypi.org/project/hushlog/1.5.0 Specify a custom character to be used for partial masking in HushLog. This allows for more flexibility in how redacted information is displayed. ```python hushlog.patch(Config(mask_style="partial", mask_character="#")) # john@example.com → j###@e###.com ``` -------------------------------- ### Unpatch HushLog Formatters Source: https://pypi.org/project/hushlog/1.5.0 Call `hushlog.unpatch()` to remove HushLog's formatter wrappers and restore original formatters. This is safe to call even if `patch()` was not previously called. ```python import hushlog hushlog.unpatch() ``` -------------------------------- ### Manually Redact Dictionary Structures Source: https://pypi.org/project/hushlog Use the redact_dict() function for manual redaction of dict, list, or string structures. Note that this creates a new PatternRegistry on each call. ```python import hushlog data = {"user": {"email": "alice@corp.io", "name": "Alice", "age": 30}} clean = hushlog.redact_dict(data) # {"user": {"email": "[EMAIL REDACTED]", "name": "Alice", "age": 30}} ``` -------------------------------- ### Manually Redact Dictionary Structures with redact_dict() Source: https://pypi.org/project/hushlog/1.5.0 Use the `redact_dict()` function for manual redaction of Python dictionaries, lists, or strings. This function creates a new PatternRegistry on each call, suitable for infrequent use. ```python import hushlog data = {"user": {"email": "alice@corp.io", "name": "Alice", "age": 30}} clean = hushlog.redact_dict(data) # {"user": {"email": "[EMAIL REDACTED]", "name": "Alice", "age": 30}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.