logput 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/logput/middleware.rb +32 -0
- data/lib/logput/version.rb +3 -0
- data/lib/logput.rb +6 -0
- data/logput.gemspec +23 -0
- data/spec/middleware_spec.rb +73 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/test.log +10 -0
- metadata +125 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Philip Lee
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Logput
|
2
|
+
|
3
|
+
Rack middleware to sit in a rails app to put put the current environments log to a webpage. eg /logput
|
4
|
+
|
5
|
+
To be used in test and development environments to see logs without needing direct access to the box.
|
6
|
+
|
7
|
+
This NOT to be used in production like environments.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'logput'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install logput
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Inside you rails app. Add the following line to config/development.rb and/or any other environment you wish to use this in.
|
26
|
+
|
27
|
+
config.middleware.use(Logput::Middleware)
|
28
|
+
|
29
|
+
The following configuration options are available.
|
30
|
+
|
31
|
+
* :path_to_log_file => '/path/to/custom/log'. Defaults to current environments log file if in rails.
|
32
|
+
* :lines_to_read => 1000. Defaults to 500.
|
33
|
+
|
34
|
+
Example.
|
35
|
+
|
36
|
+
config.middleware.use(Logput::Middleware, :lines_to_read => 300, :path_to_log_file => './log/delayed_job')
|
37
|
+
|
38
|
+
Start you rails server as normal in the set environemnt. Navigate to /logput e.g. [http://localhost:3000/logput](http://localhost:3000/logput)
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Logput
|
2
|
+
class Middleware
|
3
|
+
def initialize(app, options = {})
|
4
|
+
@app = app
|
5
|
+
@path_to_log_file = options[:path_to_log_file]
|
6
|
+
@lines_to_read = options[:lines_to_read] || 500
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@path_to_log_file ||= default_path_to_log_file(env)
|
11
|
+
|
12
|
+
raise 'Log file does not exist' unless File.exists? @path_to_log_file
|
13
|
+
|
14
|
+
if env['PATH_INFO'] == '/logput'
|
15
|
+
out = `tail -n #{@lines_to_read} #{@path_to_log_file}`
|
16
|
+
[200, {"Content-Type" => "text/html"}, ["<pre>", out, "</pre>"]]
|
17
|
+
else
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def default_path_to_log_file(env)
|
25
|
+
if defined? Rails
|
26
|
+
env['action_dispatch.logger'].instance_variable_get(:@logger).instance_variable_get(:@log_dest).path
|
27
|
+
else
|
28
|
+
raise Exception, 'Must specify path to log file'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/logput.rb
ADDED
data/logput.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/logput/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Philip Lee"]
|
6
|
+
gem.email = ["asmega@ph-lee.com"]
|
7
|
+
gem.description = 'Rack middleware to output rails logs to a webpage'
|
8
|
+
gem.summary = 'Rack middleware to output rails logs to a webpage'
|
9
|
+
gem.homepage = "https://github.com/asmega/logput"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "logput"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Logput::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'rack'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
gem.add_development_dependency 'pry'
|
23
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Logput::Middleware do
|
4
|
+
subject{ described_class.new(app, :path_to_log_file => './spec/support/test.log') }
|
5
|
+
|
6
|
+
let(:app) do
|
7
|
+
lambda do |env|
|
8
|
+
[200, {}, "hello world"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:server){ Rack::MockRequest.new(subject) }
|
13
|
+
|
14
|
+
describe '/wrong_path' do
|
15
|
+
before :each do
|
16
|
+
@response = server.get('/wrong_path')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'outputs hello world' do
|
20
|
+
@response.body.should include('hello world')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'default path to log file' do
|
25
|
+
subject { described_class.new(app) }
|
26
|
+
|
27
|
+
context 'when rails is not defined' do
|
28
|
+
it 'raises an error' do
|
29
|
+
expect{ server.get('/logput') }.to raise_exception
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when rails is defined' do
|
34
|
+
before :each do
|
35
|
+
class Rails; end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns ./log/development.log'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '/logput' do
|
43
|
+
context 'when there is no log file' do
|
44
|
+
subject{ described_class.new(app, :path_to_log_file => './file_does_not_exist') }
|
45
|
+
let(:server){ Rack::MockRequest.new(subject) }
|
46
|
+
|
47
|
+
it 'raises an exception' do
|
48
|
+
expect{ server.get('/logput')}.to raise_exception
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when there is log file' do
|
53
|
+
before :each do
|
54
|
+
@response = server.get('/logput')
|
55
|
+
end
|
56
|
+
|
57
|
+
subject{ described_class.new(app, :path_to_log_file => './spec/support/test.log', :lines_to_read => 5) }
|
58
|
+
let(:server){ Rack::MockRequest.new(subject) }
|
59
|
+
|
60
|
+
it 'responds with 200' do
|
61
|
+
@response.status.should == 200
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns the last 5 lines of the log' do
|
65
|
+
@response.body.should_not include('2')
|
66
|
+
@response.body.should_not include('5')
|
67
|
+
|
68
|
+
@response.body.should include('6')
|
69
|
+
@response.body.should include('10')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
# config.order = 'random'
|
17
|
+
|
18
|
+
config.requires = ['logput']
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logput
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Philip Lee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: pry
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Rack middleware to output rails logs to a webpage
|
79
|
+
email:
|
80
|
+
- asmega@ph-lee.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/logput.rb
|
92
|
+
- lib/logput/middleware.rb
|
93
|
+
- lib/logput/version.rb
|
94
|
+
- logput.gemspec
|
95
|
+
- spec/middleware_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- spec/support/test.log
|
98
|
+
homepage: https://github.com/asmega/logput
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.24
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Rack middleware to output rails logs to a webpage
|
122
|
+
test_files:
|
123
|
+
- spec/middleware_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
- spec/support/test.log
|