rack-custom_logger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a87602be1aad3786f050097856f0f796342e44a4
4
+ data.tar.gz: e22bcca141efc939d083d3549c514ecd605c1862
5
+ SHA512:
6
+ metadata.gz: 3647c367c1c30f6e51d37f6830a1ab27e50368777ca29cc15c71669cc79e7ee96899b2a6bf440a9f457a8dc53e44473ed3b869cd42628a2b3b5ceeea6f5e3c51
7
+ data.tar.gz: 61ffdcd4afec8d40e1c161f45778c91f9342ed6eca91be06d9412690f4eee9b5091b219d95a59949391c643bb0dd9cc1f12e26980bc0a3a1b1a4f5a7debba217
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ spec/log
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - ruby-head
6
+ matrix:
7
+ allow_failures:
8
+ - rvm: 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-custum_logger.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'bundler'
8
+ gem 'rake'
9
+ gem 'coveralls', require: false
10
+ gem 'rspec'
11
+ gem 'timecop'
12
+ gem 'daily_logger', git: 'https://github.com/SpringMT/daily_logger.git'
13
+ end
14
+
15
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 SpringMT
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,33 @@
1
+ # Rack::CustomLogger
2
+ [![Build Status](https://travis-ci.org/SpringMT/rack-custom_logger.png)](https://travis-ci.org/SpringMT/rack-custom_logger)
3
+ [![Coverage Status](https://coveralls.io/repos/SpringMT/rack-custom_logger/badge.png)](https://coveralls.io/r/SpringMT/rack-custom_logger)
4
+
5
+ * Change rack default logger
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'rack-custom_logger'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rack-custom_logger
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ use Rack::CustomLogger, DailyLogger.new("#{log_dir}/test")
25
+ ```
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+ require "bundler/setup"
3
+
4
+ task :default => :test
5
+
6
+ task :test do
7
+ require 'rspec/core'
8
+ require 'rspec/core/rake_task'
9
+ RSpec::Core::RakeTask.new(:test) do |spec|
10
+ spec.pattern = FileList['spec/**/*_spec.rb']
11
+ end
12
+ end
13
+
14
+
@@ -0,0 +1,23 @@
1
+ require 'logger'
2
+
3
+ module Rack
4
+ class CustomLogger
5
+ def initialize(app, custom_logger, level = ::Logger::INFO, custom_logger_formatter=nil)
6
+ @app, @custom_logger, @level, @custom_logger_formatter = app, custom_logger, level, custom_logger_formatter
7
+ end
8
+
9
+ def call(env)
10
+ logger = @custom_logger
11
+
12
+ if @custom_logger_formatter
13
+ logger.formatter = @custom_logger_formatter
14
+ end
15
+
16
+ logger.level = @level
17
+
18
+ env['rack.logger'] = logger
19
+ @app.call(env)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rack-custom_logger"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["SpringMT"]
9
+ spec.email = ["today.is.sky.blue.sky@gmail.com"]
10
+ spec.description = %q{Write a gem description}
11
+ spec.summary = %q{Change rack default logger}
12
+ spec.homepage = "https://github.com/SpringMT/rack-custom_logger"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'rack'
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
24
+
@@ -0,0 +1,66 @@
1
+ require 'rack/lint'
2
+ require 'rack/mock'
3
+ require 'daily_logger'
4
+ require 'timecop'
5
+ require 'rack/custom_logger'
6
+ require 'logger'
7
+
8
+ require File.dirname(__FILE__) + '/spec_helper'
9
+
10
+ describe Rack::CustomLogger do
11
+
12
+ app = lambda { |env|
13
+ log = env['rack.logger']
14
+ log.debug("Created logger")
15
+ log.info("Program started")
16
+ log.warn("Nothing to do!")
17
+
18
+ [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
19
+ }
20
+
21
+ let(:log_dir) { "#{File.dirname(__FILE__)}/log" }
22
+ let(:today) {Time.now.strftime "%Y%m%d"}
23
+ let(:now) {Time.now.strftime "%Y/%m/%d %H:%M:%S"}
24
+
25
+ before do
26
+ Dir.mkdir(log_dir)
27
+ Timecop.freeze(Time.now)
28
+ end
29
+
30
+ after do
31
+ # サブディレクトリを階層が深い順にソートした配列を作成
32
+ dirlist = Dir::glob(log_dir + "**/").sort do |a,b|
33
+ b.split('/').size <=> a.split('/').size
34
+ end
35
+
36
+ dirlist.each do |d|
37
+ Dir::foreach(d) do |f|
38
+ File::delete(d+f) if ! (/\.+$/ =~ f)
39
+ end
40
+ Dir::rmdir(d)
41
+ end
42
+ Timecop.return
43
+ end
44
+
45
+ context 'conform to Rack::Lint' do
46
+ subject {Rack::Lint.new( Rack::CustomLogger.new(app, DailyLogger.new("#{log_dir}/test")) )}
47
+ it do
48
+ Rack::MockRequest.new(subject).get('/')
49
+ expect(File.read("#{log_dir}/test.info.log.#{today}")).to eq "[#{now}]\tProgram started\n"
50
+ expect(File.read("#{log_dir}/test.warn.log.#{today}")).to eq "[#{now}]\tNothing to do!\n"
51
+ end
52
+ end
53
+
54
+ context 'conform to Rack::Lint' do
55
+ subject {Rack::Lint.new( Rack::CustomLogger.new(app, DailyLogger.new("#{log_dir}/test"), ::Logger::DEBUG) )}
56
+ it do
57
+ Rack::MockRequest.new(subject).get('/')
58
+ expect(File.read("#{log_dir}/test.debug.log.#{today}")).to eq "[#{now}]\tCreated logger\n"
59
+ expect(File.read("#{log_dir}/test.info.log.#{today}")).to eq "[#{now}]\tProgram started\n"
60
+ expect(File.read("#{log_dir}/test.warn.log.#{today}")).to eq "[#{now}]\tNothing to do!\n"
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+
@@ -0,0 +1,11 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'bundler'
5
+ Bundler.setup(:default, :test)
6
+ Bundler.require(:default, :test)
7
+
8
+ $TESTING=true
9
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib/rack/')
10
+ require 'rack/custom_logger'
11
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-custom_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - SpringMT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Write a gem description
56
+ email:
57
+ - today.is.sky.blue.sky@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/rack/custom_logger.rb
69
+ - rack-custom_logger.gemspec
70
+ - spec/rack-custom_logger_spec.rb
71
+ - spec/spec_helper.rb
72
+ homepage: https://github.com/SpringMT/rack-custom_logger
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.0.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Change rack default logger
96
+ test_files:
97
+ - spec/rack-custom_logger_spec.rb
98
+ - spec/spec_helper.rb