peephole 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/app/controllers/peephole/logfiles_controller.rb +10 -2
- data/app/models/peephole/logfile.rb +15 -6
- data/app/models/peephole/logline.rb +58 -30
- data/app/views/peephole/logfiles/_breadcrumb.html.erb +11 -0
- data/app/views/peephole/logfiles/raw.html.erb +6 -0
- data/app/views/peephole/logfiles/show.html.erb +1 -8
- data/app/views/peephole/welcome/index.html.erb +6 -1
- data/config/routes.rb +1 -0
- data/lib/generators/peephole/templates/initializer.rb +2 -1
- data/lib/peephole/config.rb +4 -1
- data/lib/peephole/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c1e1d86e93630e38593455701a77a55da123ae9
|
4
|
+
data.tar.gz: 128d0ed52547503ad721e48e84c975f4cd9ff0c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9debb5b6a4edc80500caa2f70337427cc926d961783527e3bd20a8a85c43eb5fcc16c78f532f1e7f2adf72b6066cd097ceff986e7576b879f26a7c27ba4d12de
|
7
|
+
data.tar.gz: b436052310debd50fd478c75e9e3c9934380145b654ae889f974627b64d1cea9c057578441041e03a4c78e754cad05030bd0fe96197b307987b29c792df9ad90
|
data/README.md
CHANGED
@@ -3,19 +3,27 @@ require_dependency "peephole/application_controller"
|
|
3
3
|
module Peephole
|
4
4
|
class LogfilesController < ApplicationController
|
5
5
|
before_action :set_logfile
|
6
|
+
before_action :set_page, only: %i(show raw)
|
6
7
|
|
7
8
|
def show
|
8
|
-
@
|
9
|
-
@loglines, @eof = @logfile.loglines(@page)
|
9
|
+
@loglines, @eof = @logfile.lines(@page)
|
10
10
|
end
|
11
11
|
|
12
12
|
def download
|
13
13
|
send_file @logfile.path
|
14
14
|
end
|
15
15
|
|
16
|
+
def raw
|
17
|
+
@raw, @eof = @logfile.bytes(@page)
|
18
|
+
end
|
19
|
+
|
16
20
|
private
|
17
21
|
def set_logfile
|
18
22
|
@logfile = Logfile.find(params[:id])
|
19
23
|
end
|
24
|
+
|
25
|
+
def set_page
|
26
|
+
@page = params[:page].to_i.nonzero? || 1
|
27
|
+
end
|
20
28
|
end
|
21
29
|
end
|
@@ -5,10 +5,6 @@ module Peephole
|
|
5
5
|
LOG_PATH = Rails.root.join('log')
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def glob
|
9
|
-
Dir.glob(LOG_PATH.join("#{Rails.env}.log*"))
|
10
|
-
end
|
11
|
-
|
12
8
|
def all
|
13
9
|
glob.map do |path|
|
14
10
|
Logfile.new(path)
|
@@ -21,6 +17,11 @@ module Peephole
|
|
21
17
|
end
|
22
18
|
Logfile.new(path)
|
23
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def glob
|
23
|
+
Dir.glob(LOG_PATH.join("#{Rails.env}.log*"))
|
24
|
+
end
|
24
25
|
end
|
25
26
|
|
26
27
|
def initialize(path)
|
@@ -32,8 +33,12 @@ module Peephole
|
|
32
33
|
filename
|
33
34
|
end
|
34
35
|
|
35
|
-
def
|
36
|
-
Logline.
|
36
|
+
def lines(page)
|
37
|
+
Logline.lines(path, page)
|
38
|
+
end
|
39
|
+
|
40
|
+
def bytes(page)
|
41
|
+
Logline.bytes(path, page)
|
37
42
|
end
|
38
43
|
|
39
44
|
def size
|
@@ -43,5 +48,9 @@ module Peephole
|
|
43
48
|
def updated_at
|
44
49
|
File.mtime(path)
|
45
50
|
end
|
51
|
+
|
52
|
+
def gz?
|
53
|
+
File.extname(path) == '.gz'
|
54
|
+
end
|
46
55
|
end
|
47
56
|
end
|
@@ -12,52 +12,80 @@ module Peephole
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class << self
|
15
|
-
def
|
16
|
-
(page
|
15
|
+
def first_line(page)
|
16
|
+
first(page, :line)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
page
|
19
|
+
def last_line(page)
|
20
|
+
last(page, :line)
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
23
|
+
def lines(path, page)
|
24
|
+
lines = []
|
25
|
+
map = {}
|
26
26
|
eof = true
|
27
27
|
each(path, page) do |line, i|
|
28
|
-
next if i <
|
29
|
-
if i >=
|
28
|
+
next if i < first_line(page)
|
29
|
+
if i >= last_line(page)
|
30
30
|
eof = false
|
31
31
|
break
|
32
32
|
end
|
33
|
-
parse(line, i + 1,
|
33
|
+
parse(line, i + 1, lines, map)
|
34
34
|
end
|
35
|
-
[
|
35
|
+
[lines, eof]
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
line = logmap[logline.uuid].presence || logline
|
45
|
-
line.params = logline.params
|
46
|
-
loglines << line
|
47
|
-
when TYPE::COMPLETED
|
48
|
-
logmap[logline.uuid].try(:status=, logline.status)
|
49
|
-
end
|
38
|
+
def first_byte(page)
|
39
|
+
first(page, :byte)
|
40
|
+
end
|
41
|
+
|
42
|
+
def last_byte(page)
|
43
|
+
last(page, :byte)
|
50
44
|
end
|
51
45
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
def bytes(path, page)
|
47
|
+
eof = false
|
48
|
+
raw = ''
|
49
|
+
open(path) do |f|
|
50
|
+
f.seek(first_byte(page))
|
51
|
+
raw = f.read(Peephole.config.bytes_per)
|
52
|
+
eof = f.eof?
|
58
53
|
end
|
59
|
-
|
54
|
+
[raw, eof]
|
60
55
|
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def first(page, type)
|
59
|
+
(page - 1) * Peephole.config.send("#{type}s_per")
|
60
|
+
end
|
61
|
+
|
62
|
+
def last(page, type)
|
63
|
+
page * Peephole.config.send("#{type}s_per")
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse(line, num, lines, map)
|
67
|
+
logline = new(line, num)
|
68
|
+
case logline.type
|
69
|
+
when TYPE::STARTED
|
70
|
+
map[logline.uuid] = logline if logline.uuid.present?
|
71
|
+
when TYPE::PARAMS
|
72
|
+
line = map[logline.uuid].presence || logline
|
73
|
+
line.params = logline.params
|
74
|
+
lines << line
|
75
|
+
when TYPE::COMPLETED
|
76
|
+
map[logline.uuid].try(:status=, logline.status)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def each(path, page, &block)
|
81
|
+
iterator = case path.to_s
|
82
|
+
when /\.gz\z/
|
83
|
+
Zlib::GzipReader.open(path).each
|
84
|
+
else
|
85
|
+
IO.foreach(path)
|
86
|
+
end
|
87
|
+
iterator.with_index(&block)
|
88
|
+
end
|
61
89
|
end
|
62
90
|
|
63
91
|
def initialize(line, num)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<ol class="breadcrumb">
|
2
|
+
<li><%= link_to 'Home', :root %></li>
|
3
|
+
<li><%= link_to @logfile.filename, type == :line ? logfile_path(@logfile) : raw_logfile_path(@logfile) %></li>
|
4
|
+
<li class="active">
|
5
|
+
Displaying <%= type %>s
|
6
|
+
<%= Peephole::Logline.send("first_#{type}", @page) %>
|
7
|
+
-
|
8
|
+
<%= Peephole::Logline.send("last_#{type}", @page) %>
|
9
|
+
</li>
|
10
|
+
</ol>
|
11
|
+
|
@@ -1,11 +1,4 @@
|
|
1
|
-
|
2
|
-
<li><%= link_to 'Home', :root %></li>
|
3
|
-
<li><%= link_to @logfile.filename, logfile_path(@logfile) %></li>
|
4
|
-
<li class="active">
|
5
|
-
Displaying lines <%= Peephole::Logline.first(@page) %> - <%= Peephole::Logline.last(@page) %>
|
6
|
-
</li>
|
7
|
-
</ol>
|
8
|
-
|
1
|
+
<%= render 'breadcrumb', type: :line %>
|
9
2
|
<%= render 'pager' %>
|
10
3
|
|
11
4
|
<table class="table table-bordered">
|
@@ -10,7 +10,12 @@
|
|
10
10
|
<td><%= logfile.size %> KB</td>
|
11
11
|
<td><%= logfile.updated_at %></td>
|
12
12
|
<td class="text-right">
|
13
|
-
|
13
|
+
<div class="btn-group btn-group-sm">
|
14
|
+
<% unless logfile.gz? %>
|
15
|
+
<%= link_to 'Raw', raw_logfile_path(logfile), class: 'btn btn-default' %>
|
16
|
+
<% end %>
|
17
|
+
<%= link_to 'Download', download_logfile_path(logfile), class: 'btn btn-default' %>
|
18
|
+
</div>
|
14
19
|
</td>
|
15
20
|
</tr>
|
16
21
|
<% end %>
|
data/config/routes.rb
CHANGED
data/lib/peephole/config.rb
CHANGED
@@ -2,9 +2,12 @@ module Peephole
|
|
2
2
|
class Config
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
|
5
|
-
config_accessor :
|
5
|
+
config_accessor :lines_per do
|
6
6
|
200
|
7
7
|
end
|
8
|
+
config_accessor :bytes_per do
|
9
|
+
5000
|
10
|
+
end
|
8
11
|
|
9
12
|
DEFAULT_PEEPER = proc { !Rails.env.production? }
|
10
13
|
def peeper?(&block)
|
data/lib/peephole/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peephole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tnantoka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -86,7 +86,9 @@ files:
|
|
86
86
|
- app/models/peephole/logfile.rb
|
87
87
|
- app/models/peephole/logline.rb
|
88
88
|
- app/views/layouts/peephole/application.html.erb
|
89
|
+
- app/views/peephole/logfiles/_breadcrumb.html.erb
|
89
90
|
- app/views/peephole/logfiles/_pager.html.erb
|
91
|
+
- app/views/peephole/logfiles/raw.html.erb
|
90
92
|
- app/views/peephole/logfiles/show.html.erb
|
91
93
|
- app/views/peephole/welcome/index.html.erb
|
92
94
|
- config/routes.rb
|