peephole 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/app/models/peephole/logline.rb +47 -33
- data/lib/peephole/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a34f72540f6b5184fa0ec850fcfd1ec47d90b77
|
4
|
+
data.tar.gz: 55023f73ab7cf00d01185d3aeb96d90d7f2c709d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44c363edac21c2f548ed02a6999cba6d7910632ad7575df390193411f1fdf0d1108953ad7410725686e05049a14898050d52000345412c679a6efaaf2d99e885
|
7
|
+
data.tar.gz: 175525369f8ed41650f645d37e9ca6376f08d179d003e0936251f5287ea1ebd5901f493a105dc8a1b970a4c6c148d32344c74ddf677892d5c22066dc54f2af2b
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Peephole
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/peephole.svg)](http://badge.fury.io/rb/peephole)
|
3
4
|
[![Circle CI](https://circleci.com/gh/tnantoka/peephole.svg?style=svg)](https://circleci.com/gh/tnantoka/peephole)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/tnantoka/peephole/badges/gpa.svg)](https://codeclimate.com/github/tnantoka/peephole)
|
5
6
|
[![Test Coverage](https://codeclimate.com/github/tnantoka/peephole/badges/coverage.svg)](https://codeclimate.com/github/tnantoka/peephole/coverage)
|
@@ -8,6 +9,12 @@ A log viewer engine for Rails.
|
|
8
9
|
|
9
10
|
![](screenshot.png)
|
10
11
|
|
12
|
+
## Requirement
|
13
|
+
|
14
|
+
- Ruby 2.2
|
15
|
+
- Rails 4.2
|
16
|
+
- `Rails.application.config.log_tags = [:uuid]`
|
17
|
+
|
11
18
|
## Installation
|
12
19
|
|
13
20
|
```
|
@@ -21,8 +21,8 @@ module Peephole
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def lines(path, page)
|
24
|
-
|
25
|
-
|
24
|
+
loglines = []
|
25
|
+
logmap = {}
|
26
26
|
eof = true
|
27
27
|
each(path, page) do |line, i|
|
28
28
|
next if i < first_line(page)
|
@@ -30,9 +30,9 @@ module Peephole
|
|
30
30
|
eof = false
|
31
31
|
break
|
32
32
|
end
|
33
|
-
parse(line, i + 1,
|
33
|
+
parse(line, i + 1, loglines, logmap)
|
34
34
|
end
|
35
|
-
[
|
35
|
+
[loglines, eof]
|
36
36
|
end
|
37
37
|
|
38
38
|
def first_byte(page)
|
@@ -44,29 +44,12 @@ module Peephole
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def bytes(path, page)
|
47
|
-
eof =
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
f.each do |line|
|
54
|
-
next if f.pos < first_byte(page)
|
55
|
-
if f.pos >= last_byte(page)
|
56
|
-
eof = false
|
57
|
-
break
|
58
|
-
end
|
59
|
-
raw << line
|
60
|
-
end
|
61
|
-
end
|
62
|
-
else
|
63
|
-
open(path) do |f|
|
64
|
-
f.seek(first_byte(page))
|
65
|
-
raw = f.read(Peephole.config.bytes_per)
|
66
|
-
eof = f.eof?
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
47
|
+
raw, eof = case path.to_s
|
48
|
+
when /\.gz\z/
|
49
|
+
raw_gz(path, page)
|
50
|
+
else
|
51
|
+
raw_txt(path, page)
|
52
|
+
end
|
70
53
|
[raw, eof]
|
71
54
|
end
|
72
55
|
|
@@ -79,20 +62,24 @@ module Peephole
|
|
79
62
|
page * Peephole.config.send("#{type}s_per")
|
80
63
|
end
|
81
64
|
|
82
|
-
def parse(line, num,
|
65
|
+
def parse(line, num, loglines, logmap)
|
83
66
|
logline = new(line, num)
|
84
67
|
case logline.type
|
85
68
|
when TYPE::STARTED
|
86
|
-
|
69
|
+
logmap[logline.uuid] = logline if logline.uuid.present?
|
87
70
|
when TYPE::PARAMS
|
88
|
-
|
89
|
-
line.params = logline.params
|
90
|
-
lines << line
|
71
|
+
parse_params(logline, loglines, logmap)
|
91
72
|
when TYPE::COMPLETED
|
92
|
-
|
73
|
+
logmap[logline.uuid].try(:status=, logline.status)
|
93
74
|
end
|
94
75
|
end
|
95
76
|
|
77
|
+
def parse_params(logline, loglines, logmap)
|
78
|
+
l = logmap[logline.uuid].presence || logline
|
79
|
+
l.params = logline.params
|
80
|
+
loglines << l
|
81
|
+
end
|
82
|
+
|
96
83
|
def each(path, page, &block)
|
97
84
|
iterator = case path.to_s
|
98
85
|
when /\.gz\z/
|
@@ -102,6 +89,33 @@ module Peephole
|
|
102
89
|
end
|
103
90
|
iterator.with_index(&block)
|
104
91
|
end
|
92
|
+
|
93
|
+
def raw_gz(path, page)
|
94
|
+
eof = true
|
95
|
+
raw = ''
|
96
|
+
Zlib::GzipReader.open(path) do |f|
|
97
|
+
f.each do |line|
|
98
|
+
next if f.pos < first_byte(page)
|
99
|
+
if f.pos >= last_byte(page)
|
100
|
+
eof = false
|
101
|
+
break
|
102
|
+
end
|
103
|
+
raw << line
|
104
|
+
end
|
105
|
+
end
|
106
|
+
[raw, eof]
|
107
|
+
end
|
108
|
+
|
109
|
+
def raw_txt(path, page)
|
110
|
+
eof = false
|
111
|
+
raw = ''
|
112
|
+
open(path) do |f|
|
113
|
+
f.seek(first_byte(page))
|
114
|
+
raw = f.read(Peephole.config.bytes_per)
|
115
|
+
eof = f.eof?
|
116
|
+
end
|
117
|
+
[raw, eof]
|
118
|
+
end
|
105
119
|
end
|
106
120
|
|
107
121
|
def initialize(line, num)
|
data/lib/peephole/version.rb
CHANGED