rack-ltsvlogger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-ltsvlogger.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 tnakamura
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.
@@ -0,0 +1,46 @@
1
+ # Rack::LTSVLogger
2
+
3
+ LTSV logger for Rack applications implemented as middleware
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rack-ltsvlogger', require: "rack/ltsvlogger"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```
22
+ $ gem install rack-ltsvlogger
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "rack/ltsvlogger"
29
+
30
+ class SampleApp
31
+ def call(env)
32
+ [200, {"Content-Type" => "text/html"}, ["Hello"]]
33
+ end
34
+ end
35
+
36
+ use Rack::LTSVLogger
37
+ run SampleApp.new
38
+ ```
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 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ require "rack"
3
+ require "rack/ltsvlogger/version"
4
+
5
+ module Rack
6
+ class LTSVLogger < ::Rack::CommonLogger
7
+ FORMAT = %w[
8
+ time
9
+ host
10
+ forwardedfor
11
+ user
12
+ method
13
+ path
14
+ query
15
+ protocol
16
+ status
17
+ size
18
+ runtime
19
+ ].map{ |f| "#{f}:%{#{f}}" }.join("\t") + "\n"
20
+
21
+ def log(env, status, header, began_at)
22
+ now = Time.now
23
+ length = extract_content_length(header)
24
+
25
+ logger = @logger || env['rack.errors']
26
+ logger.write FORMAT % {
27
+ time: now.strftime("%d/%b/%Y %H:%M:%S"),
28
+ host: env["REMOTE_ADDR"] || "-",
29
+ forwardedfor: env['HTTP_X_FORWARDED_FOR'] || "-",
30
+ user: env["REMOTE_USER"] || "-",
31
+ method: env["REQUEST_METHOD"],
32
+ path: env["PATH_INFO"],
33
+ query: env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
34
+ protocol: env["HTTP_VERSION"],
35
+ status: status.to_s[0..3],
36
+ size: length,
37
+ runtime: now - began_at,
38
+ }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+ require "rack"
3
+
4
+ module Rack
5
+ class LTSVLogger < ::Rack::CommonLogger
6
+ VERSION = "0.0.1"
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/ltsvlogger/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-ltsvlogger"
8
+ spec.version = Rack::LTSVLogger::VERSION
9
+ spec.authors = ["tnakamura"]
10
+ spec.email = ["griefworker@gmail.com"]
11
+ spec.description = %q{LTSV logger for Rack applications implemented as middleware}
12
+ spec.summary = %q{LTSV logger for Rack applications implemented as middleware}
13
+ spec.homepage = "https://github.com/tnakamura/rack-ltsvlogger"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rack-test"
25
+ spec.add_runtime_dependency "rack"
26
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ require_relative "spec_helper"
3
+ require "stringio"
4
+
5
+ describe Rack::LTSVLogger do
6
+ def app
7
+ Rack::LTSVLogger.new(FakeApp.new, @output)
8
+ end
9
+
10
+ def ltsv_data
11
+ @output.seek(0)
12
+ Hash[@output.read.chomp.split("\t").map{|v| v.split(":", 2)}]
13
+ end
14
+
15
+ before do
16
+ @output = StringIO.new
17
+ end
18
+
19
+ describe "#log" do
20
+ it "LTSV フォーマットでログを出力できる" do
21
+ get "/"
22
+ expect(ltsv_data["host"]).to eq("127.0.0.1")
23
+ expect(ltsv_data["forwardedfor"]).to eq("-")
24
+ expect(ltsv_data["user"]).to eq("-")
25
+ expect(ltsv_data["method"]).to eq("GET")
26
+ expect(ltsv_data["path"]).to eq("/")
27
+ expect(ltsv_data["query"]).to eq("")
28
+ expect(ltsv_data["status"]).to eq("200")
29
+ end
30
+ end
31
+ end
32
+
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+
5
+ require "rack"
6
+ require "rack/test"
7
+ require "rack/ltsvlogger"
8
+ require "rspec"
9
+ require "rspec/autorun"
10
+
11
+ class FakeApp
12
+ def call(env)
13
+ [200, {"Content-Type" => "text/html"}, ["Hello"]]
14
+ end
15
+ end
16
+
17
+ RSpec.configure do |config|
18
+ config.include Rack::Test::Methods
19
+ end
20
+
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-ltsvlogger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tnakamura
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &28911300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *28911300
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &28911060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *28911060
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &28910784 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *28910784
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack-test
49
+ requirement: &28910532 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *28910532
58
+ - !ruby/object:Gem::Dependency
59
+ name: rack
60
+ requirement: &28910280 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *28910280
69
+ description: LTSV logger for Rack applications implemented as middleware
70
+ email:
71
+ - griefworker@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/rack/ltsvlogger.rb
82
+ - lib/rack/ltsvlogger/version.rb
83
+ - rack-ltsvlogger.gemspec
84
+ - spec/ltsvlogger_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: https://github.com/tnakamura/rack-ltsvlogger
87
+ licenses:
88
+ - MIT
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: -30818019
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
109
+ - 0
110
+ hash: -30818019
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.16
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: LTSV logger for Rack applications implemented as middleware
117
+ test_files:
118
+ - spec/ltsvlogger_spec.rb
119
+ - spec/spec_helper.rb