Commit 1b43102
authored
fix: remote root handlers when they exist (#3128)
### Summary
In some environments, such as Google Colab, loggers have a root handling
that did not mask sensitive values. As a result, secrets such as API
keys appeared in the logs. The PR removes root handlers when they exist
to ensure sensitive values are handler properly.
### Testing
Run the following in a Colab notebook. You should see two log outputs,
one with the API key masked and one with it exposed.
```
!pip install unstructured
```
```python
import logging
import json
from unstructured.ingest.interfaces import (
ChunkingConfig,
EmbeddingConfig,
PartitionConfig,
ProcessorConfig,
ReadConfig,
)
partition_config = PartitionConfig(
partition_by_api=True,
api_key="super secret",
)
from unstructured.ingest.logger import ingest_log_streaming_init
ingest_log_streaming_init(logging.INFO)
logger = logging.getLogger("unstructured.ingest")
logger.setLevel(logging.INFO)
logger.info(
f"Running partition node to extract content from json files. "
f"Config: {partition_config.to_json()}, "
)
```
Now replace the first cell with the following and rerun the Python code.
Only the masked logging output should remain.
```
!git clone https://github.com/Unstructured-IO/unstructured.git && cd unstructured && git checkout fix/rm-log-dupes && pip install -e .
```1 parent 54c1e4e commit 1b43102
3 files changed
+14
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
| |||
104 | 113 | | |
105 | 114 | | |
106 | 115 | | |
| 116 | + | |
107 | 117 | | |
108 | 118 | | |
109 | 119 | | |
| |||
116 | 126 | | |
117 | 127 | | |
118 | 128 | | |
| 129 | + | |
119 | 130 | | |
0 commit comments