Logger

Overview

Install Dependencies

To use BOSA Logger, install logger dependencies.

pip install bosa-core-binary[logger]

Logging often captures sensitive personal data unintentionally. To reduce compliance risks and ensure data privacy, BOSA SDK Logger automatically masks Personally Identifiable Information (PII) from log entries.

You can select either regex-based masking for speed and simplicity or Named Entity Recognition (NER)-based masking for advanced, context-aware detection. This ensures sensitive information in logs is automatically masked while maintaining log readability and usefulness.

Integration Guide

To help you integrate PII-safe logging into your application, this section provides step-by-step guidance on using the available logger handlers in BOSA Core.

Import Logger

import logging

# Regex based logger
from bosa_core.logger.regex_pii_logger_handler import init_regex_pii_logging_handler

# NER API based logger
from bosa_core.logger.ner_pii_logger_handler import init_ner_pii_logging_handler

Setup Logger

Initializing Logger

When initializing a logger handler, you will need to provide specific parameters depending on which handler you choose. The configuration options reflect the underlying mechanism (regex-based or NER-based) used for PII redaction.

Regex based logger

Regex PII Handler Options

  • logger_name: Name of the logger to attach the handler to

  • pii_regex_process_enabled: Enable/disable PII processing

NER API based logger

NER API Handler Options

  • logger_name: Name of the logger to attach the handler to

  • api_url: URL of the NER API endpoint

  • api_field: Field name for the text in the API request

  • pii_ner_process_enabled: Enable/disable PII processing

Add Console Handler

This will allow log messages to be printed to the console. Notes that you can also add the formatter here

Usage

Now, when you log messages containing sensitive data, the logger will automatically redact PII.

Example

Explore our comprehensive logging implementation to help integrate the BOSA SDK Logger effectively:

Choosing Between Regex and NER Logging

When deciding between regex and NER based logging, consider the following trade-offs:

  • Regex-based Logging:

    • Fast and efficient

    • Easy to customize

    • Ideal for environments with high logging throughput

    • Limited in detecting context-aware or varied formats

  • NER-based Logging:

    • More accurate, especially for unstructured text

    • Suitable for sensitive or complex data types (e.g., names, locations, social URLs)

    • Depends on an external API (may introduce latency or downtime risk)

Supported PII Types

The logger currently supports detection and masking for the following types of sensitive information:

  • KTP number

  • NPWP number

  • Family card number

  • Names

    • Person

    • Organization

    • Location

  • Phone number

  • Email address

  • International bank account number

  • Credit card number

  • Cryptocurrency wallet number

  • IP address

  • URL

    • Facebook account

    • LinkedIn account

Last updated