Skip to content

Redaction of non string types #2

@PunitLodha

Description

@PunitLodha

Hello.
I am using httpx for making GET requests. httpx logs a result of a GET request as

Message: 'HTTP Request: %s %s "%s %d %s"'
Arguments: ('GET', 'https://example.com', 'HTTP/1.1', 200, 'OK')

logredactor converts the 200 to a string '200', which causes the error, TypeError: %d format: a real number is required, not str

logredactor should not convert integers to string. Here is the line which does that, https://github.com/xtream1101/logredactor/blob/master/logredactor/redacting_filter.py#L45

Minimal example,

import re
import logging
import logredactor

# Create a logger
logger = logging.getLogger()
# Add the redact filter to the logger with your custom filters
redact_patterns = [re.compile(r'\d+')]

# if no `default_mask` is passed in, 4 asterisks will be used
logger.addFilter(logredactor.RedactingFilter(redact_patterns, default_mask='xx'))

logger.warning("This is a test %d", 123)

My suggestion would be to ignore numbers, but I am not sure if that would be correct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions