logviewer 1.4.0 → 1.5.1
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.
- checksums.yaml +4 -4
- data/README.md +27 -11
- data/lib/logviewer/version.rb +1 -1
- data/lib/logviewer.rb +23 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8784d7513678b085069d4383c9aaed89a93e3e542bc6a053754ccb0814ef784
|
4
|
+
data.tar.gz: 9beac9a4fd089a81ea1f5dd7305ab69813b830e136b954b93899965fe9ff500f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84ac955ffd0d95dcc1f2d3f554911500e616a328bcde2398d80ec9d2fe552a78885c588520b2863e9b99bf28ba2547ee1a5c54ddb2736452a109de80a431cdaf
|
7
|
+
data.tar.gz: ab97e9be8d51a702896c5309422599c55d9ba45b30ee2ffe8e23802817e98779f87220ff48e59ee88f3baec1c9bae1cee16ccf1d75614dbcd1698d31c3926444
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ A Ruby gem that converts NDJSON log files into a readable HTML format for easy v
|
|
6
6
|
|
7
7
|
- Converts NDJSON log files to HTML tables
|
8
8
|
- Filters logs by minimum level (trace, debug, info, warning, error, fatal)
|
9
|
-
- Displays key fields:
|
9
|
+
- Displays key fields: date, level, tag, file, function, and text
|
10
10
|
- Human-readable timestamp formatting (MM/DD HH:MM:SS)
|
11
11
|
- Simplified file paths (shows only filename, not full path)
|
12
12
|
- Color-coded log levels for easy identification
|
@@ -27,11 +27,15 @@ gem install logviewer
|
|
27
27
|
### Basic Usage
|
28
28
|
|
29
29
|
```bash
|
30
|
+
# With a specific file
|
30
31
|
logviewer example.ndjson
|
32
|
+
|
33
|
+
# Without specifying a file (auto-detects most recent .ndjson file)
|
34
|
+
logviewer
|
31
35
|
```
|
32
36
|
|
33
37
|
This will:
|
34
|
-
1. Parse the NDJSON file
|
38
|
+
1. Parse the NDJSON file (or auto-detect the most recent .ndjson file in current directory)
|
35
39
|
2. Include all log levels (debug and above)
|
36
40
|
3. Generate an HTML file in `/tmp/`
|
37
41
|
4. Open the HTML file in your default browser
|
@@ -44,6 +48,16 @@ logviewer --level info example.ndjson
|
|
44
48
|
|
45
49
|
Only shows log entries with level "info" and above (info, warning, error, fatal).
|
46
50
|
|
51
|
+
### Auto-Detection of Log Files
|
52
|
+
|
53
|
+
When no file is specified, LogViewer automatically searches the current directory for `.ndjson` files and uses the one with the most recent modification date:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
logviewer --level info
|
57
|
+
```
|
58
|
+
|
59
|
+
This will find the most recent `.ndjson` file in the current directory and apply the specified log level filter.
|
60
|
+
|
47
61
|
### Command Line Options
|
48
62
|
|
49
63
|
- `-l, --level LEVEL`: Set minimum log level (trace, debug, info, warning, error, fatal)
|
@@ -53,13 +67,16 @@ Only shows log entries with level "info" and above (info, warning, error, fatal)
|
|
53
67
|
### Examples
|
54
68
|
|
55
69
|
```bash
|
56
|
-
# Show all logs
|
70
|
+
# Show all logs from a specific file
|
57
71
|
logviewer app.ndjson
|
58
72
|
|
59
|
-
#
|
60
|
-
logviewer
|
73
|
+
# Auto-detect most recent .ndjson file and show all logs
|
74
|
+
logviewer
|
75
|
+
|
76
|
+
# Auto-detect most recent .ndjson file and show only warnings and above
|
77
|
+
logviewer --level warning
|
61
78
|
|
62
|
-
# Show only errors and fatal logs
|
79
|
+
# Show only errors and fatal logs from specific file
|
63
80
|
logviewer -l error system.ndjson
|
64
81
|
|
65
82
|
# Show version
|
@@ -70,24 +87,23 @@ logviewer --version
|
|
70
87
|
|
71
88
|
The tool expects NDJSON (newline-delimited JSON) files where each line contains a JSON object with these fields:
|
72
89
|
|
73
|
-
- `timestamp`: ISO 8601 timestamp (e.g., "2025-06-02T18:22:48.855-07:00")
|
90
|
+
- `timestamp`: ISO 8601 timestamp (e.g., "2025-06-02T18:22:48.855-07:00") (displayed as MM/DD HH:MM:SS)
|
74
91
|
- `level`: Log level (trace, debug, info, warning, error, fatal)
|
75
92
|
- `tag`: Category or module tag (e.g., "Play/manager")
|
76
93
|
- `text`: The log message
|
77
94
|
- `file`: Source file path (displayed as filename only)
|
78
|
-
- `line`: Line number in the source file
|
79
95
|
- `method`: Function/method name
|
80
96
|
|
81
97
|
Example log entry:
|
82
98
|
```json
|
83
|
-
{"timestamp":"2025-06-02T18:22:48.855-07:00","level":"info","tag":"Auth/manager","text":"User logged in successfully","file":"auth.rb","
|
99
|
+
{"timestamp":"2025-06-02T18:22:48.855-07:00","level":"info","tag":"Auth/manager","text":"User logged in successfully","file":"auth.rb","method":"login"}
|
84
100
|
```
|
85
101
|
|
86
102
|
## Output
|
87
103
|
|
88
104
|
The generated HTML file will be saved in `/tmp/` with a timestamp and automatically opened in your browser. The HTML includes:
|
89
105
|
|
90
|
-
- A wide, responsive table layout (1800px max width) with
|
106
|
+
- A wide, responsive table layout (1800px max width) with columns in order: date, level, tag, file, function, text
|
91
107
|
- Human-readable timestamps (MM/DD HH:MM:SS format)
|
92
108
|
- Color-coded log levels
|
93
109
|
- Sticky header for easy navigation
|
@@ -95,7 +111,7 @@ The generated HTML file will be saved in `/tmp/` with a timestamp and automatica
|
|
95
111
|
- Large fonts (18px base size) for excellent readability
|
96
112
|
- Simplified file display (filename only, not full paths)
|
97
113
|
- Optimized column widths with expanded text area for log messages
|
98
|
-
-
|
114
|
+
- Date, file, and function names in monospace font
|
99
115
|
- Color-coded tags for easy categorization
|
100
116
|
|
101
117
|
## Development
|
data/lib/logviewer/version.rb
CHANGED
data/lib/logviewer.rb
CHANGED
@@ -23,7 +23,7 @@ module LogViewer
|
|
23
23
|
|
24
24
|
def parse_options
|
25
25
|
OptionParser.new do |opts|
|
26
|
-
opts.banner = "Usage: logviewer [options]
|
26
|
+
opts.banner = "Usage: logviewer [options] [ndjson_file]"
|
27
27
|
|
28
28
|
opts.on('-l', '--level LEVEL', 'Minimum log level (trace, debug, info, warning, error, fatal)') do |level|
|
29
29
|
level = level.downcase
|
@@ -48,19 +48,31 @@ module LogViewer
|
|
48
48
|
end.parse!(@args)
|
49
49
|
|
50
50
|
if @args.empty?
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
@input_file = find_most_recent_ndjson_file
|
52
|
+
if @input_file.nil?
|
53
|
+
puts "Error: No .ndjson files found in current directory"
|
54
|
+
puts "Usage: logviewer [options] [ndjson_file]"
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
puts "No file specified, using most recent .ndjson file: #{@input_file}"
|
58
|
+
else
|
59
|
+
@input_file = @args[0]
|
54
60
|
end
|
55
61
|
|
56
|
-
@input_file = @args[0]
|
57
|
-
|
58
62
|
unless File.exist?(@input_file)
|
59
63
|
puts "Error: File not found: #{@input_file}"
|
60
64
|
exit 1
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
68
|
+
def find_most_recent_ndjson_file
|
69
|
+
ndjson_files = Dir.glob('*.ndjson')
|
70
|
+
return nil if ndjson_files.empty?
|
71
|
+
|
72
|
+
# Sort by modification time (most recent first) and return the first one
|
73
|
+
ndjson_files.max_by { |file| File.mtime(file) }
|
74
|
+
end
|
75
|
+
|
64
76
|
def should_include_log?(level)
|
65
77
|
return true unless level
|
66
78
|
LOG_LEVELS[level.downcase] >= LOG_LEVELS[@min_level]
|
@@ -80,7 +92,6 @@ module LogViewer
|
|
80
92
|
tag: log_entry['tag'] || '',
|
81
93
|
text: log_entry['text'] || '',
|
82
94
|
file: log_entry['file'] || '',
|
83
|
-
line: log_entry['line'],
|
84
95
|
method: log_entry['method'] || ''
|
85
96
|
}
|
86
97
|
end
|
@@ -225,12 +236,7 @@ module LogViewer
|
|
225
236
|
color: #007acc;
|
226
237
|
font-weight: 500;
|
227
238
|
}
|
228
|
-
|
229
|
-
font-family: 'Monaco', 'Menlo', monospace;
|
230
|
-
font-size: 16px;
|
231
|
-
color: #999;
|
232
|
-
text-align: right;
|
233
|
-
}
|
239
|
+
|
234
240
|
.empty {
|
235
241
|
color: #999;
|
236
242
|
font-style: italic;
|
@@ -247,13 +253,12 @@ module LogViewer
|
|
247
253
|
<table>
|
248
254
|
<thead>
|
249
255
|
<tr>
|
250
|
-
<th style="width: 120px;">
|
256
|
+
<th style="width: 120px;">Date</th>
|
251
257
|
<th style="width: 80px;">Level</th>
|
252
258
|
<th style="width: 120px;">Tag</th>
|
253
|
-
<th>Text</th>
|
254
259
|
<th style="width: 180px;">File</th>
|
255
|
-
<th style="width:
|
256
|
-
<th
|
260
|
+
<th style="width: 100px;">Function</th>
|
261
|
+
<th>Text</th>
|
257
262
|
</tr>
|
258
263
|
</thead>
|
259
264
|
<tbody>
|
@@ -267,7 +272,6 @@ module LogViewer
|
|
267
272
|
text_content = log[:text].empty? ? '<span class="empty">-</span>' : log[:text]
|
268
273
|
filename = extract_filename(log[:file])
|
269
274
|
file_content = filename.empty? ? '<span class="empty">-</span>' : filename
|
270
|
-
line_content = log[:line].nil? ? '<span class="empty">-</span>' : log[:line]
|
271
275
|
method_content = log[:method].empty? ? '<span class="empty">-</span>' : log[:method]
|
272
276
|
|
273
277
|
html += <<~HTML
|
@@ -275,10 +279,9 @@ module LogViewer
|
|
275
279
|
<td class="timestamp">#{timestamp_content}</td>
|
276
280
|
<td class="level" style="#{level_style}">#{log[:level]}</td>
|
277
281
|
<td class="tag">#{tag_content}</td>
|
278
|
-
<td class="text">#{text_content}</td>
|
279
282
|
<td class="file">#{file_content}</td>
|
280
|
-
<td class="line">#{line_content}</td>
|
281
283
|
<td class="method">#{method_content}</td>
|
284
|
+
<td class="text">#{text_content}</td>
|
282
285
|
</tr>
|
283
286
|
HTML
|
284
287
|
end
|