onlylogs 0.13.0 → 0.14.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.
- checksums.yaml +4 -4
- data/README.md +16 -0
- data/Rakefile +2 -0
- data/app/models/onlylogs/grep.rb +31 -2
- data/lib/onlylogs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4856715cec18b6f3e8bca4cd01d3d3de18c4a6286eea249239d4a61423db5107
|
|
4
|
+
data.tar.gz: c73534414629768100cf3be121e9a06c8a0cc6841bce942dc02ed31655581432
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d25035152f19a9711cfd0ce93a238162067d1a7a070971b06eebe023569645536a63358c89d0475fd0d4201f1327aac6fc1d9a44168166278dd886564e2a788b
|
|
7
|
+
data.tar.gz: 165b9455a35fc3f4e882995ca9201340e65c13ea6074214015b529b04c5add2a828d71e29a479ad127eef1f625f2619932aaf688aba803e57338b68fb3543532
|
data/README.md
CHANGED
|
@@ -630,6 +630,22 @@ bin/rails test test/models/onlylogs/grep_performance_test.rb
|
|
|
630
630
|
> [!NOTE]
|
|
631
631
|
> Performance tests are automatically skipped in CI environments or if the large fixture files are missing.
|
|
632
632
|
|
|
633
|
+
### Release
|
|
634
|
+
|
|
635
|
+
1. Bump the version in `lib/onlylogs/version.rb`, run `bundle install`, move the `Unreleased` entries of
|
|
636
|
+
`CHANGELOG.md` under the new version and commit to `main`.
|
|
637
|
+
1. Tag the commit with the bare version and push the tag:
|
|
638
|
+
|
|
639
|
+
```bash
|
|
640
|
+
git tag -a 1.2.3 -m 1.2.3
|
|
641
|
+
git push origin 1.2.3
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
1. Create a GitHub release for the tag with the changelog section as notes.
|
|
645
|
+
|
|
646
|
+
Semaphore runs the tests on the tag and, when they pass, promotes the `release` pipeline, which pushes the gem to
|
|
647
|
+
[rubygems.org](https://rubygems.org). It fails when the tag does not match the gem version.
|
|
648
|
+
|
|
633
649
|
### Plans for the future
|
|
634
650
|
|
|
635
651
|
We believe that by simply analysing your logs you can also get error reports and performance reports. The goal is to
|
data/Rakefile
CHANGED
data/app/models/onlylogs/grep.rb
CHANGED
|
@@ -7,6 +7,10 @@ module Onlylogs
|
|
|
7
7
|
# can keep a single rescue.
|
|
8
8
|
class TimeoutError < ::Timeout::Error; end
|
|
9
9
|
|
|
10
|
+
# Raised for a pattern Ruby cannot compile, which only matters when +captures+
|
|
11
|
+
# asks Ruby to read its groups back.
|
|
12
|
+
class PatternError < ArgumentError; end
|
|
13
|
+
|
|
10
14
|
# +timeout+ is in seconds and defaults to nil, which is no deadline at all:
|
|
11
15
|
# the search runs until it finishes or the caller abandons it. The default
|
|
12
16
|
# is deliberately not a number, because only the caller knows how long it
|
|
@@ -16,9 +20,17 @@ module Onlylogs
|
|
|
16
20
|
# <tt>context: true</tt>. It needs ripgrep: plain grep is run without byte
|
|
17
21
|
# offsets, so its context lines could not be told apart from matches, and
|
|
18
22
|
# +context+ is ignored there. Context never reaches outside the byte window.
|
|
23
|
+
# +captures+ treats +pattern+ as a regular expression and yields, under
|
|
24
|
+
# <tt>captures:</tt>, what its groups matched on each match: one entry per group,
|
|
25
|
+
# or the whole match when it has none. The engine finds the line and Ruby reads
|
|
26
|
+
# the groups back from it, so a pattern the two read differently, or one that
|
|
27
|
+
# times out, yields nil there instead.
|
|
19
28
|
def self.grep(pattern, file_path, start_position: 0, end_position: nil, regexp_mode: false,
|
|
20
|
-
case_sensitive: true, max_matches: Onlylogs.max_line_matches, context: 0,
|
|
29
|
+
case_sensitive: true, max_matches: Onlylogs.max_line_matches, context: 0, captures: false,
|
|
30
|
+
timeout: nil, &block)
|
|
21
31
|
context = 0 unless Onlylogs.ripgrep_enabled?
|
|
32
|
+
regexp_mode ||= captures
|
|
33
|
+
capture_pattern = compile(pattern, case_sensitive: case_sensitive) if captures
|
|
22
34
|
command_args = search_command(pattern, file_path, start_position: start_position,
|
|
23
35
|
end_position: end_position, regexp_mode: regexp_mode, case_sensitive: case_sensitive,
|
|
24
36
|
max_matches: max_matches, context: context)
|
|
@@ -51,6 +63,7 @@ module Onlylogs
|
|
|
51
63
|
|
|
52
64
|
result = {byte_offset: byte_offset, content: content}
|
|
53
65
|
result[:context] = true if context_line
|
|
66
|
+
result[:captures] = captures_in(capture_pattern, content) if capture_pattern && !context_line
|
|
54
67
|
matches += 1 unless context_line
|
|
55
68
|
|
|
56
69
|
if block_given?
|
|
@@ -73,6 +86,21 @@ module Onlylogs
|
|
|
73
86
|
|
|
74
87
|
GROUP_SEPARATOR = "--"
|
|
75
88
|
|
|
89
|
+
def self.compile(pattern, case_sensitive:)
|
|
90
|
+
Regexp.new(pattern, case_sensitive ? nil : Regexp::IGNORECASE, timeout: MATCH_TIMEOUT)
|
|
91
|
+
rescue ::RegexpError => e
|
|
92
|
+
raise PatternError, "invalid regular expression: #{e.message}"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.captures_in(pattern, content)
|
|
96
|
+
found = pattern.match(content.gsub(ANSI_COLOR, ""))
|
|
97
|
+
return nil unless found
|
|
98
|
+
|
|
99
|
+
found.captures.empty? ? [found[0]] : found.captures
|
|
100
|
+
rescue ::Regexp::TimeoutError
|
|
101
|
+
nil
|
|
102
|
+
end
|
|
103
|
+
|
|
76
104
|
# The scripts run under LC_ALL=C. ripgrep folds case over Unicode anyway,
|
|
77
105
|
# grep then folds ASCII only: "error" finds "ERROR" with both engines, but
|
|
78
106
|
# "über" finds "Über" with ripgrep only.
|
|
@@ -186,11 +214,12 @@ module Onlylogs
|
|
|
186
214
|
end
|
|
187
215
|
|
|
188
216
|
MATCH_TIMEOUT = 0.1 # seconds
|
|
217
|
+
ANSI_COLOR = /\e\[[0-9;]*m/
|
|
189
218
|
|
|
190
219
|
# Folds case over Unicode, like ripgrep. See search_command for grep.
|
|
191
220
|
def self.match_line?(line, string, regexp_mode: false, case_sensitive: true)
|
|
192
221
|
# Strip ANSI color codes from the line before matching
|
|
193
|
-
stripped_line = line.gsub(
|
|
222
|
+
stripped_line = line.gsub(ANSI_COLOR, "")
|
|
194
223
|
# Normalize multiple spaces to single spaces
|
|
195
224
|
normalized_line = stripped_line.gsub(/\s+/, " ")
|
|
196
225
|
|
data/lib/onlylogs/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: onlylogs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alessandro Rodi
|
|
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
151
151
|
- !ruby/object:Gem::Version
|
|
152
152
|
version: '0'
|
|
153
153
|
requirements: []
|
|
154
|
-
rubygems_version:
|
|
154
|
+
rubygems_version: 4.0.8
|
|
155
155
|
specification_version: 4
|
|
156
156
|
summary: A Rails engine to view, stream, grep log files in real-time.
|
|
157
157
|
test_files: []
|