tailog 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/views/layout.erb +7 -0
- data/app/views/logs/index.erb +7 -1
- data/lib/tailog/version.rb +1 -1
- data/lib/tailog/watch_methods.rb +51 -5
- data/lib/tailog.rb +8 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 914e8459facfbf86b6b5afcf9cfb4295b90e2e51
|
4
|
+
data.tar.gz: b93bb99feac3de16f18e5b2d551413bede3f4801
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06edb9cb1315b271b5052153612f251189bc536fab37dc4f1733b4e583c3f09a940abc7bd3efd838cfcb6ce7952b45de6c526cd95e97d63b9a7e58891cf2466d
|
7
|
+
data.tar.gz: 09db93c829ea9d362d24e8622a2ca5af33686b50e9572dcdca31de90ae2c243a2a4330afca86b9f3e1f421b2cf1747cb90d9484ef39b259b477e70707e91be09
|
data/app/views/layout.erb
CHANGED
data/app/views/logs/index.erb
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
<div id="content" class="content-hover"></div>
|
11
11
|
<% end %>
|
12
12
|
|
13
|
+
<a id="add_divider" class="btn btn-danger pull-right">Add Divider</a>
|
14
|
+
|
13
15
|
<script type="text/javascript">
|
14
16
|
window.fileSize = {};
|
15
17
|
window.fileSizeDone = {};
|
@@ -17,6 +19,10 @@
|
|
17
19
|
$document = $(document),
|
18
20
|
$content = $("#content");
|
19
21
|
|
22
|
+
$("#add_divider").click(function() {
|
23
|
+
$content.append('<span class="divider">' + new Date() + '</span>');
|
24
|
+
});
|
25
|
+
|
20
26
|
function loadMore() {
|
21
27
|
$.post(window.location.href, { seek: window.fileSize }, function(json) {
|
22
28
|
try {
|
@@ -30,7 +36,7 @@
|
|
30
36
|
if (!data.content) return;
|
31
37
|
var shouldScrollToBottom = $window.scrollTop() + $window.height() == $document.height();
|
32
38
|
$content
|
33
|
-
.append('<span class="text-info">' + data.server_hostname + '</span>')
|
39
|
+
.append('<span class="text-info">' + data.server_hostname + ' - ' + data.file_size + '</span>')
|
34
40
|
.append(data.content);
|
35
41
|
|
36
42
|
if (shouldScrollToBottom) {
|
data/lib/tailog/version.rb
CHANGED
data/lib/tailog/watch_methods.rb
CHANGED
@@ -1,10 +1,55 @@
|
|
1
1
|
require 'active_support/core_ext/string'
|
2
|
+
require 'active_support/configurable'
|
3
|
+
require 'securerandom'
|
2
4
|
require 'logger'
|
3
5
|
|
4
6
|
module Tailog
|
5
7
|
module WatchMethods
|
6
|
-
|
7
|
-
|
8
|
+
include ActiveSupport::Configurable
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :request_id
|
12
|
+
|
13
|
+
def logger
|
14
|
+
return @logger if @logger
|
15
|
+
@logger = Logger.new(File.join Tailog.log_path, "watch_methods.log")
|
16
|
+
@logger.formatter = proc do |severity, datetime, progname, message|
|
17
|
+
content = ""
|
18
|
+
content << "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}]"
|
19
|
+
content << "[#{Tailog::WatchMethods.request_id}]" if Tailog::WatchMethods.request_id
|
20
|
+
content << " #{severity.rjust(5)}"
|
21
|
+
content << " (#{progname})" if progname
|
22
|
+
content << ": #{message.gsub(/\\n\\s*/, " ")}"
|
23
|
+
content << "\n"
|
24
|
+
content
|
25
|
+
end
|
26
|
+
@logger
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class RequestId
|
31
|
+
def initialize(app)
|
32
|
+
@app = app
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(env)
|
36
|
+
Tailog::WatchMethods.request_id = external_request_id(env) || internal_request_id
|
37
|
+
@app.call(env).tap do |_status, headers, _body|
|
38
|
+
headers["X-Request-Id"] = Tailog::WatchMethods.request_id
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def external_request_id(env)
|
45
|
+
if request_id = env["HTTP_X_REQUEST_ID"].presence
|
46
|
+
request_id.gsub(/[^\w\-]/, "").first(255)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def internal_request_id
|
51
|
+
SecureRandom.uuid
|
52
|
+
end
|
8
53
|
end
|
9
54
|
|
10
55
|
def inject_methods targets
|
@@ -49,13 +94,14 @@ module Tailog
|
|
49
94
|
unless instance_methods.include?(:#{raw_method})
|
50
95
|
alias_method :#{raw_method}, :#{method}
|
51
96
|
def #{method} *args
|
52
|
-
Tailog::WatchMethods.logger.info "Method called: #{target}, self: \#{self.inspect}, arguments: \#{args.inspect}"
|
53
97
|
start = Time.now
|
98
|
+
call_id = SecureRandom.uuid
|
99
|
+
Tailog::WatchMethods.logger.info "[\#{call_id}] #{target} CALLED: self: \#{self.inspect}, arguments: \#{args.inspect}"
|
54
100
|
result = send :#{raw_method}, *args
|
55
|
-
Tailog::WatchMethods.logger.info "
|
101
|
+
Tailog::WatchMethods.logger.info "[\#{call_id}] #{target} FINISHED: \#{(Time.now - start) * 1000} ms, result: \#{result.inspect}"
|
56
102
|
result
|
57
103
|
rescue => error
|
58
|
-
Tailog::WatchMethods.logger.error "
|
104
|
+
Tailog::WatchMethods.logger.error "[\#{call_id}] #{target} FAILED: \#{error.class} - \#{error.message} => \#{error.backtrace.join(", ")}"
|
59
105
|
raise error
|
60
106
|
end
|
61
107
|
else
|
data/lib/tailog.rb
CHANGED
@@ -3,21 +3,22 @@ require 'tailog/watch_methods'
|
|
3
3
|
require 'tailog/ext/file'
|
4
4
|
|
5
5
|
require 'sinatra/base'
|
6
|
-
require 'active_support/configurable'
|
7
|
-
|
8
6
|
require 'socket'
|
9
7
|
require 'open3'
|
10
8
|
require 'json'
|
11
9
|
|
12
10
|
module Tailog
|
13
|
-
include ActiveSupport::Configurable
|
14
11
|
extend Tailog::WatchMethods
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
class << self
|
14
|
+
attr_accessor :log_path
|
15
|
+
|
16
|
+
def server_hostname
|
17
|
+
@server_hostname ||= Socket.gethostname
|
18
|
+
end
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
self.server_hostname = Socket.gethostname
|
21
|
+
self.log_path = File.expand_path("log", Dir.pwd)
|
21
22
|
|
22
23
|
class App < Sinatra::Base
|
23
24
|
set :root, File.expand_path("../../app", __FILE__)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tailog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bbtfr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|