Skip to content

Commit a8ef0ff

Browse files
committed
chore: Add circleci config
1 parent f9471b6 commit a8ef0ff

File tree

5 files changed

+58
-16
lines changed

5 files changed

+58
-16
lines changed

.circleci/config.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/python:3.6.1
6+
steps:
7+
- checkout
8+
- run:
9+
command: |
10+
sudo apt install python-pip
11+
sudo pip install -U pip pipenv
12+
- run:
13+
command: |
14+
pipenv --python python3.6
15+
pipenv install --dev
16+
- run:
17+
command: |
18+
pipenv run pytest
19+
- run:
20+
command: |
21+
pipenv run flake8
22+
- run:
23+
command: |
24+
pipenv run safety check
25+
- store_artifacts:
26+
path: htmlcov
27+
destination: htmlcov
28+

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# python_log_sanitizer
1+
# python_log_sanitizer
22

3-
<!-- [![CircleCI](https://circleci.com/gh/rai200890/python_google_cloud_logger.svg?style=svg&circle-token=cdb4c95268aa18f240f607082833c94a700f96e9)](https://circleci.com/gh/rai200890/python_google_cloud_logger) -->
3+
[![CircleCI](https://circleci.com/gh/rai200890/python-log-sanitizer.svg?style=svg&circle-token=da7071836f491385a780fb92fc015ebdd1da8569)](https://circleci.com/gh/rai200890/python-log-sanitizer)
44
[![PyPI version](https://badge.fury.io/py/python-log-sanitizer.svg)](https://badge.fury.io/py/python-log-sanitizer)
5-
<!-- [![Maintainability](https://api.codeclimate.com/v1/badges/e988f26e1590a6591d96/maintainability)](https://codeclimate.com/github/rai200890/python_google_cloud_logger/maintainability) -->
5+
[![Maintainability](https://api.codeclimate.com/v1/badges/07aeb29594b05405ddd5/maintainability)](https://codeclimate.com/github/rai200890/python-log-sanitizer/maintainability)
66

77
Python log sanitizer
88

examples/example_with_python_json_logger.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import logging
2+
3+
from logging import config
4+
5+
16
LOG_CONFIG = {
27
"version": 1,
38
"formatters": {
@@ -8,7 +13,7 @@
813
},
914
"filters": {
1015
"sanitizer": {
11-
"()" : "python_log_sanitizer.SanitizerFilter",
16+
"()": "python_log_sanitizer.SanitizerFilter",
1217
"patterns": ["extra"],
1318
"placeholder": "*"
1419
}
@@ -27,13 +32,9 @@
2732
}
2833
}
2934
}
30-
import logging
31-
32-
from logging import config
33-
34-
config.dictConfig(LOG_CONFIG) # load log config from dict
35-
36-
logger = logging.getLogger("root") # get root logger instance
35+
config.dictConfig(LOG_CONFIG) # load log config from dict
3736

37+
logger = logging.getLogger("root") # get root logger instance
3838

39-
logger.info("farofa", extra={"extra": "farofa"}) # log message with extra arguments
39+
logger.info(
40+
"farofa", extra={"extra": "farofa"}) # log message with extra arguments

python_log_sanitizer/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ def filter(self, record):
1414

1515
def _sanitize(self, field, data):
1616
if isinstance(data, dict):
17-
return {key: self._sanitize(key, value) for key, value in data.items()}
17+
return {
18+
key: self._sanitize(key, value)
19+
for key, value in data.items()
20+
}
1821
if isinstance(data, list):
1922
return [self._sanitize(field, item) for item in data]
2023
return self._sanitize_value(field, data)
@@ -23,4 +26,5 @@ def _sanitize_value(self, field, value):
2326
return self.placeholder if self.matches_any_pattern(field) else value
2427

2528
def matches_any_pattern(self, key):
26-
return any(re.compile(pattern).search(key) for pattern in self.patterns)
29+
return any(
30+
re.compile(pattern).search(key) for pattern in self.patterns)

test/test_sanitizer_filter.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ def record(mocker):
2525
"other": "123"
2626
}
2727
},
28-
autospec=["asctime", "filename", "funcName", "lineno", "levelname", "getMessage", "request"])
28+
autospec=[
29+
"asctime", "filename", "funcName", "lineno", "levelname",
30+
"getMessage", "request"
31+
])
2932

3033

3134
def test_filter(sanitizer_filter, record):
@@ -37,4 +40,10 @@ def test_filter(sanitizer_filter, record):
3740
assert record.levelname == "WARNING"
3841
assert record.getMessage() == "farofa"
3942
assert record.cpf_cnpj == "[*]"
40-
assert record.request == {"cpf_cnpj": "[*]", "random": {"user_cpf_cnpj": "[*]", "other": "123"}}
43+
assert record.request == {
44+
"cpf_cnpj": "[*]",
45+
"random": {
46+
"user_cpf_cnpj": "[*]",
47+
"other": "123"
48+
}
49+
}

0 commit comments

Comments
 (0)