logs_viewer 0.1.0
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 +7 -0
- data/.gitignore +10 -0
- data/.idea/rails_logs_viewer.iml +24 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/logs_viewer/config.rb +10 -0
- data/lib/logs_viewer/display.rb +38 -0
- data/lib/logs_viewer/display_helper.rb +19 -0
- data/lib/logs_viewer/handler.rb +25 -0
- data/lib/logs_viewer/version.rb +3 -0
- data/lib/logs_viewer/views/display.html.erb +62 -0
- data/lib/logs_viewer.rb +10 -0
- data/logs_viewer.gemspec +27 -0
- data/spec/logs_viewer_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab05abaecdf3a5135fd390392cc4307e429ababe
|
4
|
+
data.tar.gz: deb97e3b295b5f43273b9b58a444d45076b074ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c552143a68c2a8ef92b3fe07f89b2e97f7439f9bff3b7ae44dce4222c0693f9e97cf81edad8ef291c22c3b7bb23bff168cb7d899187702649d0ccb090e5ec05
|
7
|
+
data.tar.gz: 8d0d41075e0278f083d217370b55bfbdb6a0a0a31ff9c37d499b9ea6e15395f4a08a7c84f27bd96e7262129029fae673f6d71b55f08fff4fa493e4b41997536c
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Ruby Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$/../rails_logs_viewer" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/../rails_logs_viewer/lib" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="NewModuleRootManager">
|
13
|
+
<content url="file://$MODULE_DIR$" />
|
14
|
+
<orderEntry type="inheritedJdk" />
|
15
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-2.2.3) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, RVM: ruby-2.2.3) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.4.0, RVM: ruby-2.2.3) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.4.1, RVM: ruby-2.2.3) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.4.0, RVM: ruby-2.2.3) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.4.0, RVM: ruby-2.2.3) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.4.1, RVM: ruby-2.2.3) [gem]" level="application" />
|
23
|
+
</component>
|
24
|
+
</module>
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# LogsViewer
|
2
|
+
|
3
|
+
This gem was developed to make possible the visualization of the application logs in the browser.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'logs_viewer'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install logs_viewer
|
20
|
+
|
21
|
+
## Configuration (Rails)
|
22
|
+
|
23
|
+
Create file **config/initializers/logs_viewer.rb** with the following content:
|
24
|
+
```ruby
|
25
|
+
LogsViewer::Config.number_lines = 1000
|
26
|
+
LogsViewer::Config.log_dir = "log"
|
27
|
+
```
|
28
|
+
|
29
|
+
Add the hack on their application in the file **config/application.rb**
|
30
|
+
```ruby
|
31
|
+
module YourApplicationModule
|
32
|
+
class Application < Rails::Application
|
33
|
+
|
34
|
+
# Rack to intercept path /logs
|
35
|
+
config.middleware.use LogsViewer::Display
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
```
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
After creating the initialization file and add the rack, go to your project the path /logs: (http://your-app:port/logs)
|
44
|
+
|
45
|
+
|
46
|
+
## Development
|
47
|
+
|
48
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
|
+
|
50
|
+
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).
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/logs_viewer.
|
55
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "logs_viewer"
|
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
@@ -0,0 +1,38 @@
|
|
1
|
+
module LogsViewer
|
2
|
+
class Display
|
3
|
+
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
@lines = LogsViewer::Config.number_lines
|
7
|
+
@log_dir = LogsViewer::Config.log_dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env = {})
|
11
|
+
if env["PATH_INFO"]=~/^\/logs/
|
12
|
+
@data = {
|
13
|
+
list: LogsViewer::Handler.list(@log_dir),
|
14
|
+
lines: []
|
15
|
+
}
|
16
|
+
|
17
|
+
if(env["QUERY_STRING"]=~/file/ )
|
18
|
+
log_name = env["QUERY_STRING"].clone
|
19
|
+
log_name = log_name.gsub(/file=/, '')
|
20
|
+
|
21
|
+
@data[:lines] = `tail -n "#{@lines}" "#{log_name}"`
|
22
|
+
[200,{"Content-Type"=>"text/html"},[view_generate(@data)]]
|
23
|
+
else
|
24
|
+
[200,{"Content-Type"=>"text/html"},[view_generate(@data)]]
|
25
|
+
end
|
26
|
+
else
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def view_generate(data)
|
32
|
+
temp = LogsViewer::Handler.file_open("../views/display.html.erb")
|
33
|
+
temp = ERB.new(temp)
|
34
|
+
return temp.result(binding)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module LogsViewer
|
2
|
+
class DisplayHelper
|
3
|
+
|
4
|
+
def self.get_nested_logs(list)
|
5
|
+
html = "<ul style='list-style-type:none'>"
|
6
|
+
list.each do |(item)|
|
7
|
+
icon_file = '<i class="glyphicon glyphicon-file"></i>'
|
8
|
+
icon_dir = '<i class="glyphicon glyphicon-folder-open"></i>'
|
9
|
+
link = "<a href='/logs?file=#{item}'>#{icon_file} #{item}</a>"
|
10
|
+
html += (LogsViewer::Handler.is_file? item) ? "<li>#{link}": "<li>#{icon_dir} #{item}"
|
11
|
+
html +=" #{self.get_nested_logs(LogsViewer::Handler.list(item))}" if LogsViewer::Handler.is_directory? item
|
12
|
+
html +="</li>"
|
13
|
+
end
|
14
|
+
html += "</ul>"
|
15
|
+
html
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LogsViewer
|
2
|
+
class Handler
|
3
|
+
|
4
|
+
def self.list(dir, type: nil )
|
5
|
+
case type
|
6
|
+
when :file then Dir[File.join(dir, '**')].reject {|f| File.directory?(f)}
|
7
|
+
when :directory then Dir[File.join(dir, '**')].select {|f| File.directory?(f)}
|
8
|
+
else Dir[File.join(dir, '**')]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.file_open(path)
|
13
|
+
File.open(File.expand_path(path,__FILE__),"r").read
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.is_file?(path)
|
17
|
+
File.file? path
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.is_directory?(path)
|
21
|
+
File.directory? path
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Rails Logs Viewer</title>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
7
|
+
|
8
|
+
<!-- Latest compiled and minified CSS -->
|
9
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
|
10
|
+
|
11
|
+
<style type="text/css">
|
12
|
+
.menu-box {
|
13
|
+
height: 100vh;
|
14
|
+
overflow-x: auto;
|
15
|
+
overflow-y: auto;
|
16
|
+
margin-right: -30px;
|
17
|
+
}
|
18
|
+
.console-box {
|
19
|
+
padding: 20px;
|
20
|
+
font-family: Monospace;
|
21
|
+
background-color: #212121;
|
22
|
+
color: #ffffff;
|
23
|
+
height: 100vh;
|
24
|
+
overflow: auto;
|
25
|
+
font-size: 12px;
|
26
|
+
}
|
27
|
+
</style>
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
|
32
|
+
<div class="container-fluid">
|
33
|
+
|
34
|
+
<div class="row">
|
35
|
+
<div class="col-md-3">
|
36
|
+
<div class="menu-box">
|
37
|
+
<h3>Logs</h3>
|
38
|
+
<%= (LogsViewer::DisplayHelper.get_nested_logs(data[:list]).html_safe) %>
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
<div class="col-md-9">
|
42
|
+
<div class="console-box">
|
43
|
+
<% unless data[:lines].empty? %>
|
44
|
+
|
45
|
+
<% data[:lines].each_line do |line| %>
|
46
|
+
<%= line %><br>
|
47
|
+
<% end %>
|
48
|
+
|
49
|
+
<% end %>
|
50
|
+
</div>
|
51
|
+
</div>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<!-- Latest compiled and minified JavaScript -->
|
58
|
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
|
59
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
60
|
+
|
61
|
+
</body>
|
62
|
+
</html>
|
data/lib/logs_viewer.rb
ADDED
data/logs_viewer.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logs_viewer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "logs_viewer"
|
8
|
+
spec.version = LogsViewer::VERSION
|
9
|
+
spec.licenses = ['MIT']
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
11
|
+
spec.authors = ["Washington Silva"]
|
12
|
+
spec.email = ["w-osilva@hotmail.com"]
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
16
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
spec.required_ruby_version = '>= 2.0.0'
|
19
|
+
|
20
|
+
spec.summary = %q{ Gem to view the application logs in the browser }
|
21
|
+
spec.description = %q{ This gem was developed to make possible the visualization of the application logs in the browser.}
|
22
|
+
|
23
|
+
spec.add_dependency "bundler"
|
24
|
+
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logs_viewer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Washington Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-11 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: " This gem was developed to make possible the visualization of the application
|
56
|
+
logs in the browser."
|
57
|
+
email:
|
58
|
+
- w-osilva@hotmail.com
|
59
|
+
executables:
|
60
|
+
- console
|
61
|
+
- setup
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- ".idea/rails_logs_viewer.iml"
|
67
|
+
- ".rspec"
|
68
|
+
- ".travis.yml"
|
69
|
+
- Gemfile
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/logs_viewer.rb
|
75
|
+
- lib/logs_viewer/config.rb
|
76
|
+
- lib/logs_viewer/display.rb
|
77
|
+
- lib/logs_viewer/display_helper.rb
|
78
|
+
- lib/logs_viewer/handler.rb
|
79
|
+
- lib/logs_viewer/version.rb
|
80
|
+
- lib/logs_viewer/views/display.html.erb
|
81
|
+
- logs_viewer.gemspec
|
82
|
+
- spec/logs_viewer_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
homepage: ''
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.0
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.8
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Gem to view the application logs in the browser
|
108
|
+
test_files: []
|