tailog 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1eee8873170ab412654ccf81ce8f59df6aa03667
4
- data.tar.gz: 5bedb6af7297342259ec7611c6032f9a377bb175
3
+ metadata.gz: 9e883f46101f9d9932bd47c8d275fc4c304a7026
4
+ data.tar.gz: 6ca0aa4bfc2d1806f386465153607b24d7a18683
5
5
  SHA512:
6
- metadata.gz: 5cc194e4d7df33a18a0b40ed633b0e815e7151141f8e9f82dbfb0118631f7999232a7fe73aed68f15349d9e7c8b7bb0cb7c43a74edc1dbe045b10e5b1a461092
7
- data.tar.gz: c387dcef3da18acf98217c77372535b805b381ccd7a0683e2c33409d89fc4c59a47f3bf022fa61a5812e65b16d0bae88b93fd6e85e0edae418960f11fef7af74
6
+ metadata.gz: 0a3741b98e3cf6b9bed879a6e66c12678d75c2bf3a61db9667724851d44a76186209080166d84866212770a3103f427ec0d134e98f42af0565cfa5a37a4ddb87
7
+ data.tar.gz: 3fcc682690a3242219f6af6939e2b5d3a174cc0f352f2f387810be6907a87afa04d68f9cd3db916e4cb99cfb0a78700d9769d24c8b400e9c11c02bc2d60386bb
data/app/views/layout.erb CHANGED
@@ -45,7 +45,7 @@
45
45
  <div class="container">
46
46
 
47
47
  <!-- Static navbar -->
48
- <% p path_info = request.path_info %>
48
+ <% path_info = request.path_info %>
49
49
  <nav class="navbar navbar-default">
50
50
  <div class="container-fluid">
51
51
  <div class="navbar-header">
@@ -22,15 +22,15 @@
22
22
  try {
23
23
  var data = JSON.parse(json);
24
24
 
25
- var fileSizeKey = data.server_uuid + '-' + data.file_size;
25
+ var fileSizeKey = data.server_hostname + '-' + data.file_size;
26
26
  if (window.fileSizeDone[fileSizeKey]) return;
27
27
  window.fileSizeDone[fileSizeKey] = true;
28
- window.fileSize[data.server_uuid] = data.file_size;
28
+ window.fileSize[data.server_hostname] = data.file_size;
29
29
 
30
30
  if (!data.content) return;
31
31
  var shouldScrollToBottom = $window.scrollTop() + $window.height() == $document.height();
32
32
  $content
33
- .append('<span class="text-info">' + data.server_uuid + '</span>')
33
+ .append('<span class="text-info">' + data.server_hostname + '</span>')
34
34
  .append(data.content);
35
35
 
36
36
  if (shouldScrollToBottom) {
@@ -21,6 +21,7 @@
21
21
  var data = JSON.parse(json);
22
22
  $content
23
23
  .html('<hr>')
24
+ .append('<span class="text-info">' + data.server_hostname + '</span>')
24
25
  .append(data.content);
25
26
  } catch (error) {
26
27
  console.log(error)
@@ -1,3 +1,3 @@
1
1
  module Tailog
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -9,10 +9,14 @@ module Tailog
9
9
 
10
10
  def inject_methods targets
11
11
  targets.each do |target|
12
- if target.include? "#"
13
- inject_instance_method target
14
- else
15
- inject_class_method target
12
+ begin
13
+ if target.include? "#"
14
+ inject_instance_method target
15
+ else
16
+ inject_class_method target
17
+ end
18
+ rescue => error
19
+ WatchMethods.logger.error "Inject method `#{target}' failed: #{error.class}: #{error.message}"
16
20
  end
17
21
  end
18
22
  end
@@ -30,8 +34,6 @@ module Tailog
30
34
  #{build_watch_method target, method}
31
35
  end
32
36
  EOS
33
- rescue => error
34
- WatchMethods.logger.error "Inject class method `#{target}' failed: #{error.class}: #{error.message}"
35
37
  end
36
38
 
37
39
  def inject_instance_method target
@@ -39,23 +41,25 @@ module Tailog
39
41
  klass.constantize.class_eval <<-EOS, __FILE__, __LINE__
40
42
  #{build_watch_method target, method}
41
43
  EOS
42
- rescue => error
43
- WatchMethods.logger.error "Inject instance method `#{target}' failed: #{error.class}: #{error.message}"
44
44
  end
45
45
 
46
46
  def build_watch_method target, method
47
47
  raw_method = "watch_method_raw_#{method}"
48
48
  return <<-EOS
49
- alias_method :#{raw_method}, :#{method}
50
- def #{method} *args
51
- Tailog::WatchMethods.logger.info "Method called: #{target} \#{self} with \#{args}"
52
- start = Time.now
53
- result = send :#{raw_method}, *args
54
- Tailog::WatchMethods.logger.info "Method finished: #{target} with \#{result} in \#{(Time.now - start) * 1000} ms"
55
- result
56
- rescue => error
57
- Tailog::WatchMethods.logger.error "Method failed: #{target} raises \#{error.class}: \#{error.message}\\n\#{error.backtrace.join("\\n")}"
58
- raise error
49
+ unless instance_methods.include?(:#{raw_method})
50
+ alias_method :#{raw_method}, :#{method}
51
+ def #{method} *args
52
+ Tailog::WatchMethods.logger.info "Method called: #{target}, self: \#{self.inspect}, arguments: \#{args.inspect}"
53
+ start = Time.now
54
+ result = send :#{raw_method}, *args
55
+ Tailog::WatchMethods.logger.info "Method finished: #{target} in \#{(Time.now - start) * 1000} ms, result: \#{result.inspect}"
56
+ result
57
+ rescue => error
58
+ Tailog::WatchMethods.logger.error "Method failed: #{target}, error: \#{error.class} - \#{error.message}\\n\#{error.backtrace.join("\\n")}"
59
+ raise error
60
+ end
61
+ else
62
+ Tailog::WatchMethods.logger.error "Inject method `#{target}' failed: already injected"
59
63
  end
60
64
  EOS
61
65
  end
data/lib/tailog.rb CHANGED
@@ -5,7 +5,7 @@ require 'tailog/ext/file'
5
5
  require 'sinatra/base'
6
6
  require 'active_support/configurable'
7
7
 
8
- require 'securerandom'
8
+ require 'socket'
9
9
  require 'open3'
10
10
  require 'json'
11
11
 
@@ -13,13 +13,11 @@ module Tailog
13
13
  include ActiveSupport::Configurable
14
14
  extend Tailog::WatchMethods
15
15
 
16
- config_accessor :log_path do
17
- File.expand_path("log", Dir.pwd)
18
- end
16
+ config_accessor :log_path
17
+ self.log_path = File.expand_path("log", Dir.pwd)
19
18
 
20
- config_accessor :server_uuid do
21
- SecureRandom.uuid
22
- end
19
+ config_accessor :server_hostname
20
+ self.server_hostname = Socket.gethostname
23
21
 
24
22
  class App < Sinatra::Base
25
23
  set :root, File.expand_path("../../app", __FILE__)
@@ -45,7 +43,7 @@ module Tailog
45
43
  file_path = File.join Tailog.log_path, params[:file]
46
44
  file = File.open file_path
47
45
  file_size = file.size
48
- tail = if seek = params[:seek] && params[:seek][Tailog.server_uuid]
46
+ tail = if seek = params[:seek] && params[:seek][Tailog.server_hostname]
49
47
  file.seek seek.to_i
50
48
  file
51
49
  else
@@ -58,7 +56,7 @@ module Tailog
58
56
  end
59
57
 
60
58
  {
61
- server_uuid: Tailog.server_uuid,
59
+ server_hostname: Tailog.server_hostname,
62
60
  file_size: file_size,
63
61
  content: content
64
62
  }.to_json
@@ -76,6 +74,7 @@ module Tailog
76
74
  content = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false
77
75
 
78
76
  {
77
+ server_hostname: Tailog.server_hostname,
79
78
  content: content
80
79
  }.to_json
81
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bbtfr