logguard-cli 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {logguard_cli-0.1.0/logguard_cli.egg-info → logguard_cli-0.2.0}/PKG-INFO +45 -20
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/README.md +40 -17
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/log_guard.py +203 -13
- {logguard_cli-0.1.0 → logguard_cli-0.2.0/logguard_cli.egg-info}/PKG-INFO +45 -20
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/logguard_cli.egg-info/SOURCES.txt +1 -0
- logguard_cli-0.2.0/logguard_cli.egg-info/requires.txt +2 -0
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/pyproject.toml +8 -2
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/LICENSE +0 -0
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/logguard_cli.egg-info/dependency_links.txt +0 -0
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/logguard_cli.egg-info/entry_points.txt +0 -0
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/logguard_cli.egg-info/top_level.txt +0 -0
- {logguard_cli-0.1.0 → logguard_cli-0.2.0}/setup.cfg +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: logguard-cli
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A 100% local, offline CLI tool that scans log files and masks sensitive data (emails, phone numbers, API keys, IPs, credit cards) before you share them.
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A 100% local, offline CLI tool that scans log files and Excel (.xlsx) spreadsheets and masks sensitive data (emails, phone numbers, API keys, IPs, credit cards) before you share them.
|
|
5
5
|
Author: Apurva Raj
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/apurvaraj9/log-guard
|
|
8
8
|
Project-URL: Repository, https://github.com/apurvaraj9/log-guard
|
|
9
9
|
Project-URL: Issues, https://github.com/apurvaraj9/log-guard/issues
|
|
10
|
-
Keywords: logs,logging,masking,redaction,privacy,security,pii,sensitive-data,cli,pre-commit
|
|
10
|
+
Keywords: logs,logging,masking,redaction,privacy,security,pii,sensitive-data,cli,pre-commit,excel,xlsx
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Environment :: Console
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -25,23 +25,25 @@ Classifier: Topic :: Utilities
|
|
|
25
25
|
Requires-Python: >=3.9
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE
|
|
28
|
+
Requires-Dist: openpyxl>=3.1
|
|
29
|
+
Requires-Dist: defusedxml>=0.7
|
|
28
30
|
Dynamic: license-file
|
|
29
31
|
|
|
30
32
|
# 🛡️ Log Guard
|
|
31
33
|
|
|
32
|
-
[](https://github.com/apurvaraj9/log-guard/actions/workflows/tests.yml)
|
|
34
|
+
[](https://github.com/apurvaraj9/log-guard/actions/workflows/tests.yml) [](https://pypi.org/project/logguard-cli/)
|
|
33
35
|
|
|
34
|
-
**A local, offline tool that scans server log files and masks sensitive data before you share them for debugging.**
|
|
36
|
+
**A local, offline tool that scans server log files — and Excel spreadsheets — and masks sensitive data before you share them for debugging.**
|
|
35
37
|
|
|
36
|
-
No uploads. No third-party servers. No enterprise pricing. Your
|
|
38
|
+
No uploads. No third-party servers. No enterprise pricing. Your data never leaves your machine.
|
|
37
39
|
|
|
38
40
|
---
|
|
39
41
|
|
|
40
42
|
## Why Log Guard?
|
|
41
43
|
|
|
42
|
-
When you're debugging with a teammate, posting to a forum, or filing a support ticket, you often need to share a log file — but real
|
|
44
|
+
When you're debugging with a teammate, posting to a forum, or filing a support ticket, you often need to share a log file or a spreadsheet export — but real data is full of things you *shouldn't* share: customer emails, phone numbers, API keys, IP addresses, credit card numbers.
|
|
43
45
|
|
|
44
|
-
- **Online masking tools** require uploading your private
|
|
46
|
+
- **Online masking tools** require uploading your private data to a third-party server — a privacy risk in itself.
|
|
45
47
|
- **Enterprise security tools** solve this, but are expensive, complex, and overkill for an individual developer or small team.
|
|
46
48
|
|
|
47
49
|
**Log Guard** runs 100% locally, does one job well, and stays simple.
|
|
@@ -49,14 +51,15 @@ When you're debugging with a teammate, posting to a forum, or filing a support t
|
|
|
49
51
|
## Features
|
|
50
52
|
|
|
51
53
|
- 🔍 **Detects and masks:** emails, phone numbers, API keys (Stripe/AWS/GitHub formats + a generic long-token fallback), IP addresses, and credit card numbers (Visa/Mastercard/Amex/Discover)
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
+
- 📗 **Excel spreadsheet support** — scans every cell of every sheet in `.xlsx` files (hidden sheets included) and writes a masked copy you can open in Excel
|
|
55
|
+
- 📁 **Scans whole directories**, recursively by default — point it at a `logs/` folder and it finds everything inside, spreadsheets included
|
|
56
|
+
- 🧩 **Custom patterns** via a simple JSON file — add your own detection rules with no code changes (they apply to spreadsheets too)
|
|
54
57
|
- ⚙️ **Config file support** (`.log-guard.json`) — set project-level defaults for extensions, recursion, custom patterns, and quiet mode; CLI flags always override it
|
|
55
58
|
- 🚦 **CI / pre-commit mode** (`--check`) — scans without writing files and exits with status code `1` if secrets are found, so it can block a commit or fail a build. Ships with a ready-to-use `.pre-commit-hooks.yaml`
|
|
56
|
-
- 📄 **Non-destructive** — writes a new `*.masked.log` file (or a path you choose with `-o`); your original is never touched, and a clean file with nothing to mask doesn't get a redundant copy
|
|
59
|
+
- 📄 **Non-destructive** — writes a new `*.masked.log` / `*.masked.xlsx` file (or a path you choose with `-o`); your original is never touched, and a clean file with nothing to mask doesn't get a redundant copy
|
|
57
60
|
- 📊 **Summary report** — see exactly how many of each type were found
|
|
58
|
-
- 🧪 **Fully tested** —
|
|
59
|
-
- 💻 **Handles edge cases** — empty files, huge files (streamed line-by-line), unusual encodings, mixed line endings, and directories with zero matching files
|
|
61
|
+
- 🧪 **Fully tested** — 65+ automated tests covering detection, masking, spreadsheets, directory scanning, config parsing, and a wide range of edge cases, run automatically on every push via GitHub Actions across Python 3.9–3.12
|
|
62
|
+
- 💻 **Handles edge cases** — empty files, huge log files (streamed line-by-line), unusual encodings, mixed line endings, corrupt or password-protected spreadsheets, and directories with zero matching files
|
|
60
63
|
- 🚫 **Smart defaults for directories** — automatically skips `.git`, `node_modules`, `venv`, `.venv`, and `__pycache__` while recursing (use `--ext all` to scan every file if you really want to)
|
|
61
64
|
- ⚡ **Zero network calls, ever**
|
|
62
65
|
|
|
@@ -68,6 +71,8 @@ pip install logguard-cli
|
|
|
68
71
|
|
|
69
72
|
That's it — this installs the `log-guard` command. (The package is named `logguard-cli` on PyPI because the name `log-guard` was already taken, but the command you run is still `log-guard`.)
|
|
70
73
|
|
|
74
|
+
It also automatically installs two small libraries used for `.xlsx` support: `openpyxl` (reads and writes spreadsheets) and `defusedxml` (protects against maliciously crafted files). Both work fully offline.
|
|
75
|
+
|
|
71
76
|
Requires Python 3.9 or newer.
|
|
72
77
|
|
|
73
78
|
> **Note:** if `log-guard` isn't recognized as a command right after installing, your Python Scripts folder probably isn't on your system PATH. Either add it to PATH, or run the tool with `python -m log_guard` instead — both work identically.
|
|
@@ -92,13 +97,28 @@ log-guard your.log
|
|
|
92
97
|
|
|
93
98
|
Creates `your.masked.log` alongside the original (unless nothing was found — then no output file is created, to avoid clutter).
|
|
94
99
|
|
|
100
|
+
**Scan an Excel spreadsheet (`.xlsx`):**
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
log-guard data.xlsx
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
Scanned 29 cells across 4 sheet(s) in data.xlsx
|
|
108
|
+
Masked spreadsheet written to data.masked.xlsx
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Creates `data.masked.xlsx` — a real spreadsheet you can open in Excel. Every cell on every sheet is checked, including hidden sheets. Text cells and whole numbers (like a phone number typed as `5551234567`) are scanned; formulas, dates, and decimals are left untouched. `--check`, `--quiet`, `-o`, custom patterns, and the config file all work exactly as they do for text files.
|
|
112
|
+
|
|
113
|
+
Old `.xls` files (Excel 97–2003) aren't supported — open them in Excel and use **File > Save As** to save them as `.xlsx` first.
|
|
114
|
+
|
|
95
115
|
**Scan an entire directory (recursive by default):**
|
|
96
116
|
|
|
97
117
|
```bash
|
|
98
118
|
log-guard logs/
|
|
99
119
|
```
|
|
100
120
|
|
|
101
|
-
By default this scans `.log`, `.txt`, `.csv`, `.json`, `.out`, and `.
|
|
121
|
+
By default this scans `.log`, `.txt`, `.csv`, `.json`, `.out`, `.err`, and `.xlsx` files, skipping `.git`/`node_modules`/`venv`/`__pycache__` automatically.
|
|
102
122
|
|
|
103
123
|
```bash
|
|
104
124
|
log-guard logs/ --ext log,txt --no-recursive # only .log/.txt, top level only
|
|
@@ -119,12 +139,12 @@ log-guard your.log -o cleaned.log
|
|
|
119
139
|
log-guard logs/*.log --check
|
|
120
140
|
```
|
|
121
141
|
|
|
122
|
-
Add `--quiet` for a condensed summary suited to CI logs. To use Log Guard as an actual [pre-commit](https://pre-commit.com) hook in any repo:
|
|
142
|
+
Add `--quiet` for a condensed summary suited to CI logs. To use Log Guard as an actual [pre-commit](https://pre-commit.com) hook in any repo (it checks staged `.log` and `.xlsx` files):
|
|
123
143
|
|
|
124
144
|
```yaml
|
|
125
145
|
repos:
|
|
126
146
|
- repo: https://github.com/apurvaraj9/log-guard
|
|
127
|
-
rev: v0.
|
|
147
|
+
rev: v0.2.0
|
|
128
148
|
hooks:
|
|
129
149
|
- id: log-guard
|
|
130
150
|
```
|
|
@@ -183,14 +203,16 @@ pytest
|
|
|
183
203
|
```
|
|
184
204
|
log-guard/
|
|
185
205
|
├── .github/workflows/tests.yml # GitHub Actions: runs the test suite on every push
|
|
186
|
-
├── log_guard.py # Core tool: detection, masking, CLI, config, directory scanning
|
|
206
|
+
├── log_guard.py # Core tool: detection, masking, spreadsheets, CLI, config, directory scanning
|
|
187
207
|
├── test_log_guard.py # Automated test suite (pytest)
|
|
188
|
-
├── pyproject.toml # Packaging config (PyPI metadata + the `log-guard` command)
|
|
208
|
+
├── pyproject.toml # Packaging config (PyPI metadata, dependencies + the `log-guard` command)
|
|
189
209
|
├── .pre-commit-hooks.yaml # Lets others use Log Guard as a pre-commit hook
|
|
190
210
|
├── .log-guard.json.example # Example project config file
|
|
191
211
|
├── sample.log # Example log file for testing
|
|
192
212
|
├── generate_samples.py # Generates edge-case sample files for manual testing
|
|
193
213
|
├── generate_test_logs_dir.py # Generates a sample directory tree for directory-scanning tests
|
|
214
|
+
├── generate_xlsx_sample.py # Generates a sample .xlsx workbook (and can print any .xlsx file's contents)
|
|
215
|
+
├── RELEASING.md # Step-by-step checklist for publishing a new version
|
|
194
216
|
└── README.md
|
|
195
217
|
```
|
|
196
218
|
|
|
@@ -198,12 +220,15 @@ log-guard/
|
|
|
198
220
|
|
|
199
221
|
- Detection is regex-based, so like any pattern-matching approach it can occasionally miss unusual formats (false negatives) or flag something that isn't actually sensitive (false positives) — especially the generic long-token API key fallback, which can flag any long run of random-looking characters.
|
|
200
222
|
- Currently focused on common US-style phone number and card formats.
|
|
201
|
-
- **
|
|
223
|
+
- **Supported file types:** plain-text files and `.xlsx` spreadsheets. Old `.xls` files are not supported (re-save them as `.xlsx`), and other binary formats such as PDF or Word documents are not read.
|
|
224
|
+
- **Spreadsheet scanning covers cell values only.** Formulas are deliberately left untouched (masking text inside a formula could break it), and cell comments, headers/footers, sheet names, and text inside charts or images are not scanned.
|
|
225
|
+
- **Masked spreadsheets may lose some extras.** The masked copy keeps every sheet, all cell values, and basic formatting, but charts, images, and some advanced Excel features may not survive — a limitation of the `openpyxl` library used to read and write them. Your original file is never changed.
|
|
226
|
+
- **Spreadsheets are loaded into memory in full**, so very large workbooks need correspondingly more RAM. (Text logs are streamed line by line and don't have this limit.)
|
|
202
227
|
- This tool reduces the risk of accidentally sharing sensitive data, but it isn't a substitute for careful review of anything genuinely high-stakes before sharing.
|
|
203
228
|
|
|
204
229
|
## Roadmap
|
|
205
230
|
|
|
206
|
-
- [
|
|
231
|
+
- [x] `.xlsx` spreadsheet support (via `openpyxl`)
|
|
207
232
|
- [x] PyPI packaging (`pip install logguard-cli`)
|
|
208
233
|
|
|
209
234
|
## License
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# 🛡️ Log Guard
|
|
2
2
|
|
|
3
|
-
[](https://github.com/apurvaraj9/log-guard/actions/workflows/tests.yml)
|
|
3
|
+
[](https://github.com/apurvaraj9/log-guard/actions/workflows/tests.yml) [](https://pypi.org/project/logguard-cli/)
|
|
4
4
|
|
|
5
|
-
**A local, offline tool that scans server log files and masks sensitive data before you share them for debugging.**
|
|
5
|
+
**A local, offline tool that scans server log files — and Excel spreadsheets — and masks sensitive data before you share them for debugging.**
|
|
6
6
|
|
|
7
|
-
No uploads. No third-party servers. No enterprise pricing. Your
|
|
7
|
+
No uploads. No third-party servers. No enterprise pricing. Your data never leaves your machine.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
## Why Log Guard?
|
|
12
12
|
|
|
13
|
-
When you're debugging with a teammate, posting to a forum, or filing a support ticket, you often need to share a log file — but real
|
|
13
|
+
When you're debugging with a teammate, posting to a forum, or filing a support ticket, you often need to share a log file or a spreadsheet export — but real data is full of things you *shouldn't* share: customer emails, phone numbers, API keys, IP addresses, credit card numbers.
|
|
14
14
|
|
|
15
|
-
- **Online masking tools** require uploading your private
|
|
15
|
+
- **Online masking tools** require uploading your private data to a third-party server — a privacy risk in itself.
|
|
16
16
|
- **Enterprise security tools** solve this, but are expensive, complex, and overkill for an individual developer or small team.
|
|
17
17
|
|
|
18
18
|
**Log Guard** runs 100% locally, does one job well, and stays simple.
|
|
@@ -20,14 +20,15 @@ When you're debugging with a teammate, posting to a forum, or filing a support t
|
|
|
20
20
|
## Features
|
|
21
21
|
|
|
22
22
|
- 🔍 **Detects and masks:** emails, phone numbers, API keys (Stripe/AWS/GitHub formats + a generic long-token fallback), IP addresses, and credit card numbers (Visa/Mastercard/Amex/Discover)
|
|
23
|
-
-
|
|
24
|
-
-
|
|
23
|
+
- 📗 **Excel spreadsheet support** — scans every cell of every sheet in `.xlsx` files (hidden sheets included) and writes a masked copy you can open in Excel
|
|
24
|
+
- 📁 **Scans whole directories**, recursively by default — point it at a `logs/` folder and it finds everything inside, spreadsheets included
|
|
25
|
+
- 🧩 **Custom patterns** via a simple JSON file — add your own detection rules with no code changes (they apply to spreadsheets too)
|
|
25
26
|
- ⚙️ **Config file support** (`.log-guard.json`) — set project-level defaults for extensions, recursion, custom patterns, and quiet mode; CLI flags always override it
|
|
26
27
|
- 🚦 **CI / pre-commit mode** (`--check`) — scans without writing files and exits with status code `1` if secrets are found, so it can block a commit or fail a build. Ships with a ready-to-use `.pre-commit-hooks.yaml`
|
|
27
|
-
- 📄 **Non-destructive** — writes a new `*.masked.log` file (or a path you choose with `-o`); your original is never touched, and a clean file with nothing to mask doesn't get a redundant copy
|
|
28
|
+
- 📄 **Non-destructive** — writes a new `*.masked.log` / `*.masked.xlsx` file (or a path you choose with `-o`); your original is never touched, and a clean file with nothing to mask doesn't get a redundant copy
|
|
28
29
|
- 📊 **Summary report** — see exactly how many of each type were found
|
|
29
|
-
- 🧪 **Fully tested** —
|
|
30
|
-
- 💻 **Handles edge cases** — empty files, huge files (streamed line-by-line), unusual encodings, mixed line endings, and directories with zero matching files
|
|
30
|
+
- 🧪 **Fully tested** — 65+ automated tests covering detection, masking, spreadsheets, directory scanning, config parsing, and a wide range of edge cases, run automatically on every push via GitHub Actions across Python 3.9–3.12
|
|
31
|
+
- 💻 **Handles edge cases** — empty files, huge log files (streamed line-by-line), unusual encodings, mixed line endings, corrupt or password-protected spreadsheets, and directories with zero matching files
|
|
31
32
|
- 🚫 **Smart defaults for directories** — automatically skips `.git`, `node_modules`, `venv`, `.venv`, and `__pycache__` while recursing (use `--ext all` to scan every file if you really want to)
|
|
32
33
|
- ⚡ **Zero network calls, ever**
|
|
33
34
|
|
|
@@ -39,6 +40,8 @@ pip install logguard-cli
|
|
|
39
40
|
|
|
40
41
|
That's it — this installs the `log-guard` command. (The package is named `logguard-cli` on PyPI because the name `log-guard` was already taken, but the command you run is still `log-guard`.)
|
|
41
42
|
|
|
43
|
+
It also automatically installs two small libraries used for `.xlsx` support: `openpyxl` (reads and writes spreadsheets) and `defusedxml` (protects against maliciously crafted files). Both work fully offline.
|
|
44
|
+
|
|
42
45
|
Requires Python 3.9 or newer.
|
|
43
46
|
|
|
44
47
|
> **Note:** if `log-guard` isn't recognized as a command right after installing, your Python Scripts folder probably isn't on your system PATH. Either add it to PATH, or run the tool with `python -m log_guard` instead — both work identically.
|
|
@@ -63,13 +66,28 @@ log-guard your.log
|
|
|
63
66
|
|
|
64
67
|
Creates `your.masked.log` alongside the original (unless nothing was found — then no output file is created, to avoid clutter).
|
|
65
68
|
|
|
69
|
+
**Scan an Excel spreadsheet (`.xlsx`):**
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
log-guard data.xlsx
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Scanned 29 cells across 4 sheet(s) in data.xlsx
|
|
77
|
+
Masked spreadsheet written to data.masked.xlsx
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Creates `data.masked.xlsx` — a real spreadsheet you can open in Excel. Every cell on every sheet is checked, including hidden sheets. Text cells and whole numbers (like a phone number typed as `5551234567`) are scanned; formulas, dates, and decimals are left untouched. `--check`, `--quiet`, `-o`, custom patterns, and the config file all work exactly as they do for text files.
|
|
81
|
+
|
|
82
|
+
Old `.xls` files (Excel 97–2003) aren't supported — open them in Excel and use **File > Save As** to save them as `.xlsx` first.
|
|
83
|
+
|
|
66
84
|
**Scan an entire directory (recursive by default):**
|
|
67
85
|
|
|
68
86
|
```bash
|
|
69
87
|
log-guard logs/
|
|
70
88
|
```
|
|
71
89
|
|
|
72
|
-
By default this scans `.log`, `.txt`, `.csv`, `.json`, `.out`, and `.
|
|
90
|
+
By default this scans `.log`, `.txt`, `.csv`, `.json`, `.out`, `.err`, and `.xlsx` files, skipping `.git`/`node_modules`/`venv`/`__pycache__` automatically.
|
|
73
91
|
|
|
74
92
|
```bash
|
|
75
93
|
log-guard logs/ --ext log,txt --no-recursive # only .log/.txt, top level only
|
|
@@ -90,12 +108,12 @@ log-guard your.log -o cleaned.log
|
|
|
90
108
|
log-guard logs/*.log --check
|
|
91
109
|
```
|
|
92
110
|
|
|
93
|
-
Add `--quiet` for a condensed summary suited to CI logs. To use Log Guard as an actual [pre-commit](https://pre-commit.com) hook in any repo:
|
|
111
|
+
Add `--quiet` for a condensed summary suited to CI logs. To use Log Guard as an actual [pre-commit](https://pre-commit.com) hook in any repo (it checks staged `.log` and `.xlsx` files):
|
|
94
112
|
|
|
95
113
|
```yaml
|
|
96
114
|
repos:
|
|
97
115
|
- repo: https://github.com/apurvaraj9/log-guard
|
|
98
|
-
rev: v0.
|
|
116
|
+
rev: v0.2.0
|
|
99
117
|
hooks:
|
|
100
118
|
- id: log-guard
|
|
101
119
|
```
|
|
@@ -154,14 +172,16 @@ pytest
|
|
|
154
172
|
```
|
|
155
173
|
log-guard/
|
|
156
174
|
├── .github/workflows/tests.yml # GitHub Actions: runs the test suite on every push
|
|
157
|
-
├── log_guard.py # Core tool: detection, masking, CLI, config, directory scanning
|
|
175
|
+
├── log_guard.py # Core tool: detection, masking, spreadsheets, CLI, config, directory scanning
|
|
158
176
|
├── test_log_guard.py # Automated test suite (pytest)
|
|
159
|
-
├── pyproject.toml # Packaging config (PyPI metadata + the `log-guard` command)
|
|
177
|
+
├── pyproject.toml # Packaging config (PyPI metadata, dependencies + the `log-guard` command)
|
|
160
178
|
├── .pre-commit-hooks.yaml # Lets others use Log Guard as a pre-commit hook
|
|
161
179
|
├── .log-guard.json.example # Example project config file
|
|
162
180
|
├── sample.log # Example log file for testing
|
|
163
181
|
├── generate_samples.py # Generates edge-case sample files for manual testing
|
|
164
182
|
├── generate_test_logs_dir.py # Generates a sample directory tree for directory-scanning tests
|
|
183
|
+
├── generate_xlsx_sample.py # Generates a sample .xlsx workbook (and can print any .xlsx file's contents)
|
|
184
|
+
├── RELEASING.md # Step-by-step checklist for publishing a new version
|
|
165
185
|
└── README.md
|
|
166
186
|
```
|
|
167
187
|
|
|
@@ -169,12 +189,15 @@ log-guard/
|
|
|
169
189
|
|
|
170
190
|
- Detection is regex-based, so like any pattern-matching approach it can occasionally miss unusual formats (false negatives) or flag something that isn't actually sensitive (false positives) — especially the generic long-token API key fallback, which can flag any long run of random-looking characters.
|
|
171
191
|
- Currently focused on common US-style phone number and card formats.
|
|
172
|
-
- **
|
|
192
|
+
- **Supported file types:** plain-text files and `.xlsx` spreadsheets. Old `.xls` files are not supported (re-save them as `.xlsx`), and other binary formats such as PDF or Word documents are not read.
|
|
193
|
+
- **Spreadsheet scanning covers cell values only.** Formulas are deliberately left untouched (masking text inside a formula could break it), and cell comments, headers/footers, sheet names, and text inside charts or images are not scanned.
|
|
194
|
+
- **Masked spreadsheets may lose some extras.** The masked copy keeps every sheet, all cell values, and basic formatting, but charts, images, and some advanced Excel features may not survive — a limitation of the `openpyxl` library used to read and write them. Your original file is never changed.
|
|
195
|
+
- **Spreadsheets are loaded into memory in full**, so very large workbooks need correspondingly more RAM. (Text logs are streamed line by line and don't have this limit.)
|
|
173
196
|
- This tool reduces the risk of accidentally sharing sensitive data, but it isn't a substitute for careful review of anything genuinely high-stakes before sharing.
|
|
174
197
|
|
|
175
198
|
## Roadmap
|
|
176
199
|
|
|
177
|
-
- [
|
|
200
|
+
- [x] `.xlsx` spreadsheet support (via `openpyxl`)
|
|
178
201
|
- [x] PyPI packaging (`pip install logguard-cli`)
|
|
179
202
|
|
|
180
203
|
## License
|
|
@@ -3,6 +3,9 @@ import argparse
|
|
|
3
3
|
import os
|
|
4
4
|
import json
|
|
5
5
|
import sys
|
|
6
|
+
import warnings
|
|
7
|
+
|
|
8
|
+
import openpyxl
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
def read_log_file_lines(filepath):
|
|
@@ -59,12 +62,21 @@ DISPLAY_NAMES = {
|
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
# Default file extensions scanned when a directory is given and no
|
|
62
|
-
# --ext / config "extensions" override is present.
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
DEFAULT_EXTENSIONS = ["log", "txt", "csv", "json", "out", "err"]
|
|
65
|
+
# --ext / config "extensions" override is present. The plain-text
|
|
66
|
+
# formats are read line by line; .xlsx is read cell by cell with
|
|
67
|
+
# openpyxl (see SPREADSHEET_EXTENSIONS below). The old .xls format is
|
|
68
|
+
# deliberately NOT included: it isn't supported, and including it would
|
|
69
|
+
# turn every .xls file in a scanned folder into an error.
|
|
70
|
+
DEFAULT_EXTENSIONS = ["log", "txt", "csv", "json", "out", "err", "xlsx"]
|
|
71
|
+
|
|
72
|
+
# Spreadsheet formats that are read cell-by-cell with openpyxl instead
|
|
73
|
+
# of line-by-line as plain text.
|
|
74
|
+
SPREADSHEET_EXTENSIONS = {"xlsx"}
|
|
75
|
+
|
|
76
|
+
# The old pre-2007 Excel format: a completely different binary format
|
|
77
|
+
# that openpyxl can't read, so we give a clear error instead of
|
|
78
|
+
# pretending to scan it.
|
|
79
|
+
UNSUPPORTED_SPREADSHEET_EXTENSIONS = {"xls"}
|
|
68
80
|
|
|
69
81
|
# Directories that are never worth recursing into automatically —
|
|
70
82
|
# their contents are tooling/dependency internals, not application
|
|
@@ -148,6 +160,97 @@ def mask_log(lines, patterns):
|
|
|
148
160
|
return masked_lines, total_counts, line_count
|
|
149
161
|
|
|
150
162
|
|
|
163
|
+
# --- Spreadsheet (.xlsx) support ---
|
|
164
|
+
# .xlsx files are ZIP archives of XML, not plain text, so they can't go
|
|
165
|
+
# through the line-by-line reader above. Instead we open them with
|
|
166
|
+
# openpyxl and run the same mask_line() logic on each cell's text.
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def _cell_text_for_scanning(cell):
|
|
170
|
+
"""
|
|
171
|
+
Returns the text that should be scanned for a spreadsheet cell, or
|
|
172
|
+
None if the cell should be skipped.
|
|
173
|
+
|
|
174
|
+
- Text cells are scanned as-is.
|
|
175
|
+
- Whole numbers (e.g. a phone number typed as 5551234567) are
|
|
176
|
+
scanned as their digits.
|
|
177
|
+
- Formulas are skipped: masking text inside a formula could break it.
|
|
178
|
+
- Dates, decimals, and True/False values are skipped: they can't
|
|
179
|
+
contain the kinds of data we look for.
|
|
180
|
+
"""
|
|
181
|
+
value = cell.value
|
|
182
|
+
if value is None:
|
|
183
|
+
return None
|
|
184
|
+
if cell.data_type == "f":
|
|
185
|
+
return None
|
|
186
|
+
# bool must be checked before int, because True/False count as ints in Python.
|
|
187
|
+
if isinstance(value, bool):
|
|
188
|
+
return None
|
|
189
|
+
if isinstance(value, str):
|
|
190
|
+
return value
|
|
191
|
+
if isinstance(value, int):
|
|
192
|
+
return str(value)
|
|
193
|
+
if isinstance(value, float) and value.is_integer():
|
|
194
|
+
return str(int(value))
|
|
195
|
+
return None
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def mask_workbook(filepath, patterns):
|
|
199
|
+
"""
|
|
200
|
+
Opens an .xlsx file and masks sensitive data in every cell of every
|
|
201
|
+
sheet (hidden sheets included). Cells are only changed if something
|
|
202
|
+
was actually found in them.
|
|
203
|
+
|
|
204
|
+
Returns a tuple of: (workbook, total_counts, cell_count, sheet_count)
|
|
205
|
+
where cell_count is the number of non-empty cells looked at.
|
|
206
|
+
The masked workbook is returned in memory; use write_workbook() to
|
|
207
|
+
save it.
|
|
208
|
+
"""
|
|
209
|
+
# openpyxl prints harmless technical warnings for many real-world
|
|
210
|
+
# files (e.g. "Data Validation extension is not supported"). They
|
|
211
|
+
# don't affect scanning, so we hide them to keep output clean.
|
|
212
|
+
with warnings.catch_warnings():
|
|
213
|
+
warnings.simplefilter("ignore")
|
|
214
|
+
workbook = openpyxl.load_workbook(filepath)
|
|
215
|
+
|
|
216
|
+
total_counts = {label: 0 for label in patterns}
|
|
217
|
+
cell_count = 0
|
|
218
|
+
|
|
219
|
+
for worksheet in workbook.worksheets:
|
|
220
|
+
for row in worksheet.iter_rows():
|
|
221
|
+
for cell in row:
|
|
222
|
+
if cell.value is None:
|
|
223
|
+
continue
|
|
224
|
+
cell_count += 1
|
|
225
|
+
|
|
226
|
+
text = _cell_text_for_scanning(cell)
|
|
227
|
+
if text is None:
|
|
228
|
+
continue
|
|
229
|
+
|
|
230
|
+
masked_text, counts = mask_line(text, patterns)
|
|
231
|
+
if masked_text != text:
|
|
232
|
+
cell.value = masked_text
|
|
233
|
+
for label in total_counts:
|
|
234
|
+
total_counts[label] += counts[label]
|
|
235
|
+
|
|
236
|
+
return workbook, total_counts, cell_count, len(workbook.worksheets)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
def write_workbook(filepath, workbook):
|
|
240
|
+
"""
|
|
241
|
+
Saves an openpyxl workbook to a new .xlsx file.
|
|
242
|
+
"""
|
|
243
|
+
workbook.save(filepath)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _file_extension(filepath):
|
|
247
|
+
"""
|
|
248
|
+
Returns the file's extension, lowercased, without the dot.
|
|
249
|
+
"Report.XLSX" -> "xlsx", "server.log" -> "log", "README" -> "".
|
|
250
|
+
"""
|
|
251
|
+
return os.path.splitext(filepath)[1].lower().lstrip(".")
|
|
252
|
+
|
|
253
|
+
|
|
151
254
|
def build_output_filepath(input_filepath):
|
|
152
255
|
"""
|
|
153
256
|
Given "somelog.log", returns "somelog.masked.log" in the same folder.
|
|
@@ -274,17 +377,82 @@ def load_config(config_path):
|
|
|
274
377
|
return data
|
|
275
378
|
|
|
276
379
|
|
|
380
|
+
def _process_spreadsheet(filepath, patterns, check_mode, output_override, result):
|
|
381
|
+
"""
|
|
382
|
+
The spreadsheet half of process_file(): scans an .xlsx file cell by
|
|
383
|
+
cell and (unless in check mode) writes a masked .xlsx copy. Fills in
|
|
384
|
+
and returns the same `result` dict that process_file() uses, so the
|
|
385
|
+
rest of the program can treat spreadsheets and text files the same.
|
|
386
|
+
"""
|
|
387
|
+
result["kind"] = "spreadsheet"
|
|
388
|
+
|
|
389
|
+
try:
|
|
390
|
+
workbook, total_counts, cell_count, sheet_count = mask_workbook(filepath, patterns)
|
|
391
|
+
except FileNotFoundError:
|
|
392
|
+
result["error"] = f"file not found (it may have been deleted or moved): {filepath}"
|
|
393
|
+
return result
|
|
394
|
+
except PermissionError:
|
|
395
|
+
result["error"] = f"permission denied when trying to read: {filepath}"
|
|
396
|
+
return result
|
|
397
|
+
except Exception as e:
|
|
398
|
+
# A corrupt file, a password-protected workbook, or a file that
|
|
399
|
+
# isn't really an .xlsx can fail in many different ways inside
|
|
400
|
+
# openpyxl. Whatever happens, report it clearly — never crash.
|
|
401
|
+
result["error"] = (
|
|
402
|
+
f"could not read spreadsheet: {filepath} (it may be corrupt, "
|
|
403
|
+
f"password-protected, or not a real .xlsx file; details: {e})"
|
|
404
|
+
)
|
|
405
|
+
return result
|
|
406
|
+
|
|
407
|
+
result["cell_count"] = cell_count
|
|
408
|
+
result["sheet_count"] = sheet_count
|
|
409
|
+
result["counts"] = total_counts
|
|
410
|
+
|
|
411
|
+
if cell_count == 0:
|
|
412
|
+
result["empty"] = True
|
|
413
|
+
return result
|
|
414
|
+
|
|
415
|
+
if not check_mode:
|
|
416
|
+
total_found = sum(total_counts.values())
|
|
417
|
+
|
|
418
|
+
if total_found == 0 and output_override is None:
|
|
419
|
+
result["skipped_write"] = True
|
|
420
|
+
return result
|
|
421
|
+
|
|
422
|
+
output_filepath = output_override or build_output_filepath(filepath)
|
|
423
|
+
try:
|
|
424
|
+
write_workbook(output_filepath, workbook)
|
|
425
|
+
except PermissionError:
|
|
426
|
+
result["error"] = (
|
|
427
|
+
f"permission denied when trying to write: {output_filepath} "
|
|
428
|
+
f"(if it's open in Excel, close it and try again)"
|
|
429
|
+
)
|
|
430
|
+
return result
|
|
431
|
+
except OSError as e:
|
|
432
|
+
result["error"] = f"could not write file: {output_filepath} ({e})"
|
|
433
|
+
return result
|
|
434
|
+
result["output_filepath"] = output_filepath
|
|
435
|
+
|
|
436
|
+
return result
|
|
437
|
+
|
|
438
|
+
|
|
277
439
|
def process_file(filepath, patterns, check_mode, output_override=None):
|
|
278
440
|
"""
|
|
279
441
|
Reads and scans a single file. In check_mode, never writes an output
|
|
280
442
|
file. In normal mode, writes an output file UNLESS nothing was found
|
|
281
443
|
AND no explicit output_override was given.
|
|
444
|
+
|
|
445
|
+
.xlsx files are handled by _process_spreadsheet(); .xls files get a
|
|
446
|
+
clear "not supported" error; everything else is read as plain text.
|
|
282
447
|
"""
|
|
283
448
|
result = {
|
|
284
449
|
"filepath": filepath,
|
|
450
|
+
"kind": "text",
|
|
285
451
|
"error": None,
|
|
286
452
|
"empty": False,
|
|
287
453
|
"line_count": 0,
|
|
454
|
+
"cell_count": 0,
|
|
455
|
+
"sheet_count": 0,
|
|
288
456
|
"counts": {label: 0 for label in patterns},
|
|
289
457
|
"output_filepath": None,
|
|
290
458
|
"skipped_write": False,
|
|
@@ -294,6 +462,18 @@ def process_file(filepath, patterns, check_mode, output_override=None):
|
|
|
294
462
|
result["error"] = f"file not found: {filepath}"
|
|
295
463
|
return result
|
|
296
464
|
|
|
465
|
+
extension = _file_extension(filepath)
|
|
466
|
+
|
|
467
|
+
if extension in UNSUPPORTED_SPREADSHEET_EXTENSIONS:
|
|
468
|
+
result["error"] = (
|
|
469
|
+
f"the old .xls Excel format is not supported: {filepath} "
|
|
470
|
+
f"(open it in Excel and use File > Save As to save it as .xlsx)"
|
|
471
|
+
)
|
|
472
|
+
return result
|
|
473
|
+
|
|
474
|
+
if extension in SPREADSHEET_EXTENSIONS:
|
|
475
|
+
return _process_spreadsheet(filepath, patterns, check_mode, output_override, result)
|
|
476
|
+
|
|
297
477
|
try:
|
|
298
478
|
lines = read_log_file_lines(filepath)
|
|
299
479
|
masked_lines, total_counts, line_count = mask_log(lines, patterns)
|
|
@@ -342,15 +522,16 @@ def parse_arguments():
|
|
|
342
522
|
parser = argparse.ArgumentParser(
|
|
343
523
|
prog="log-guard",
|
|
344
524
|
description=(
|
|
345
|
-
"Scan log files (or entire directories) and
|
|
346
|
-
"(emails, phone numbers, API keys, IP addresses,
|
|
347
|
-
"and custom patterns)."
|
|
525
|
+
"Scan log files and .xlsx spreadsheets (or entire directories) and "
|
|
526
|
+
"mask sensitive data (emails, phone numbers, API keys, IP addresses, "
|
|
527
|
+
"credit cards, and custom patterns)."
|
|
348
528
|
),
|
|
349
529
|
epilog=(
|
|
350
530
|
"Examples:\n"
|
|
351
531
|
" log-guard sample.log\n"
|
|
352
532
|
" log-guard sample.log -o cleaned.log\n"
|
|
353
|
-
" log-guard
|
|
533
|
+
" log-guard data.xlsx # Excel spreadsheet -> data.masked.xlsx\n"
|
|
534
|
+
" log-guard logs/ # scans log/txt/csv/json/out/err/xlsx in logs/, recursively\n"
|
|
354
535
|
" log-guard logs/ --ext log,txt --no-recursive\n"
|
|
355
536
|
" log-guard logs/ --ext all # scan every file, any extension\n"
|
|
356
537
|
" log-guard sample.log --patterns custom_patterns.json\n"
|
|
@@ -365,7 +546,7 @@ def parse_arguments():
|
|
|
365
546
|
parser.add_argument(
|
|
366
547
|
"filepaths",
|
|
367
548
|
nargs="+",
|
|
368
|
-
help="Path(s) to log file(s) and/or directories to scan"
|
|
549
|
+
help="Path(s) to log file(s), .xlsx spreadsheet(s), and/or directories to scan"
|
|
369
550
|
)
|
|
370
551
|
parser.add_argument(
|
|
371
552
|
"-o", "--output",
|
|
@@ -520,9 +701,18 @@ def main():
|
|
|
520
701
|
continue
|
|
521
702
|
|
|
522
703
|
if not quiet:
|
|
523
|
-
|
|
704
|
+
if result["kind"] == "spreadsheet":
|
|
705
|
+
print(
|
|
706
|
+
f"Scanned {result['cell_count']} cells across "
|
|
707
|
+
f"{result['sheet_count']} sheet(s) in {filepath}"
|
|
708
|
+
)
|
|
709
|
+
output_label = "Masked spreadsheet"
|
|
710
|
+
else:
|
|
711
|
+
print(f"Scanned {result['line_count']} lines in {filepath}")
|
|
712
|
+
output_label = "Masked log"
|
|
713
|
+
|
|
524
714
|
if result["output_filepath"]:
|
|
525
|
-
print(f"
|
|
715
|
+
print(f"{output_label} written to {result['output_filepath']}")
|
|
526
716
|
elif result["skipped_write"]:
|
|
527
717
|
print(f"No sensitive data found in {filepath}; masked file not created.")
|
|
528
718
|
print_summary(result["counts"], heading=f"--- Summary for {filepath} ---", verb=verb)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: logguard-cli
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: A 100% local, offline CLI tool that scans log files and masks sensitive data (emails, phone numbers, API keys, IPs, credit cards) before you share them.
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A 100% local, offline CLI tool that scans log files and Excel (.xlsx) spreadsheets and masks sensitive data (emails, phone numbers, API keys, IPs, credit cards) before you share them.
|
|
5
5
|
Author: Apurva Raj
|
|
6
6
|
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/apurvaraj9/log-guard
|
|
8
8
|
Project-URL: Repository, https://github.com/apurvaraj9/log-guard
|
|
9
9
|
Project-URL: Issues, https://github.com/apurvaraj9/log-guard/issues
|
|
10
|
-
Keywords: logs,logging,masking,redaction,privacy,security,pii,sensitive-data,cli,pre-commit
|
|
10
|
+
Keywords: logs,logging,masking,redaction,privacy,security,pii,sensitive-data,cli,pre-commit,excel,xlsx
|
|
11
11
|
Classifier: Development Status :: 4 - Beta
|
|
12
12
|
Classifier: Environment :: Console
|
|
13
13
|
Classifier: Intended Audience :: Developers
|
|
@@ -25,23 +25,25 @@ Classifier: Topic :: Utilities
|
|
|
25
25
|
Requires-Python: >=3.9
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE
|
|
28
|
+
Requires-Dist: openpyxl>=3.1
|
|
29
|
+
Requires-Dist: defusedxml>=0.7
|
|
28
30
|
Dynamic: license-file
|
|
29
31
|
|
|
30
32
|
# 🛡️ Log Guard
|
|
31
33
|
|
|
32
|
-
[](https://github.com/apurvaraj9/log-guard/actions/workflows/tests.yml)
|
|
34
|
+
[](https://github.com/apurvaraj9/log-guard/actions/workflows/tests.yml) [](https://pypi.org/project/logguard-cli/)
|
|
33
35
|
|
|
34
|
-
**A local, offline tool that scans server log files and masks sensitive data before you share them for debugging.**
|
|
36
|
+
**A local, offline tool that scans server log files — and Excel spreadsheets — and masks sensitive data before you share them for debugging.**
|
|
35
37
|
|
|
36
|
-
No uploads. No third-party servers. No enterprise pricing. Your
|
|
38
|
+
No uploads. No third-party servers. No enterprise pricing. Your data never leaves your machine.
|
|
37
39
|
|
|
38
40
|
---
|
|
39
41
|
|
|
40
42
|
## Why Log Guard?
|
|
41
43
|
|
|
42
|
-
When you're debugging with a teammate, posting to a forum, or filing a support ticket, you often need to share a log file — but real
|
|
44
|
+
When you're debugging with a teammate, posting to a forum, or filing a support ticket, you often need to share a log file or a spreadsheet export — but real data is full of things you *shouldn't* share: customer emails, phone numbers, API keys, IP addresses, credit card numbers.
|
|
43
45
|
|
|
44
|
-
- **Online masking tools** require uploading your private
|
|
46
|
+
- **Online masking tools** require uploading your private data to a third-party server — a privacy risk in itself.
|
|
45
47
|
- **Enterprise security tools** solve this, but are expensive, complex, and overkill for an individual developer or small team.
|
|
46
48
|
|
|
47
49
|
**Log Guard** runs 100% locally, does one job well, and stays simple.
|
|
@@ -49,14 +51,15 @@ When you're debugging with a teammate, posting to a forum, or filing a support t
|
|
|
49
51
|
## Features
|
|
50
52
|
|
|
51
53
|
- 🔍 **Detects and masks:** emails, phone numbers, API keys (Stripe/AWS/GitHub formats + a generic long-token fallback), IP addresses, and credit card numbers (Visa/Mastercard/Amex/Discover)
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
+
- 📗 **Excel spreadsheet support** — scans every cell of every sheet in `.xlsx` files (hidden sheets included) and writes a masked copy you can open in Excel
|
|
55
|
+
- 📁 **Scans whole directories**, recursively by default — point it at a `logs/` folder and it finds everything inside, spreadsheets included
|
|
56
|
+
- 🧩 **Custom patterns** via a simple JSON file — add your own detection rules with no code changes (they apply to spreadsheets too)
|
|
54
57
|
- ⚙️ **Config file support** (`.log-guard.json`) — set project-level defaults for extensions, recursion, custom patterns, and quiet mode; CLI flags always override it
|
|
55
58
|
- 🚦 **CI / pre-commit mode** (`--check`) — scans without writing files and exits with status code `1` if secrets are found, so it can block a commit or fail a build. Ships with a ready-to-use `.pre-commit-hooks.yaml`
|
|
56
|
-
- 📄 **Non-destructive** — writes a new `*.masked.log` file (or a path you choose with `-o`); your original is never touched, and a clean file with nothing to mask doesn't get a redundant copy
|
|
59
|
+
- 📄 **Non-destructive** — writes a new `*.masked.log` / `*.masked.xlsx` file (or a path you choose with `-o`); your original is never touched, and a clean file with nothing to mask doesn't get a redundant copy
|
|
57
60
|
- 📊 **Summary report** — see exactly how many of each type were found
|
|
58
|
-
- 🧪 **Fully tested** —
|
|
59
|
-
- 💻 **Handles edge cases** — empty files, huge files (streamed line-by-line), unusual encodings, mixed line endings, and directories with zero matching files
|
|
61
|
+
- 🧪 **Fully tested** — 65+ automated tests covering detection, masking, spreadsheets, directory scanning, config parsing, and a wide range of edge cases, run automatically on every push via GitHub Actions across Python 3.9–3.12
|
|
62
|
+
- 💻 **Handles edge cases** — empty files, huge log files (streamed line-by-line), unusual encodings, mixed line endings, corrupt or password-protected spreadsheets, and directories with zero matching files
|
|
60
63
|
- 🚫 **Smart defaults for directories** — automatically skips `.git`, `node_modules`, `venv`, `.venv`, and `__pycache__` while recursing (use `--ext all` to scan every file if you really want to)
|
|
61
64
|
- ⚡ **Zero network calls, ever**
|
|
62
65
|
|
|
@@ -68,6 +71,8 @@ pip install logguard-cli
|
|
|
68
71
|
|
|
69
72
|
That's it — this installs the `log-guard` command. (The package is named `logguard-cli` on PyPI because the name `log-guard` was already taken, but the command you run is still `log-guard`.)
|
|
70
73
|
|
|
74
|
+
It also automatically installs two small libraries used for `.xlsx` support: `openpyxl` (reads and writes spreadsheets) and `defusedxml` (protects against maliciously crafted files). Both work fully offline.
|
|
75
|
+
|
|
71
76
|
Requires Python 3.9 or newer.
|
|
72
77
|
|
|
73
78
|
> **Note:** if `log-guard` isn't recognized as a command right after installing, your Python Scripts folder probably isn't on your system PATH. Either add it to PATH, or run the tool with `python -m log_guard` instead — both work identically.
|
|
@@ -92,13 +97,28 @@ log-guard your.log
|
|
|
92
97
|
|
|
93
98
|
Creates `your.masked.log` alongside the original (unless nothing was found — then no output file is created, to avoid clutter).
|
|
94
99
|
|
|
100
|
+
**Scan an Excel spreadsheet (`.xlsx`):**
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
log-guard data.xlsx
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
Scanned 29 cells across 4 sheet(s) in data.xlsx
|
|
108
|
+
Masked spreadsheet written to data.masked.xlsx
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Creates `data.masked.xlsx` — a real spreadsheet you can open in Excel. Every cell on every sheet is checked, including hidden sheets. Text cells and whole numbers (like a phone number typed as `5551234567`) are scanned; formulas, dates, and decimals are left untouched. `--check`, `--quiet`, `-o`, custom patterns, and the config file all work exactly as they do for text files.
|
|
112
|
+
|
|
113
|
+
Old `.xls` files (Excel 97–2003) aren't supported — open them in Excel and use **File > Save As** to save them as `.xlsx` first.
|
|
114
|
+
|
|
95
115
|
**Scan an entire directory (recursive by default):**
|
|
96
116
|
|
|
97
117
|
```bash
|
|
98
118
|
log-guard logs/
|
|
99
119
|
```
|
|
100
120
|
|
|
101
|
-
By default this scans `.log`, `.txt`, `.csv`, `.json`, `.out`, and `.
|
|
121
|
+
By default this scans `.log`, `.txt`, `.csv`, `.json`, `.out`, `.err`, and `.xlsx` files, skipping `.git`/`node_modules`/`venv`/`__pycache__` automatically.
|
|
102
122
|
|
|
103
123
|
```bash
|
|
104
124
|
log-guard logs/ --ext log,txt --no-recursive # only .log/.txt, top level only
|
|
@@ -119,12 +139,12 @@ log-guard your.log -o cleaned.log
|
|
|
119
139
|
log-guard logs/*.log --check
|
|
120
140
|
```
|
|
121
141
|
|
|
122
|
-
Add `--quiet` for a condensed summary suited to CI logs. To use Log Guard as an actual [pre-commit](https://pre-commit.com) hook in any repo:
|
|
142
|
+
Add `--quiet` for a condensed summary suited to CI logs. To use Log Guard as an actual [pre-commit](https://pre-commit.com) hook in any repo (it checks staged `.log` and `.xlsx` files):
|
|
123
143
|
|
|
124
144
|
```yaml
|
|
125
145
|
repos:
|
|
126
146
|
- repo: https://github.com/apurvaraj9/log-guard
|
|
127
|
-
rev: v0.
|
|
147
|
+
rev: v0.2.0
|
|
128
148
|
hooks:
|
|
129
149
|
- id: log-guard
|
|
130
150
|
```
|
|
@@ -183,14 +203,16 @@ pytest
|
|
|
183
203
|
```
|
|
184
204
|
log-guard/
|
|
185
205
|
├── .github/workflows/tests.yml # GitHub Actions: runs the test suite on every push
|
|
186
|
-
├── log_guard.py # Core tool: detection, masking, CLI, config, directory scanning
|
|
206
|
+
├── log_guard.py # Core tool: detection, masking, spreadsheets, CLI, config, directory scanning
|
|
187
207
|
├── test_log_guard.py # Automated test suite (pytest)
|
|
188
|
-
├── pyproject.toml # Packaging config (PyPI metadata + the `log-guard` command)
|
|
208
|
+
├── pyproject.toml # Packaging config (PyPI metadata, dependencies + the `log-guard` command)
|
|
189
209
|
├── .pre-commit-hooks.yaml # Lets others use Log Guard as a pre-commit hook
|
|
190
210
|
├── .log-guard.json.example # Example project config file
|
|
191
211
|
├── sample.log # Example log file for testing
|
|
192
212
|
├── generate_samples.py # Generates edge-case sample files for manual testing
|
|
193
213
|
├── generate_test_logs_dir.py # Generates a sample directory tree for directory-scanning tests
|
|
214
|
+
├── generate_xlsx_sample.py # Generates a sample .xlsx workbook (and can print any .xlsx file's contents)
|
|
215
|
+
├── RELEASING.md # Step-by-step checklist for publishing a new version
|
|
194
216
|
└── README.md
|
|
195
217
|
```
|
|
196
218
|
|
|
@@ -198,12 +220,15 @@ log-guard/
|
|
|
198
220
|
|
|
199
221
|
- Detection is regex-based, so like any pattern-matching approach it can occasionally miss unusual formats (false negatives) or flag something that isn't actually sensitive (false positives) — especially the generic long-token API key fallback, which can flag any long run of random-looking characters.
|
|
200
222
|
- Currently focused on common US-style phone number and card formats.
|
|
201
|
-
- **
|
|
223
|
+
- **Supported file types:** plain-text files and `.xlsx` spreadsheets. Old `.xls` files are not supported (re-save them as `.xlsx`), and other binary formats such as PDF or Word documents are not read.
|
|
224
|
+
- **Spreadsheet scanning covers cell values only.** Formulas are deliberately left untouched (masking text inside a formula could break it), and cell comments, headers/footers, sheet names, and text inside charts or images are not scanned.
|
|
225
|
+
- **Masked spreadsheets may lose some extras.** The masked copy keeps every sheet, all cell values, and basic formatting, but charts, images, and some advanced Excel features may not survive — a limitation of the `openpyxl` library used to read and write them. Your original file is never changed.
|
|
226
|
+
- **Spreadsheets are loaded into memory in full**, so very large workbooks need correspondingly more RAM. (Text logs are streamed line by line and don't have this limit.)
|
|
202
227
|
- This tool reduces the risk of accidentally sharing sensitive data, but it isn't a substitute for careful review of anything genuinely high-stakes before sharing.
|
|
203
228
|
|
|
204
229
|
## Roadmap
|
|
205
230
|
|
|
206
|
-
- [
|
|
231
|
+
- [x] `.xlsx` spreadsheet support (via `openpyxl`)
|
|
207
232
|
- [x] PyPI packaging (`pip install logguard-cli`)
|
|
208
233
|
|
|
209
234
|
## License
|
|
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "logguard-cli"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "A 100% local, offline CLI tool that scans log files and masks sensitive data (emails, phone numbers, API keys, IPs, credit cards) before you share them."
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "A 100% local, offline CLI tool that scans log files and Excel (.xlsx) spreadsheets and masks sensitive data (emails, phone numbers, API keys, IPs, credit cards) before you share them."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
11
11
|
license = "MIT"
|
|
@@ -24,6 +24,8 @@ keywords = [
|
|
|
24
24
|
"sensitive-data",
|
|
25
25
|
"cli",
|
|
26
26
|
"pre-commit",
|
|
27
|
+
"excel",
|
|
28
|
+
"xlsx",
|
|
27
29
|
]
|
|
28
30
|
classifiers = [
|
|
29
31
|
"Development Status :: 4 - Beta",
|
|
@@ -41,6 +43,10 @@ classifiers = [
|
|
|
41
43
|
"Topic :: System :: Logging",
|
|
42
44
|
"Topic :: Utilities",
|
|
43
45
|
]
|
|
46
|
+
dependencies = [
|
|
47
|
+
"openpyxl>=3.1",
|
|
48
|
+
"defusedxml>=0.7",
|
|
49
|
+
]
|
|
44
50
|
|
|
45
51
|
[project.urls]
|
|
46
52
|
Homepage = "https://github.com/apurvaraj9/log-guard"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|