log-search 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +226 -0
- package/bin/log-search.js +45 -0
- package/dist/cli/commands/clear.d.ts +9 -0
- package/dist/cli/commands/clear.d.ts.map +1 -0
- package/dist/cli/commands/clear.js +116 -0
- package/dist/cli/commands/clear.js.map +1 -0
- package/dist/cli/commands/index.d.ts +8 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +118 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/info.d.ts +8 -0
- package/dist/cli/commands/info.d.ts.map +1 -0
- package/dist/cli/commands/info.js +96 -0
- package/dist/cli/commands/info.js.map +1 -0
- package/dist/cli/commands/search.d.ts +9 -0
- package/dist/cli/commands/search.d.ts.map +1 -0
- package/dist/cli/commands/search.js +178 -0
- package/dist/cli/commands/search.js.map +1 -0
- package/dist/cli/commands/watch.d.ts +8 -0
- package/dist/cli/commands/watch.d.ts.map +1 -0
- package/dist/cli/commands/watch.js +141 -0
- package/dist/cli/commands/watch.js.map +1 -0
- package/dist/cli/main.d.ts +6 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +57 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/output/colorizer.d.ts +36 -0
- package/dist/cli/output/colorizer.d.ts.map +1 -0
- package/dist/cli/output/colorizer.js +101 -0
- package/dist/cli/output/colorizer.js.map +1 -0
- package/dist/cli/output/formatter.d.ts +31 -0
- package/dist/cli/output/formatter.d.ts.map +1 -0
- package/dist/cli/output/formatter.js +146 -0
- package/dist/cli/output/formatter.js.map +1 -0
- package/dist/cli/output/table.d.ts +12 -0
- package/dist/cli/output/table.d.ts.map +1 -0
- package/dist/cli/output/table.js +48 -0
- package/dist/cli/output/table.js.map +1 -0
- package/dist/core/indexer/ChunkProcessor.d.ts +21 -0
- package/dist/core/indexer/ChunkProcessor.d.ts.map +1 -0
- package/dist/core/indexer/ChunkProcessor.js +105 -0
- package/dist/core/indexer/ChunkProcessor.js.map +1 -0
- package/dist/core/indexer/IndexBuilder.d.ts +47 -0
- package/dist/core/indexer/IndexBuilder.d.ts.map +1 -0
- package/dist/core/indexer/IndexBuilder.js +274 -0
- package/dist/core/indexer/IndexBuilder.js.map +1 -0
- package/dist/core/indexer/IndexSerializer.d.ts +30 -0
- package/dist/core/indexer/IndexSerializer.d.ts.map +1 -0
- package/dist/core/indexer/IndexSerializer.js +142 -0
- package/dist/core/indexer/IndexSerializer.js.map +1 -0
- package/dist/core/indexer/OffsetMapper.d.ts +55 -0
- package/dist/core/indexer/OffsetMapper.d.ts.map +1 -0
- package/dist/core/indexer/OffsetMapper.js +94 -0
- package/dist/core/indexer/OffsetMapper.js.map +1 -0
- package/dist/core/indexer/TokenExtractor.d.ts +27 -0
- package/dist/core/indexer/TokenExtractor.d.ts.map +1 -0
- package/dist/core/indexer/TokenExtractor.js +92 -0
- package/dist/core/indexer/TokenExtractor.js.map +1 -0
- package/dist/core/searcher/IndexSearcher.d.ts +37 -0
- package/dist/core/searcher/IndexSearcher.d.ts.map +1 -0
- package/dist/core/searcher/IndexSearcher.js +360 -0
- package/dist/core/searcher/IndexSearcher.js.map +1 -0
- package/dist/core/searcher/RankEngine.d.ts +29 -0
- package/dist/core/searcher/RankEngine.d.ts.map +1 -0
- package/dist/core/searcher/RankEngine.js +90 -0
- package/dist/core/searcher/RankEngine.js.map +1 -0
- package/dist/core/searcher/ResultFetcher.d.ts +37 -0
- package/dist/core/searcher/ResultFetcher.d.ts.map +1 -0
- package/dist/core/searcher/ResultFetcher.js +118 -0
- package/dist/core/searcher/ResultFetcher.js.map +1 -0
- package/dist/core/streaming/ChunkSplitter.d.ts +25 -0
- package/dist/core/streaming/ChunkSplitter.d.ts.map +1 -0
- package/dist/core/streaming/ChunkSplitter.js +71 -0
- package/dist/core/streaming/ChunkSplitter.js.map +1 -0
- package/dist/core/streaming/FileStreamer.d.ts +39 -0
- package/dist/core/streaming/FileStreamer.d.ts.map +1 -0
- package/dist/core/streaming/FileStreamer.js +138 -0
- package/dist/core/streaming/FileStreamer.js.map +1 -0
- package/dist/core/streaming/LineBuffer.d.ts +26 -0
- package/dist/core/streaming/LineBuffer.d.ts.map +1 -0
- package/dist/core/streaming/LineBuffer.js +52 -0
- package/dist/core/streaming/LineBuffer.js.map +1 -0
- package/dist/core/workers/IndexWorker.d.ts +8 -0
- package/dist/core/workers/IndexWorker.d.ts.map +1 -0
- package/dist/core/workers/IndexWorker.js +41 -0
- package/dist/core/workers/IndexWorker.js.map +1 -0
- package/dist/core/workers/SearchWorker.d.ts +7 -0
- package/dist/core/workers/SearchWorker.d.ts.map +1 -0
- package/dist/core/workers/SearchWorker.js +63 -0
- package/dist/core/workers/SearchWorker.js.map +1 -0
- package/dist/core/workers/WorkerPool.d.ts +30 -0
- package/dist/core/workers/WorkerPool.d.ts.map +1 -0
- package/dist/core/workers/WorkerPool.js +132 -0
- package/dist/core/workers/WorkerPool.js.map +1 -0
- package/dist/formats/LogFormatDetector.d.ts +22 -0
- package/dist/formats/LogFormatDetector.d.ts.map +1 -0
- package/dist/formats/LogFormatDetector.js +123 -0
- package/dist/formats/LogFormatDetector.js.map +1 -0
- package/dist/formats/parsers/ApacheParser.d.ts +10 -0
- package/dist/formats/parsers/ApacheParser.d.ts.map +1 -0
- package/dist/formats/parsers/ApacheParser.js +54 -0
- package/dist/formats/parsers/ApacheParser.js.map +1 -0
- package/dist/formats/parsers/GenericParser.d.ts +11 -0
- package/dist/formats/parsers/GenericParser.d.ts.map +1 -0
- package/dist/formats/parsers/GenericParser.js +61 -0
- package/dist/formats/parsers/GenericParser.js.map +1 -0
- package/dist/formats/parsers/JsonParser.d.ts +12 -0
- package/dist/formats/parsers/JsonParser.d.ts.map +1 -0
- package/dist/formats/parsers/JsonParser.js +92 -0
- package/dist/formats/parsers/JsonParser.js.map +1 -0
- package/dist/formats/parsers/NginxParser.d.ts +15 -0
- package/dist/formats/parsers/NginxParser.d.ts.map +1 -0
- package/dist/formats/parsers/NginxParser.js +78 -0
- package/dist/formats/parsers/NginxParser.js.map +1 -0
- package/dist/formats/parsers/SyslogParser.d.ts +10 -0
- package/dist/formats/parsers/SyslogParser.d.ts.map +1 -0
- package/dist/formats/parsers/SyslogParser.js +73 -0
- package/dist/formats/parsers/SyslogParser.js.map +1 -0
- package/dist/formats/schemas/LogSchema.d.ts +70 -0
- package/dist/formats/schemas/LogSchema.d.ts.map +1 -0
- package/dist/formats/schemas/LogSchema.js +7 -0
- package/dist/formats/schemas/LogSchema.js.map +1 -0
- package/dist/index-store/CacheManager.d.ts +45 -0
- package/dist/index-store/CacheManager.d.ts.map +1 -0
- package/dist/index-store/CacheManager.js +84 -0
- package/dist/index-store/CacheManager.js.map +1 -0
- package/dist/index-store/FileWatcher.d.ts +39 -0
- package/dist/index-store/FileWatcher.d.ts.map +1 -0
- package/dist/index-store/FileWatcher.js +121 -0
- package/dist/index-store/FileWatcher.js.map +1 -0
- package/dist/index-store/IncrementalUpdater.d.ts +19 -0
- package/dist/index-store/IncrementalUpdater.d.ts.map +1 -0
- package/dist/index-store/IncrementalUpdater.js +62 -0
- package/dist/index-store/IncrementalUpdater.js.map +1 -0
- package/dist/index-store/IndexStore.d.ts +66 -0
- package/dist/index-store/IndexStore.d.ts.map +1 -0
- package/dist/index-store/IndexStore.js +183 -0
- package/dist/index-store/IndexStore.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/pro/alerts/AlertEngine.d.ts +35 -0
- package/dist/pro/alerts/AlertEngine.d.ts.map +1 -0
- package/dist/pro/alerts/AlertEngine.js +162 -0
- package/dist/pro/alerts/AlertEngine.js.map +1 -0
- package/dist/pro/alerts/Notifier.d.ts +23 -0
- package/dist/pro/alerts/Notifier.d.ts.map +1 -0
- package/dist/pro/alerts/Notifier.js +173 -0
- package/dist/pro/alerts/Notifier.js.map +1 -0
- package/dist/pro/alerts/RuleParser.d.ts +32 -0
- package/dist/pro/alerts/RuleParser.d.ts.map +1 -0
- package/dist/pro/alerts/RuleParser.js +86 -0
- package/dist/pro/alerts/RuleParser.js.map +1 -0
- package/dist/pro/auth/LicenseValidator.d.ts +29 -0
- package/dist/pro/auth/LicenseValidator.d.ts.map +1 -0
- package/dist/pro/auth/LicenseValidator.js +122 -0
- package/dist/pro/auth/LicenseValidator.js.map +1 -0
- package/dist/pro/auth/TokenManager.d.ts +27 -0
- package/dist/pro/auth/TokenManager.d.ts.map +1 -0
- package/dist/pro/auth/TokenManager.js +98 -0
- package/dist/pro/auth/TokenManager.js.map +1 -0
- package/dist/pro/webui/UIServer.d.ts +34 -0
- package/dist/pro/webui/UIServer.d.ts.map +1 -0
- package/dist/pro/webui/UIServer.js +353 -0
- package/dist/pro/webui/UIServer.js.map +1 -0
- package/dist/query/QueryEngine.d.ts +34 -0
- package/dist/query/QueryEngine.d.ts.map +1 -0
- package/dist/query/QueryEngine.js +187 -0
- package/dist/query/QueryEngine.js.map +1 -0
- package/dist/query/operators/AndOperator.d.ts +18 -0
- package/dist/query/operators/AndOperator.d.ts.map +1 -0
- package/dist/query/operators/AndOperator.js +55 -0
- package/dist/query/operators/AndOperator.js.map +1 -0
- package/dist/query/operators/NotOperator.d.ts +19 -0
- package/dist/query/operators/NotOperator.d.ts.map +1 -0
- package/dist/query/operators/NotOperator.js +43 -0
- package/dist/query/operators/NotOperator.js.map +1 -0
- package/dist/query/operators/OrOperator.d.ts +17 -0
- package/dist/query/operators/OrOperator.d.ts.map +1 -0
- package/dist/query/operators/OrOperator.js +54 -0
- package/dist/query/operators/OrOperator.js.map +1 -0
- package/dist/query/operators/RangeOperator.d.ts +23 -0
- package/dist/query/operators/RangeOperator.d.ts.map +1 -0
- package/dist/query/operators/RangeOperator.js +63 -0
- package/dist/query/operators/RangeOperator.js.map +1 -0
- package/dist/query/regex/FuzzyMatcher.d.ts +29 -0
- package/dist/query/regex/FuzzyMatcher.d.ts.map +1 -0
- package/dist/query/regex/FuzzyMatcher.js +89 -0
- package/dist/query/regex/FuzzyMatcher.js.map +1 -0
- package/dist/query/regex/RegexMatcher.d.ts +31 -0
- package/dist/query/regex/RegexMatcher.d.ts.map +1 -0
- package/dist/query/regex/RegexMatcher.js +73 -0
- package/dist/query/regex/RegexMatcher.js.map +1 -0
- package/dist/types/ConfigTypes.d.ts +78 -0
- package/dist/types/ConfigTypes.d.ts.map +1 -0
- package/dist/types/ConfigTypes.js +7 -0
- package/dist/types/ConfigTypes.js.map +1 -0
- package/dist/types/IndexTypes.d.ts +86 -0
- package/dist/types/IndexTypes.d.ts.map +1 -0
- package/dist/types/IndexTypes.js +7 -0
- package/dist/types/IndexTypes.js.map +1 -0
- package/dist/types/SearchTypes.d.ts +102 -0
- package/dist/types/SearchTypes.d.ts.map +1 -0
- package/dist/types/SearchTypes.js +7 -0
- package/dist/types/SearchTypes.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/fs-helpers.d.ts +9 -0
- package/dist/utils/fs-helpers.d.ts.map +1 -0
- package/dist/utils/fs-helpers.js +76 -0
- package/dist/utils/fs-helpers.js.map +1 -0
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +49 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/logger.d.ts +19 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +41 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/performance.d.ts +14 -0
- package/dist/utils/performance.d.ts.map +1 -0
- package/dist/utils/performance.js +32 -0
- package/dist/utils/performance.js.map +1 -0
- package/dist/utils/progress.d.ts +7 -0
- package/dist/utils/progress.d.ts.map +1 -0
- package/dist/utils/progress.js +22 -0
- package/dist/utils/progress.js.map +1 -0
- package/package.json +105 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 log-search contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# ⚡ log-search
|
|
2
|
+
|
|
3
|
+
> **"Search through 50GB log files in under a second"**
|
|
4
|
+
|
|
5
|
+
A blazing-fast CLI search engine for massive log files. Built on an **Inverted Index** — searches that take `grep` 2 minutes now complete in **0.3 seconds**.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🚀 Quick Start
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# First search — builds index automatically
|
|
13
|
+
npx log-search search /var/log/nginx/access.log "ERROR 500"
|
|
14
|
+
|
|
15
|
+
# Subsequent searches — instant (index reused)
|
|
16
|
+
npx log-search search /var/log/nginx/access.log "ERROR AND timeout"
|
|
17
|
+
|
|
18
|
+
# Shorthand (no subcommand needed)
|
|
19
|
+
npx log-search access.log "ERROR"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 📦 Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Global install
|
|
28
|
+
npm install -g log-search
|
|
29
|
+
|
|
30
|
+
# Or use directly
|
|
31
|
+
npx log-search --help
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Requirements:** Node.js 18+
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 🔍 Query Syntax
|
|
39
|
+
|
|
40
|
+
| Syntax | Example | Description |
|
|
41
|
+
|--------|---------|-------------|
|
|
42
|
+
| Simple | `error` | Find lines containing "error" |
|
|
43
|
+
| AND | `error AND timeout` | Both terms must appear |
|
|
44
|
+
| OR | `error OR warning` | Either term |
|
|
45
|
+
| NOT | `error NOT 404` | Exclude lines with 404 |
|
|
46
|
+
| Phrase | `"connection refused"` | Exact phrase match |
|
|
47
|
+
| Regex | `/ERROR [45]\d{2}/` | Regular expression |
|
|
48
|
+
| Fuzzy | `~erorr` | Approximate match (Jaro-Winkler) |
|
|
49
|
+
| Level | `level:ERROR` | Match log level field |
|
|
50
|
+
| Field | `status:500` | Match specific field |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 📋 Commands
|
|
55
|
+
|
|
56
|
+
### `search` — Search a log file
|
|
57
|
+
```bash
|
|
58
|
+
log-search search <file> <query> [options]
|
|
59
|
+
|
|
60
|
+
Options:
|
|
61
|
+
-n, --limit <n> Max results (default: 100)
|
|
62
|
+
-c, --context <n> Lines of context around match (default: 0)
|
|
63
|
+
-r, --regex Treat query as regex
|
|
64
|
+
-I, --case-sensitive Case-sensitive search
|
|
65
|
+
--json JSON output
|
|
66
|
+
--table Table output
|
|
67
|
+
--rebuild-index Force index rebuild
|
|
68
|
+
--since <datetime> Filter results after this time
|
|
69
|
+
--until <datetime> Filter results before this time
|
|
70
|
+
--level <level> Filter by log level (ERROR, WARN, INFO...)
|
|
71
|
+
--sort-by <field> Sort by: line or score
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### `index` — Build index manually
|
|
75
|
+
```bash
|
|
76
|
+
log-search index <file> [--force] [--workers <n>]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `info` — Show index information
|
|
80
|
+
```bash
|
|
81
|
+
log-search info <file>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### `watch` — Watch file for new content
|
|
85
|
+
```bash
|
|
86
|
+
log-search watch <file> [query] [--alert <pattern>] [--tail <n>]
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `clear` — Delete index files
|
|
90
|
+
```bash
|
|
91
|
+
log-search clear <file>
|
|
92
|
+
log-search clear --all
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## ⚡ Performance
|
|
98
|
+
|
|
99
|
+
| File Size | grep (SSD) | log-search (1st run) | log-search (cached) |
|
|
100
|
+
|-----------|-----------|---------------------|---------------------|
|
|
101
|
+
| 1 GB | ~2s | ~8s (build) | **0.05s** |
|
|
102
|
+
| 10 GB | ~20s | ~45s (build) | **0.1s** |
|
|
103
|
+
| 50 GB | ~100s | ~3min (build) | **0.3s** |
|
|
104
|
+
| 100 GB | ~200s | ~6min (build) | **0.5s** |
|
|
105
|
+
|
|
106
|
+
**How?** Builds an Inverted Index (term → byte offsets). Searches jump directly to matching lines — no full file scan.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 💡 Usage Examples
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Basic search
|
|
114
|
+
log-search app.log "ERROR"
|
|
115
|
+
|
|
116
|
+
# AND search
|
|
117
|
+
log-search app.log "ERROR AND database"
|
|
118
|
+
|
|
119
|
+
# Regex
|
|
120
|
+
log-search app.log --regex "ERROR [45]\d{2}"
|
|
121
|
+
|
|
122
|
+
# Time range
|
|
123
|
+
log-search app.log "ERROR" --since "2024-01-01" --until "2024-01-31"
|
|
124
|
+
|
|
125
|
+
# Context lines
|
|
126
|
+
log-search app.log "FATAL" --context 5
|
|
127
|
+
|
|
128
|
+
# JSON output for piping
|
|
129
|
+
log-search app.log "ERROR 500" --json | jq '.results[0].content'
|
|
130
|
+
|
|
131
|
+
# Watch with alert
|
|
132
|
+
log-search watch app.log --alert "FATAL" --tail 20
|
|
133
|
+
|
|
134
|
+
# Build index first
|
|
135
|
+
log-search index /var/log/nginx/access.log --workers 4
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## 🏗️ Architecture
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
log-search/
|
|
144
|
+
├── src/
|
|
145
|
+
│ ├── core/
|
|
146
|
+
│ │ ├── indexer/ ← Inverted index building (parallel workers)
|
|
147
|
+
│ │ ├── searcher/ ← Index-based search + BM25 scoring
|
|
148
|
+
│ │ ├── streaming/ ← Efficient file streaming
|
|
149
|
+
│ │ └── workers/ ← Worker thread pool
|
|
150
|
+
│ ├── index-store/ ← Index registry + LRU cache
|
|
151
|
+
│ ├── formats/ ← Auto-detect + parse Nginx/Apache/JSON/Syslog
|
|
152
|
+
│ ├── query/ ← Full query parser (AND/OR/NOT/regex/fuzzy)
|
|
153
|
+
│ ├── cli/ ← CLI commands + output formatters
|
|
154
|
+
│ └── pro/ ← Pro features (alerts, web UI, license)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Key algorithm:**
|
|
158
|
+
1. **Index build:** Split file into 64MB chunks → process in parallel workers → merge into single inverted index → compress with gzip → save as `.lsi` file
|
|
159
|
+
2. **Search:** Parse query → look up terms in index → get byte offsets → seek directly to those offsets → fetch line content → score with BM25 → return results
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 🔓 Free vs Pro
|
|
164
|
+
|
|
165
|
+
### Free (MIT)
|
|
166
|
+
- ✅ Unlimited local file search
|
|
167
|
+
- ✅ Full query syntax (AND/OR/NOT/regex/fuzzy)
|
|
168
|
+
- ✅ All log format parsers
|
|
169
|
+
- ✅ Watch mode
|
|
170
|
+
- ✅ JSON/Table output
|
|
171
|
+
- ✅ Programmatic API
|
|
172
|
+
|
|
173
|
+
### Pro ($12/month)
|
|
174
|
+
- ✅ **Web UI** at `localhost:7777`
|
|
175
|
+
- ✅ **Real-time alerts** → Slack/Discord/PagerDuty/Email/Webhook
|
|
176
|
+
- ✅ **Multi-file search** across directories
|
|
177
|
+
- ✅ **REST API** at `localhost:7778`
|
|
178
|
+
- ✅ **Periodic reports** (daily/weekly error patterns)
|
|
179
|
+
- ✅ Priority support
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Activate Pro
|
|
183
|
+
log-search pro activate LSEARCH-XXXX-XXXX-XXXX-XXXX
|
|
184
|
+
|
|
185
|
+
# Start Web UI
|
|
186
|
+
log-search pro ui
|
|
187
|
+
|
|
188
|
+
# Start alert engine
|
|
189
|
+
log-search pro alert app.log --rules ./alert-rules.json
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## 🛠️ Programmatic API
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { IndexBuilder, IndexSearcher } from 'log-search';
|
|
198
|
+
|
|
199
|
+
// Build index
|
|
200
|
+
const builder = new IndexBuilder('./app.log');
|
|
201
|
+
const result = await builder.build((pct) => console.log(`${pct}%`));
|
|
202
|
+
|
|
203
|
+
// Search
|
|
204
|
+
const searcher = new IndexSearcher('./app.log');
|
|
205
|
+
await searcher.loadIndex(result.indexPath);
|
|
206
|
+
|
|
207
|
+
const hits = await searcher.search('ERROR AND timeout', {
|
|
208
|
+
limit: 100,
|
|
209
|
+
context: 2,
|
|
210
|
+
since: '2024-01-01',
|
|
211
|
+
level: 'ERROR',
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
console.log(`Found ${hits.length} matches`);
|
|
215
|
+
hits.forEach((h) => console.log(`Line ${h.lineNumber}: ${h.content}`));
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## 📄 License
|
|
221
|
+
|
|
222
|
+
MIT — see [LICENSE](./LICENSE)
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
*TIMSoftDZ*
|
|
226
|
+
*Built for DevOps engineers who are tired of waiting for grep.*
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* log-search — Entry Point
|
|
5
|
+
* Checks Node.js version first, then launches the CLI.
|
|
6
|
+
* Supports both `log-search` and `lsearch` aliases.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
// ─── Node.js Version Check ────────────────────────────────────────────────────
|
|
12
|
+
const [major] = process.versions.node.split('.').map(Number);
|
|
13
|
+
|
|
14
|
+
if (major < 18) {
|
|
15
|
+
console.error(
|
|
16
|
+
'\x1b[31m[log-search] Error:\x1b[0m Node.js 18+ is required.\n' +
|
|
17
|
+
`Current version: v${process.versions.node}\n` +
|
|
18
|
+
'Please upgrade: https://nodejs.org'
|
|
19
|
+
);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ─── Source Map Support (for TypeScript stack traces) ─────────────────────────
|
|
24
|
+
try {
|
|
25
|
+
require('source-map-support/register');
|
|
26
|
+
} catch (_) {
|
|
27
|
+
// Source map support is optional — silently ignore if not installed
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ─── Global Error Handlers ────────────────────────────────────────────────────
|
|
31
|
+
process.on('uncaughtException', (err) => {
|
|
32
|
+
console.error('\x1b[31m[log-search] Uncaught Exception:\x1b[0m', err.message);
|
|
33
|
+
if (process.env.DEBUG) {
|
|
34
|
+
console.error(err.stack);
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
process.on('unhandledRejection', (reason) => {
|
|
40
|
+
console.error('\x1b[31m[log-search] Unhandled Rejection:\x1b[0m', reason);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ─── Launch CLI ───────────────────────────────────────────────────────────────
|
|
45
|
+
require('../dist/cli/main');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* clear.ts
|
|
3
|
+
* Delete index files for one or all files.
|
|
4
|
+
* Usage: log-search clear <file> — clear index for a specific file
|
|
5
|
+
* log-search clear --all — clear ALL indexes
|
|
6
|
+
*/
|
|
7
|
+
import { Command } from 'commander';
|
|
8
|
+
export declare function createClearCommand(): Command;
|
|
9
|
+
//# sourceMappingURL=clear.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/clear.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,kBAAkB,IAAI,OAAO,CAsE5C"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* clear.ts
|
|
4
|
+
* Delete index files for one or all files.
|
|
5
|
+
* Usage: log-search clear <file> — clear index for a specific file
|
|
6
|
+
* log-search clear --all — clear ALL indexes
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.createClearCommand = createClearCommand;
|
|
46
|
+
const commander_1 = require("commander");
|
|
47
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const IndexStore_1 = require("../../index-store/IndexStore");
|
|
50
|
+
const formatter_1 = require("../output/formatter");
|
|
51
|
+
function createClearCommand() {
|
|
52
|
+
return new commander_1.Command('clear')
|
|
53
|
+
.alias('c')
|
|
54
|
+
.description('Delete cached index files')
|
|
55
|
+
.argument('[file]', 'Path to the log file (optional — omit with --all)')
|
|
56
|
+
.option('--all', 'Clear ALL cached indexes', false)
|
|
57
|
+
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
58
|
+
.action(async (file, options) => {
|
|
59
|
+
const store = new IndexStore_1.IndexStore();
|
|
60
|
+
if (options.all) {
|
|
61
|
+
const entries = await store.listAll();
|
|
62
|
+
if (entries.length === 0) {
|
|
63
|
+
formatter_1.OutputFormatter.printInfo('No indexes found to clear.');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
console.log(chalk_1.default.bold(`\n About to delete ${entries.length} index(es):`));
|
|
67
|
+
for (const e of entries) {
|
|
68
|
+
console.log(chalk_1.default.dim(` • ${e.indexPath}`));
|
|
69
|
+
}
|
|
70
|
+
console.log('');
|
|
71
|
+
if (!options.yes) {
|
|
72
|
+
const { default: inquirer } = await Promise.resolve().then(() => __importStar(require('inquirer')));
|
|
73
|
+
const { confirm } = await inquirer.prompt([
|
|
74
|
+
{ type: 'confirm', name: 'confirm', message: 'Delete all indexes?', default: false },
|
|
75
|
+
]);
|
|
76
|
+
if (!confirm) {
|
|
77
|
+
formatter_1.OutputFormatter.printInfo('Aborted.');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
let deleted = 0;
|
|
82
|
+
for (const e of entries) {
|
|
83
|
+
try {
|
|
84
|
+
fs.unlinkSync(e.indexPath);
|
|
85
|
+
deleted++;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Ignore if already gone
|
|
89
|
+
}
|
|
90
|
+
await store.removeEntry(e.filePath);
|
|
91
|
+
}
|
|
92
|
+
formatter_1.OutputFormatter.printInfo(`Deleted ${deleted} index file(s).`);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
// Single file
|
|
96
|
+
if (!file) {
|
|
97
|
+
formatter_1.OutputFormatter.printError('Please specify a file or use --all.');
|
|
98
|
+
process.exit(1);
|
|
99
|
+
}
|
|
100
|
+
const indexPath = await store.getIndexPath(file);
|
|
101
|
+
if (!indexPath) {
|
|
102
|
+
formatter_1.OutputFormatter.printWarning(`No index found for: ${file}`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
fs.unlinkSync(indexPath);
|
|
107
|
+
await store.removeEntry(file);
|
|
108
|
+
formatter_1.OutputFormatter.printInfo(`Index cleared: ${indexPath}`);
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
formatter_1.OutputFormatter.printError(`Failed to delete index: ${err}`);
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=clear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear.js","sourceRoot":"","sources":["../../../src/cli/commands/clear.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQH,gDAsEC;AA5ED,yCAAoC;AACpC,kDAA0B;AAC1B,uCAAyB;AACzB,6DAA0D;AAC1D,mDAAsD;AAEtD,SAAgB,kBAAkB;IAChC,OAAO,IAAI,mBAAO,CAAC,OAAO,CAAC;SACxB,KAAK,CAAC,GAAG,CAAC;SACV,WAAW,CAAC,2BAA2B,CAAC;SACxC,QAAQ,CAAC,QAAQ,EAAE,mDAAmD,CAAC;SACvE,MAAM,CAAC,OAAO,EAAE,0BAA0B,EAAE,KAAK,CAAC;SAClD,MAAM,CAAC,WAAW,EAAE,0BAA0B,EAAE,KAAK,CAAC;SACtD,MAAM,CAAC,KAAK,EAAE,IAAwB,EAAE,OAA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AAO,EAAE,CAAC;gBACZ,CAAC;gBAAC,MAAM,CAAC;oBACP,yBAAyB;gBAC3B,CAAC;gBACD,MAAM,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;YACtC,CAAC;YAED,2BAAe,CAAC,SAAS,CAAC,WAAW,OAAO,iBAAiB,CAAC,CAAC;YAC/D,OAAO;QACT,CAAC;QAED,cAAc;QACd,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,2BAAe,CAAC,UAAU,CAAC,qCAAqC,CAAC,CAAC;YAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACjD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,2BAAe,CAAC,YAAY,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;YAC5D,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YACzB,MAAM,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YAC9B,2BAAe,CAAC,SAAS,CAAC,kBAAkB,SAAS,EAAE,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,2BAAe,CAAC,UAAU,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAC;YAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* index.ts (CLI command)
|
|
3
|
+
* Manually build the index for a file without searching.
|
|
4
|
+
* Usage: log-search index <file> [options]
|
|
5
|
+
*/
|
|
6
|
+
import { Command } from 'commander';
|
|
7
|
+
export declare function createIndexCommand(): Command;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,wBAAgB,kBAAkB,IAAI,OAAO,CA4E5C"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* index.ts (CLI command)
|
|
4
|
+
* Manually build the index for a file without searching.
|
|
5
|
+
* Usage: log-search index <file> [options]
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.createIndexCommand = createIndexCommand;
|
|
45
|
+
const commander_1 = require("commander");
|
|
46
|
+
const ora_1 = __importDefault(require("ora"));
|
|
47
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
48
|
+
const path = __importStar(require("path"));
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const IndexBuilder_1 = require("../../core/indexer/IndexBuilder");
|
|
51
|
+
const IndexStore_1 = require("../../index-store/IndexStore");
|
|
52
|
+
const LogFormatDetector_1 = require("../../formats/LogFormatDetector");
|
|
53
|
+
const formatter_1 = require("../output/formatter");
|
|
54
|
+
function createIndexCommand() {
|
|
55
|
+
return new commander_1.Command('index')
|
|
56
|
+
.alias('i')
|
|
57
|
+
.description('Build (or rebuild) the search index for a log file')
|
|
58
|
+
.argument('<file>', 'Path to the log file to index')
|
|
59
|
+
.option('--force', 'Force rebuild even if index exists', false)
|
|
60
|
+
.option('--chunk-size <mb>', 'Chunk size in MB for parallel processing', '64')
|
|
61
|
+
.option('--workers <n>', 'Number of parallel worker threads')
|
|
62
|
+
.action(async (file, options) => {
|
|
63
|
+
const filePath = path.resolve(file);
|
|
64
|
+
if (!fs.existsSync(filePath)) {
|
|
65
|
+
formatter_1.OutputFormatter.printError(`File not found: ${filePath}`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
const store = new IndexStore_1.IndexStore();
|
|
69
|
+
const existingIndex = await store.getIndexPath(filePath);
|
|
70
|
+
if (existingIndex && !options.force) {
|
|
71
|
+
formatter_1.OutputFormatter.printWarning(`Index already exists for this file. Use --force to rebuild.`);
|
|
72
|
+
formatter_1.OutputFormatter.printInfo(`Index path: ${existingIndex}`);
|
|
73
|
+
process.exit(0);
|
|
74
|
+
}
|
|
75
|
+
// Detect format
|
|
76
|
+
const detector = new LogFormatDetector_1.LogFormatDetector();
|
|
77
|
+
const format = await detector.detect(filePath);
|
|
78
|
+
formatter_1.OutputFormatter.printInfo(`Detected format: ${chalk_1.default.bold(format)}`);
|
|
79
|
+
// Build index
|
|
80
|
+
const chunkSizeMb = parseInt(options.chunkSize, 10);
|
|
81
|
+
const maxWorkers = options.workers ? parseInt(options.workers, 10) : undefined;
|
|
82
|
+
const spinner = (0, ora_1.default)({
|
|
83
|
+
text: chalk_1.default.cyan('Indexing...'),
|
|
84
|
+
spinner: 'dots',
|
|
85
|
+
}).start();
|
|
86
|
+
const t0 = Date.now();
|
|
87
|
+
try {
|
|
88
|
+
const builder = new IndexBuilder_1.IndexBuilder(filePath, {
|
|
89
|
+
chunkSize: chunkSizeMb * 1024 * 1024,
|
|
90
|
+
maxWorkers,
|
|
91
|
+
});
|
|
92
|
+
const result = await builder.build((percent) => {
|
|
93
|
+
spinner.text = chalk_1.default.cyan(`Indexing... ${percent}%`);
|
|
94
|
+
});
|
|
95
|
+
await store.saveIndexPath(filePath, result.indexPath, {
|
|
96
|
+
totalLines: result.totalLines,
|
|
97
|
+
fileSize: result.fileSize,
|
|
98
|
+
});
|
|
99
|
+
const elapsed = ((Date.now() - t0) / 1000).toFixed(1);
|
|
100
|
+
spinner.succeed(chalk_1.default.green(`Index built successfully in ${elapsed}s`));
|
|
101
|
+
console.log('');
|
|
102
|
+
console.log(chalk_1.default.bold(' Index Stats:'));
|
|
103
|
+
console.log(chalk_1.default.dim(` File: ${filePath}`));
|
|
104
|
+
console.log(chalk_1.default.dim(` Index: ${result.indexPath}`));
|
|
105
|
+
console.log(chalk_1.default.dim(` File size: ${(result.fileSize / 1024 / 1024).toFixed(1)} MB`));
|
|
106
|
+
console.log(chalk_1.default.dim(` Total lines: ${result.totalLines.toLocaleString()}`));
|
|
107
|
+
console.log(chalk_1.default.dim(` Unique terms: ${result.uniqueTerms.toLocaleString()}`));
|
|
108
|
+
console.log(chalk_1.default.dim(` Compression: ${(result.compressionRatio * 100).toFixed(0)}%`));
|
|
109
|
+
console.log('');
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
spinner.fail(chalk_1.default.red('Indexing failed'));
|
|
113
|
+
console.error(err);
|
|
114
|
+
process.exit(1);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYH,gDA4EC;AAtFD,yCAAoC;AACpC,8CAAsB;AACtB,kDAA0B;AAC1B,2CAA6B;AAC7B,uCAAyB;AACzB,kEAA+D;AAC/D,6DAA0D;AAC1D,uEAAoE;AACpE,mDAAsD;AAEtD,SAAgB,kBAAkB;IAChC,OAAO,IAAI,mBAAO,CAAC,OAAO,CAAC;SACxB,KAAK,CAAC,GAAG,CAAC;SACV,WAAW,CAAC,oDAAoD,CAAC;SACjE,QAAQ,CAAC,QAAQ,EAAE,+BAA+B,CAAC;SACnD,MAAM,CAAC,SAAS,EAAE,oCAAoC,EAAE,KAAK,CAAC;SAC9D,MAAM,CAAC,mBAAmB,EAAE,0CAA0C,EAAE,IAAI,CAAC;SAC7E,MAAM,CAAC,eAAe,EAAE,mCAAmC,CAAC;SAC5D,MAAM,CAAC,KAAK,EAAE,IAAY,EAAE,OAAO,EAAE,EAAE;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAA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