logger_shift_hook 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWZkNjcxNzBmMDk5NjI2NTJlMmE5ZDJlYzZmZDg0Njg2YjdjYmY4NA==
5
+ data.tar.gz: !binary |-
6
+ NDFhYTIzMjNmZjI5YmJkMmQ0MmRjNDZkNjg3NDI1Zjg0ZDY1NDdhNg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OGE2ZjI3YmU2MDI2ODRiODk4YjdhOWFjMTdhZTYyZmRjMWIxYWY2N2I1YWFk
10
+ YzM0YWQ3NjgyMmFlNjU2YzFiZTQ3Y2EyM2IyOWY0MmZhMWYxMDgyOTg1NTRl
11
+ OWIzZTlmMzA1OWQ3MDM3NWQ2MjJkZWQ2Njk3NTA5MzVjMWE1ZTg=
12
+ data.tar.gz: !binary |-
13
+ Mzk4ZGM2Y2Y2ZTcwODY2ZmU2MTZhYjNmZjhmZDA2ZjllMDc3ZTEyNTYwNGYy
14
+ YTRlYWM2Nzc4MWMyZTNkMmY4N2I4YWRiNjQ1MWRmMzlkMzQ0M2ZlMzQ5OTg2
15
+ MGJkMDY5MjRmNzczYWVmNzA4MzBjODU4NjdlMjRjNmI4NTViYWQ=
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logger_shift_hook.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Keisuke KITA
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,42 @@
1
+ # LoggerShiftHook
2
+
3
+ This gem is logger library extension.
4
+ When shifting a log, do hook.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'logger_shift_hook'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install logger_shift_hook
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require 'logger'
24
+ require 'logger_shift_hook'
25
+
26
+ # register with initializing
27
+ log = Logger.new('hoge.log', 'daily') do
28
+ # do something
29
+ end
30
+
31
+ log.shift_hook do
32
+ # do something
33
+ end
34
+ ```
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logger_shift_hook'
@@ -0,0 +1,6 @@
1
+ require "logger_shift_hook/version"
2
+ require "logger_shift_hook/logger"
3
+ require "logger_shift_hook/log_device"
4
+
5
+ module LoggerShiftHook
6
+ end
@@ -0,0 +1,29 @@
1
+ class Logger
2
+ class LogDevice
3
+ attr_reader :shift_hooks
4
+
5
+ def shift_hook(&blk)
6
+ @shift_hooks ||= []
7
+ @shift_hooks << blk if blk
8
+ end
9
+
10
+ private
11
+ def shift_log_age_with_hook
12
+ shift_log_age_without_hook
13
+ @shift_hooks.each do |hook|
14
+ hook.call
15
+ end
16
+ end
17
+ alias_method :shift_log_age_without_hook, :shift_log_age
18
+ alias_method :shift_log_age, :shift_log_age_with_hook
19
+
20
+ def shift_log_period_with_hook(period_end)
21
+ shift_log_period_without_hook(period_end)
22
+ @shift_hooks.each do |hook|
23
+ hook.call
24
+ end
25
+ end
26
+ alias_method :shift_log_period_without_hook, :shift_log_period
27
+ alias_method :shift_log_period, :shift_log_period_with_hook
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+
2
+ class Logger
3
+ def initialize_with_hook(logdev, shift_age, shift_size, &blk)
4
+ initialize_without_hook(logdev, shift_age, shift_size)
5
+ shift_hook &blk if blk
6
+ end
7
+ alias_method :initialize_without_hook, :initialize
8
+ alias_method :initialize, :initialize_with_hook
9
+
10
+ def shift_hook(&blk)
11
+ @logdev.shift_hook &blk
12
+ end
13
+
14
+ def shift_hooks
15
+ @logdev.shift_hooks
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module LoggerShiftHook
2
+ VERSION = "0.0.1"
3
+ 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
+ require 'logger_shift_hook/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logger_shift_hook"
8
+ spec.version = LoggerShiftHook::VERSION
9
+ spec.authors = ["Keisuke KITA"]
10
+ spec.email = ["kei.kita2501@gmail.com"]
11
+ spec.description = %q{Hook when log shift}
12
+ spec.summary = %q{Hook when log shift}
13
+ spec.homepage = "https://github.com/kitak/logger_shift_hook"
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
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe LoggerShiftHook do
4
+ it 'should have a version number' do
5
+ LoggerShiftHook::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should be_true
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'logger_shift_hook'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logger_shift_hook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Keisuke KITA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-06 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: '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: Hook when log shift
56
+ email:
57
+ - kei.kita2501@gmail.com
58
+ executables:
59
+ - logger_shift_hook
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - .travis.yml
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/logger_shift_hook
71
+ - lib/logger_shift_hook.rb
72
+ - lib/logger_shift_hook/log_device.rb
73
+ - lib/logger_shift_hook/logger.rb
74
+ - lib/logger_shift_hook/version.rb
75
+ - logger_shift_hook.gemspec
76
+ - spec/logger_shift_hook_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/kitak/logger_shift_hook
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Hook when log shift
102
+ test_files:
103
+ - spec/logger_shift_hook_spec.rb
104
+ - spec/spec_helper.rb