tailog 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/app/views/ajax.erb +15 -0
- data/app/views/index.erb +105 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tailog/version.rb +3 -0
- data/lib/tailog.rb +54 -0
- data/tailog.gemspec +31 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGU3ODNiNTE4MDdhNTIwNDEzYjYwNWIxNmY1YjZiMmYyZGM1MmI2MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YWNhZDliODQ4ODRhOGRmYzFmYzJhM2YzNjFhNWU0NmUyM2I5YzJmNQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ODY2OTBiNGEyYTYwYmI1ZDAyMjM2MGM0NzQ1Zjc0MTFjNTQ4MDc1NjRiNWIx
|
10
|
+
YzE1ZjY4MzIzM2M2YWFmODRmNjhhOGFjNDljMTc1ZjdkZmJjMWU3YzU5NTBk
|
11
|
+
MWM5OTZlZDIwMGU4NDk3NTdlZGY4Yjg3MjQ3NzM4YWFiYWY2Mjg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDQ3ZTRlYjUzMTJiYjhjMGM0NmVhZDQ3ZjUwYmNmOWY5N2RmYjljZWU0MzUz
|
14
|
+
OGYxZDJmM2JlNGExODVhOGU2N2NiNzc4MWY1NmU2YTJlNjcyYTAwY2I5OWQ3
|
15
|
+
ZmYyOTUyNzM1OTQ5NTlhMjE4ZDk3NDg1ODZiNmY5ZGMyYjg2NTI=
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at bbtfrr@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# TAILOG
|
2
|
+
|
3
|
+
Sinatra App to serve log in browser
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'tailog'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tailog
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In `config.ru`
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
run Rack::URLMap.new(
|
27
|
+
'/' => Your::App,
|
28
|
+
'/tailog' => Tailog::App
|
29
|
+
)
|
30
|
+
```
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bbtfr/tailog. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
41
|
+
|
data/Rakefile
ADDED
data/app/views/ajax.erb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<% begin %>
|
2
|
+
<% file_path = File.join Tailog.log_path, params[:file] %>
|
3
|
+
<% File.open file_path do |file| %>
|
4
|
+
<% file_size = file.size %>
|
5
|
+
<% file.seek params[:seek].to_i %>
|
6
|
+
<% file.each_line do |line| %>
|
7
|
+
<p><%= h line %></p>
|
8
|
+
<% end %>
|
9
|
+
<script type="text/javascript">
|
10
|
+
window.fileSize = <%= file_size %>;
|
11
|
+
</script>
|
12
|
+
<% end %>
|
13
|
+
<% rescue => error %>
|
14
|
+
<div class="alert alert-danger"><%= h error.message %></div>
|
15
|
+
<% end %>
|
data/app/views/index.erb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Tailog</title>
|
5
|
+
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
|
6
|
+
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
|
7
|
+
<style type="text/css">
|
8
|
+
body {
|
9
|
+
padding-top: 20px;
|
10
|
+
padding-bottom: 20px;
|
11
|
+
}
|
12
|
+
|
13
|
+
.monospace {
|
14
|
+
font-family: "Lucida Console", Monaco, monospace;
|
15
|
+
}
|
16
|
+
|
17
|
+
p {
|
18
|
+
white-space: pre-wrap;
|
19
|
+
margin: 0;
|
20
|
+
}
|
21
|
+
|
22
|
+
p:hover {
|
23
|
+
background: #EEE;
|
24
|
+
}
|
25
|
+
</style>
|
26
|
+
</head>
|
27
|
+
<body>
|
28
|
+
|
29
|
+
<div class="container">
|
30
|
+
|
31
|
+
<!-- Static navbar -->
|
32
|
+
<nav class="navbar navbar-default">
|
33
|
+
<div class="container-fluid">
|
34
|
+
<div class="navbar-header">
|
35
|
+
<a class="navbar-brand monospace">TAILOG</a>
|
36
|
+
</div>
|
37
|
+
<div id="navbar" class="navbar-collapse collapse">
|
38
|
+
<ul class="nav navbar-nav">
|
39
|
+
<li class="active"><a href="#">Home</a></li>
|
40
|
+
</ul>
|
41
|
+
<ul class="nav navbar-nav navbar-right">
|
42
|
+
<form class="navbar-form navbar-left" method="get">
|
43
|
+
<div class="input-group">
|
44
|
+
<input name="file" type="text" class="form-control" placeholder="<%= params[:file] || 'File Name...' %>">
|
45
|
+
<span class="input-group-btn">
|
46
|
+
<button class="btn btn-default" type="button">Go!</button>
|
47
|
+
</span>
|
48
|
+
</div>
|
49
|
+
</form>
|
50
|
+
</ul>
|
51
|
+
</div><!--/.nav-collapse -->
|
52
|
+
</div><!--/.container-fluid -->
|
53
|
+
</nav>
|
54
|
+
|
55
|
+
<% if params[:file] %>
|
56
|
+
<% file_path = File.join Tailog.log_path, params[:file] %>
|
57
|
+
<h3 class="page-header monospace"><%= file_path %></h3>
|
58
|
+
|
59
|
+
<% begin %>
|
60
|
+
<% File.open file_path do |file| %>
|
61
|
+
|
62
|
+
<div id="content" class="monospace">
|
63
|
+
<% file_size = file.size %>
|
64
|
+
<% file.tail(100).each do |line| %>
|
65
|
+
<p><%= h line %></p>
|
66
|
+
<% end %>
|
67
|
+
</div>
|
68
|
+
|
69
|
+
<script type="text/javascript">
|
70
|
+
window.fileSize = <%= file_size %>;
|
71
|
+
window.fileSizeDone = {};
|
72
|
+
var $window = $(window),
|
73
|
+
$document = $(document),
|
74
|
+
$content = $("#content");
|
75
|
+
|
76
|
+
setInterval(function() {
|
77
|
+
$.get(window.location.href, { seek: window.fileSize }, function(data) {
|
78
|
+
var $data = $(data);
|
79
|
+
|
80
|
+
if (window.fileSizeDone[window.fileSize]) {
|
81
|
+
return
|
82
|
+
} else if (!$data.length) {
|
83
|
+
window.fileSizeDone[window.fileSize] = true
|
84
|
+
}
|
85
|
+
|
86
|
+
if ($window.scrollTop() + $window.height() == $document.height()) {
|
87
|
+
$(data).appendTo($content);
|
88
|
+
$window.scrollTop($document.height() - $window.height())
|
89
|
+
} else {
|
90
|
+
$(data).appendTo($content);
|
91
|
+
}
|
92
|
+
});
|
93
|
+
}, 1000);
|
94
|
+
</script>
|
95
|
+
|
96
|
+
<% end %>
|
97
|
+
|
98
|
+
<% rescue => error %>
|
99
|
+
<div class="alert alert-danger"><%= h error.message %></div>
|
100
|
+
<% end %>
|
101
|
+
<% end %>
|
102
|
+
|
103
|
+
</div> <!-- /container -->
|
104
|
+
</body>
|
105
|
+
</html>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "tailog"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/tailog.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'tailog/version'
|
2
|
+
require 'sinatra/base'
|
3
|
+
|
4
|
+
class File
|
5
|
+
|
6
|
+
def tail(n)
|
7
|
+
buffer = 1024
|
8
|
+
idx = (size - buffer).abs
|
9
|
+
chunks = []
|
10
|
+
lines = 0
|
11
|
+
|
12
|
+
begin
|
13
|
+
seek(idx)
|
14
|
+
chunk = read(buffer)
|
15
|
+
lines += chunk.count("\n")
|
16
|
+
chunks.unshift chunk
|
17
|
+
idx -= buffer
|
18
|
+
end while lines < ( n + 1 ) && pos != 0
|
19
|
+
|
20
|
+
tail_of_file = chunks.join('')
|
21
|
+
ary = tail_of_file.split(/\n/)
|
22
|
+
lines_to_return = ary[ ary.size - n, ary.size - 1 ]
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module Tailog
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_accessor :log_path
|
31
|
+
end
|
32
|
+
|
33
|
+
self.log_path = File.expand_path("log", Dir.pwd)
|
34
|
+
|
35
|
+
class App < Sinatra::Base
|
36
|
+
set :root, File.expand_path("../../app", __FILE__)
|
37
|
+
set :public_folder do "#{root}/assets" end
|
38
|
+
set :views do "#{root}/views" end
|
39
|
+
|
40
|
+
helpers do
|
41
|
+
def h(text)
|
42
|
+
Rack::Utils.escape_html(text)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
get '/' do
|
47
|
+
if params[:seek]
|
48
|
+
erb :ajax
|
49
|
+
else
|
50
|
+
erb :index
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/tailog.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tailog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tailog"
|
8
|
+
spec.version = Tailog::VERSION
|
9
|
+
spec.authors = ["bbtfr"]
|
10
|
+
spec.email = ["bbtfrr@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "tail -f to the web-browser"
|
13
|
+
spec.description = "Sinatra App to serve log in browser"
|
14
|
+
spec.homepage = "https://github.com/bbtfr/tailog"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tailog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bbtfr
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Sinatra App to serve log in browser
|
42
|
+
email:
|
43
|
+
- bbtfrr@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- app/views/ajax.erb
|
54
|
+
- app/views/index.erb
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- lib/tailog.rb
|
58
|
+
- lib/tailog/version.rb
|
59
|
+
- tailog.gemspec
|
60
|
+
homepage: https://github.com/bbtfr/tailog
|
61
|
+
licenses: []
|
62
|
+
metadata:
|
63
|
+
allowed_push_host: https://rubygems.org
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.8
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: tail -f to the web-browser
|
84
|
+
test_files: []
|
85
|
+
has_rdoc:
|