tailog 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e883f46101f9d9932bd47c8d275fc4c304a7026
4
- data.tar.gz: 6ca0aa4bfc2d1806f386465153607b24d7a18683
3
+ metadata.gz: 914e8459facfbf86b6b5afcf9cfb4295b90e2e51
4
+ data.tar.gz: b93bb99feac3de16f18e5b2d551413bede3f4801
5
5
  SHA512:
6
- metadata.gz: 0a3741b98e3cf6b9bed879a6e66c12678d75c2bf3a61db9667724851d44a76186209080166d84866212770a3103f427ec0d134e98f42af0565cfa5a37a4ddb87
7
- data.tar.gz: 3fcc682690a3242219f6af6939e2b5d3a174cc0f352f2f387810be6907a87afa04d68f9cd3db916e4cb99cfb0a78700d9769d24c8b400e9c11c02bc2d60386bb
6
+ metadata.gz: 06edb9cb1315b271b5052153612f251189bc536fab37dc4f1733b4e583c3f09a940abc7bd3efd838cfcb6ce7952b45de6c526cd95e97d63b9a7e58891cf2466d
7
+ data.tar.gz: 09db93c829ea9d362d24e8622a2ca5af33686b50e9572dcdca31de90ae2c243a2a4330afca86b9f3e1f421b2cf1747cb90d9484ef39b259b477e70707e91be09
data/app/views/layout.erb CHANGED
@@ -38,6 +38,13 @@
38
38
  display: inline-block;
39
39
  width: 100px;
40
40
  }
41
+
42
+ .divider {
43
+ display: block;
44
+ margin: 10px 0 20px;
45
+ color: #a94442;
46
+ border-bottom: 3px dashed #d9534f;
47
+ }
41
48
  </style>
42
49
  </head>
43
50
  <body>
@@ -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) {
@@ -1,3 +1,3 @@
1
1
  module Tailog
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -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
- def self.logger
7
- @logger ||= Logger.new(File.join Tailog.log_path, "watch_methods.log")
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 "Method finished: #{target} in \#{(Time.now - start) * 1000} ms, result: \#{result.inspect}"
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 "Method failed: #{target}, error: \#{error.class} - \#{error.message}\\n\#{error.backtrace.join("\\n")}"
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
- config_accessor :log_path
17
- self.log_path = File.expand_path("log", Dir.pwd)
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
- config_accessor :server_hostname
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.2
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-21 00:00:00.000000000 Z
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler