eye-rotate 0.1
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 +15 -0
- data/.gitignore +26 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +8 -0
- data/examples/default.eye +16 -0
- data/examples/manual.eye +15 -0
- data/eye-rotate.gemspec +27 -0
- data/lib/eye-rotate.rb +3 -0
- data/lib/eye-rotate/extension.rb +10 -0
- data/lib/eye-rotate/log_rotate.rb +41 -0
- data/lib/eye-rotate/rotator.rb +94 -0
- data/lib/eye-rotate/version.rb +6 -0
- data/spec/eye_spec.rb +42 -0
- data/spec/fixtures/default.eye +17 -0
- data/spec/fixtures/filename.eye +14 -0
- data/spec/fixtures/manual.eye +14 -0
- data/spec/rotate_spec.rb +160 -0
- data/spec/spec_helper.rb +57 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzNjMTI4ZDAxYjM1NDllMTM2N2I4MmIxMWEyMTMyYWI1NjhlMGZhNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2E2YjAxZGJhZGFhMWViODA2NzRkOThlMDQ1YzM1YTYxOGY5NjlmYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YmVjYTUxODA0Njk1YmY0YzBjY2ZkOTEwMDZkMzhhNDY0ZTRkZjkxZTQ0OTVk
|
10
|
+
ODcxNjNmYWZhNjUyZjVmZTczMjUxZmJjYWYwN2FhNWZiYWYyNWVmYzZjYWFk
|
11
|
+
NTQyZGNlYTdkMDFiYzUwMzlmNmYxMzg3NmIwN2U3NDY1NTIyZGQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDI1MTQ1MWQxYWE4YTA3N2QxOWQ4MzJlY2MwZmM1OWI2MzIxOWE2MGI2YWZj
|
14
|
+
Y2FlYzA4MzFkZjZjYTc4MDJmODU1NjMwM2YyMzRhMDlmYzBlZDdiNGU1ODY0
|
15
|
+
NzEwMGQ5OTgwOTVjYjczYmQzMTNhM2VjNmE4YmZkNTI5MjI0ZWQ=
|
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
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
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
*.log
|
24
|
+
*.gz
|
25
|
+
*.log.*
|
26
|
+
*.pid
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 'Konstantin Makarchev'
|
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,62 @@
|
|
1
|
+
Eye::Rotate
|
2
|
+
---------
|
3
|
+
|
4
|
+
Log rotate for the [Eye](http://github.com/kostya/eye) gem.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install eye
|
9
|
+
gem install eye-rotate
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Options:
|
14
|
+
|
15
|
+
:min_size (Fixnum) - set minimal file size for rotate
|
16
|
+
:gzip (Boolean) - gzip file or not
|
17
|
+
:count (Fixnum) - count of rotated files
|
18
|
+
|
19
|
+
Example config: Auto rotate all processes stdall:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'eye-rotate'
|
23
|
+
|
24
|
+
Eye.config do
|
25
|
+
log_rotate :every => 3.seconds, :count => 5, :gzip => true
|
26
|
+
end
|
27
|
+
|
28
|
+
Eye.application :app do
|
29
|
+
working_dir path
|
30
|
+
process :process do
|
31
|
+
start_command "ruby -e '1000.times { puts Time.now; $stdout.flush; sleep 0.1 } '"
|
32
|
+
daemonize true
|
33
|
+
pid_file "1.pid"
|
34
|
+
stdall "/tmp/test.log"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Example config: Manually rotate:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'eye-rotate'
|
43
|
+
|
44
|
+
Eye.config do
|
45
|
+
logger "/tmp/eye.log"
|
46
|
+
end
|
47
|
+
|
48
|
+
Eye.application :app do
|
49
|
+
process :process do
|
50
|
+
start_command "ruby -e 'loop { puts Time.now; $stdout.flush; sleep 0.1 } '"
|
51
|
+
daemonize true
|
52
|
+
pid_file "/tmp/1.pid"
|
53
|
+
stdall "/tmp/1.log"
|
54
|
+
check :log_rotate, :every => 30.seconds, :count => 5, :gzip => true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
Run:
|
60
|
+
|
61
|
+
bundle exec eye l examples/manual.eye
|
62
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'eye-rotate'
|
2
|
+
|
3
|
+
Eye.config do
|
4
|
+
# set log_rotate for all processes, for all stdalls
|
5
|
+
log_rotate :every => 3.seconds, :count => 5, :gzip => true
|
6
|
+
end
|
7
|
+
|
8
|
+
Eye.application :app do
|
9
|
+
working_dir path
|
10
|
+
process :process do
|
11
|
+
start_command "ruby -e '1000.times { puts Time.now; $stdout.flush; sleep 0.1 } '"
|
12
|
+
daemonize true
|
13
|
+
pid_file "1.pid"
|
14
|
+
stdall "/tmp/test.log"
|
15
|
+
end
|
16
|
+
end
|
data/examples/manual.eye
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'eye-rotate'
|
2
|
+
|
3
|
+
Eye.config do
|
4
|
+
logger "/tmp/eye.log"
|
5
|
+
end
|
6
|
+
|
7
|
+
Eye.application :app do
|
8
|
+
process :process do
|
9
|
+
start_command "ruby -e 'loop { puts Time.now; $stdout.flush; sleep 0.1 } '"
|
10
|
+
daemonize true
|
11
|
+
pid_file "/tmp/1.pid"
|
12
|
+
stdall "/tmp/1.log"
|
13
|
+
check :log_rotate, :every => 30.seconds, :count => 5, :gzip => true
|
14
|
+
end
|
15
|
+
end
|
data/eye-rotate.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 'eye-rotate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eye-rotate"
|
8
|
+
spec.version = Eye::Rotate::VERSION
|
9
|
+
spec.authors = ["'Konstantin Makarchev'"]
|
10
|
+
spec.email = ["'kostya27@gmail.com'"]
|
11
|
+
spec.summary = %q{ Rotate logs for eye gem }
|
12
|
+
spec.description = %q{ Rotate logs for eye gem }
|
13
|
+
spec.homepage = "https://github.com/kostya/eye-rotate"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_dependency "eye", '>= 0.6'
|
22
|
+
spec.add_dependency "logrotate"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
data/lib/eye-rotate.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative "rotator"
|
2
|
+
|
3
|
+
Eye::Controller
|
4
|
+
|
5
|
+
class LogRotate < Eye::Checker::CustomDefer
|
6
|
+
param :filename, [String]
|
7
|
+
param :device, [Symbol], nil, nil, [:stdout, :stderr, :stdall]
|
8
|
+
|
9
|
+
param :min_size, [Fixnum]
|
10
|
+
param :gzip, [TrueClass, FalseClass]
|
11
|
+
param :count, [Fixnum]
|
12
|
+
|
13
|
+
def initialize(*args)
|
14
|
+
super
|
15
|
+
|
16
|
+
fname = if filename
|
17
|
+
filename
|
18
|
+
elsif device && device != :stdall
|
19
|
+
process.config[device]
|
20
|
+
else
|
21
|
+
if process.config[:stdout] != process.config[:stderr]
|
22
|
+
[process.config[:stdout], process.config[:stderr]]
|
23
|
+
else
|
24
|
+
process.config[:stdall]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@rots = Array(fname).map do |name|
|
29
|
+
Eye::Rotator.new(name, {:min_size => min_size, :gzip => gzip, :count => count})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_value
|
34
|
+
@rots.each &:rotate_if_needed
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def good?(v)
|
39
|
+
true
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'zlib'
|
3
|
+
|
4
|
+
# very simple log rotator
|
5
|
+
|
6
|
+
def gzip_cmd
|
7
|
+
if !`which /bin/gzip`.empty?
|
8
|
+
"/bin/gzip"
|
9
|
+
elsif !`which gzip`.empty?
|
10
|
+
"gzip"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def cp_cmd
|
15
|
+
if !`which /bin/cp`.empty?
|
16
|
+
"/bin/cp"
|
17
|
+
elsif !`which cp`.empty?
|
18
|
+
"cp"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
raise "Requires gzip" unless gzip_cmd
|
23
|
+
raise "Requires cp" unless cp_cmd
|
24
|
+
|
25
|
+
module Eye
|
26
|
+
end
|
27
|
+
|
28
|
+
class Eye::Rotator
|
29
|
+
# options
|
30
|
+
# :gzip => [true, false]
|
31
|
+
# :min_size => [10 * 1024 * 1024, nil]
|
32
|
+
# :count => 5
|
33
|
+
|
34
|
+
attr_reader :gzip, :min_size, :filename, :options, :count
|
35
|
+
|
36
|
+
def initialize(filename, options = {})
|
37
|
+
@filename = File.expand_path(filename)
|
38
|
+
@options = options
|
39
|
+
|
40
|
+
@gzip = @options[:gzip]
|
41
|
+
@min_size = @options[:min_size]
|
42
|
+
@count = @options[:count] || 7
|
43
|
+
@count = 1 if @count.to_i < 1
|
44
|
+
end
|
45
|
+
|
46
|
+
def rotate_if_needed
|
47
|
+
if min_size
|
48
|
+
rotate if file_size > min_size
|
49
|
+
else
|
50
|
+
rotate
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def file_size
|
57
|
+
File.size(filename) rescue -1
|
58
|
+
end
|
59
|
+
|
60
|
+
def name(num)
|
61
|
+
s = "#{filename}.#{num}"
|
62
|
+
s += ".gz" if gzip
|
63
|
+
s
|
64
|
+
end
|
65
|
+
|
66
|
+
def rotate
|
67
|
+
return unless File.exists?(filename)
|
68
|
+
|
69
|
+
@tmp_name = "#{filename}.tmp#{Time.now.to_f}"
|
70
|
+
|
71
|
+
if gzip
|
72
|
+
`#{gzip_cmd} -c '#{filename}' > '#{@tmp_name}'`
|
73
|
+
else
|
74
|
+
`#{cp_cmd} '#{filename}' '#{@tmp_name}'`
|
75
|
+
end
|
76
|
+
|
77
|
+
# truncate filename
|
78
|
+
File.truncate(filename, 0)
|
79
|
+
|
80
|
+
# delete last
|
81
|
+
FileUtils.rm(name(count)) rescue nil
|
82
|
+
|
83
|
+
# move files
|
84
|
+
count.downto(1) { |i| move(i - 1, i) }
|
85
|
+
|
86
|
+
FileUtils.mv(@tmp_name, name(1))
|
87
|
+
end
|
88
|
+
|
89
|
+
def move(from_num, to_num)
|
90
|
+
FileUtils.mv(name(from_num), name(to_num))
|
91
|
+
rescue
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
data/spec/eye_spec.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe "Integration" do
|
4
|
+
subject{ Eye::Controller.new }
|
5
|
+
|
6
|
+
it "should rotate for process" do
|
7
|
+
subject.load(fixture("manual.eye"))
|
8
|
+
|
9
|
+
sleep 10 # 3 rotation steps here
|
10
|
+
|
11
|
+
filegz.size.should > 1
|
12
|
+
filegz(1).size.should > 1
|
13
|
+
filegz(2).size.should > 1
|
14
|
+
filegz(3).should == -1
|
15
|
+
filegz(4).should == -1
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should rotate for all processes" do
|
19
|
+
subject.load(fixture("default.eye"))
|
20
|
+
|
21
|
+
sleep 10 # 3 rotation steps here
|
22
|
+
|
23
|
+
filegz.size.should > 1
|
24
|
+
filegz(1).size.should > 1
|
25
|
+
filegz(2).size.should > 1
|
26
|
+
filegz(3).should == -1
|
27
|
+
filegz(4).should == -1
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should rotate for filename" do
|
31
|
+
subject.load(fixture("filename.eye"))
|
32
|
+
|
33
|
+
sleep 10 # 3 rotation steps here
|
34
|
+
|
35
|
+
filegz.size.should > 1
|
36
|
+
filegz(1).size.should > 1
|
37
|
+
filegz(2).size.should > 1
|
38
|
+
filegz(3).should == -1
|
39
|
+
filegz(4).should == -1
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'eye-rotate'
|
2
|
+
|
3
|
+
path = File.expand_path(File.dirname(__FILE__) + "/../")
|
4
|
+
|
5
|
+
Eye.config do
|
6
|
+
log_rotate :every => 3.seconds, :count => 5, :gzip => true
|
7
|
+
end
|
8
|
+
|
9
|
+
Eye.application :app do
|
10
|
+
working_dir path
|
11
|
+
process :process do
|
12
|
+
start_command "ruby -e '1000.times { puts Time.now; $stdout.flush; sleep 0.1 } '"
|
13
|
+
daemonize true
|
14
|
+
pid_file "1.pid"
|
15
|
+
stdall "test.log"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'eye-rotate'
|
2
|
+
|
3
|
+
path = File.expand_path(File.dirname(__FILE__) + "/../")
|
4
|
+
|
5
|
+
Eye.application :app do
|
6
|
+
working_dir path
|
7
|
+
process :process do
|
8
|
+
start_command "ruby -e '1000.times { puts Time.now; $stdout.flush; sleep 0.1 } '"
|
9
|
+
daemonize true
|
10
|
+
pid_file "1.pid"
|
11
|
+
stdall "test.log"
|
12
|
+
check :log_rotate, :filename => "test.log", :every => 3.seconds, :count => 5, :gzip => true
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'eye-rotate'
|
2
|
+
|
3
|
+
path = File.expand_path(File.dirname(__FILE__) + "/../")
|
4
|
+
|
5
|
+
Eye.application :app do
|
6
|
+
working_dir path
|
7
|
+
process :process do
|
8
|
+
start_command "ruby -e '1000.times { puts Time.now; $stdout.flush; sleep 0.1 } '"
|
9
|
+
daemonize true
|
10
|
+
pid_file "1.pid"
|
11
|
+
stdall "test.log"
|
12
|
+
check :log_rotate, :every => 3.seconds, :count => 5, :gzip => true
|
13
|
+
end
|
14
|
+
end
|
data/spec/rotate_spec.rb
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
|
3
|
+
describe "Rotator" do
|
4
|
+
it "rotate file every call" do
|
5
|
+
r = Eye::Rotator.new(TEST_FILE, :count => 3)
|
6
|
+
create_test_file
|
7
|
+
|
8
|
+
file.should == test_content
|
9
|
+
file(1).should == -1
|
10
|
+
file(2).should == -1
|
11
|
+
file(3).should == -1
|
12
|
+
file(4).should == -1
|
13
|
+
|
14
|
+
r.rotate_if_needed
|
15
|
+
file.should == ""
|
16
|
+
file(1).should == test_content
|
17
|
+
file(2).should == -1
|
18
|
+
file(3).should == -1
|
19
|
+
file(4).should == -1
|
20
|
+
|
21
|
+
r.rotate_if_needed
|
22
|
+
file.should == ""
|
23
|
+
file(1).should == ""
|
24
|
+
file(2).should == test_content
|
25
|
+
file(3).should == -1
|
26
|
+
file(4).should == -1
|
27
|
+
|
28
|
+
File.open(TEST_FILE, 'w') { |f| f.write "a" }
|
29
|
+
|
30
|
+
r.rotate_if_needed
|
31
|
+
file.should == ""
|
32
|
+
file(1).should == "a"
|
33
|
+
file(2).should == ""
|
34
|
+
file(3).should == test_content
|
35
|
+
file(4).should == -1
|
36
|
+
|
37
|
+
r.rotate_if_needed
|
38
|
+
file.should == ""
|
39
|
+
file(1).should == ""
|
40
|
+
file(2).should == "a"
|
41
|
+
file(3).should == ""
|
42
|
+
file(4).should == -1
|
43
|
+
|
44
|
+
r.rotate_if_needed
|
45
|
+
file.should == ""
|
46
|
+
file(1).should == ""
|
47
|
+
file(2).should == ""
|
48
|
+
file(3).should == "a"
|
49
|
+
file(4).should == -1
|
50
|
+
|
51
|
+
r.rotate_if_needed
|
52
|
+
file.should == ""
|
53
|
+
file(1).should == ""
|
54
|
+
file(2).should == ""
|
55
|
+
file(3).should == ""
|
56
|
+
file(4).should == -1
|
57
|
+
end
|
58
|
+
|
59
|
+
it "rotate file every call with Gzip" do
|
60
|
+
r = Eye::Rotator.new(TEST_FILE, :count => 3, :gzip => true)
|
61
|
+
create_test_file
|
62
|
+
|
63
|
+
filegz.should == test_content
|
64
|
+
filegz(1).should == -1
|
65
|
+
filegz(2).should == -1
|
66
|
+
filegz(3).should == -1
|
67
|
+
filegz(4).should == -1
|
68
|
+
|
69
|
+
r.rotate_if_needed
|
70
|
+
filegz.should == ""
|
71
|
+
filegz(1).should == test_content
|
72
|
+
filegz(2).should == -1
|
73
|
+
filegz(3).should == -1
|
74
|
+
filegz(4).should == -1
|
75
|
+
|
76
|
+
r.rotate_if_needed
|
77
|
+
filegz.should == ""
|
78
|
+
filegz(1).should == ""
|
79
|
+
filegz(2).should == test_content
|
80
|
+
filegz(3).should == -1
|
81
|
+
filegz(4).should == -1
|
82
|
+
|
83
|
+
File.open(TEST_FILE, 'w') { |f| f.write "a" }
|
84
|
+
|
85
|
+
r.rotate_if_needed
|
86
|
+
filegz.should == ""
|
87
|
+
filegz(1).should == "a"
|
88
|
+
filegz(2).should == ""
|
89
|
+
filegz(3).should == test_content
|
90
|
+
filegz(4).should == -1
|
91
|
+
|
92
|
+
r.rotate_if_needed
|
93
|
+
filegz.should == ""
|
94
|
+
filegz(1).should == ""
|
95
|
+
filegz(2).should == "a"
|
96
|
+
filegz(3).should == ""
|
97
|
+
filegz(4).should == -1
|
98
|
+
|
99
|
+
r.rotate_if_needed
|
100
|
+
filegz.should == ""
|
101
|
+
filegz(1).should == ""
|
102
|
+
filegz(2).should == ""
|
103
|
+
filegz(3).should == "a"
|
104
|
+
filegz(4).should == -1
|
105
|
+
|
106
|
+
r.rotate_if_needed
|
107
|
+
filegz.should == ""
|
108
|
+
filegz(1).should == ""
|
109
|
+
filegz(2).should == ""
|
110
|
+
filegz(3).should == ""
|
111
|
+
filegz(4).should == -1
|
112
|
+
end
|
113
|
+
|
114
|
+
it "correctly truncate, not loose descriptor" do
|
115
|
+
Thread.new do
|
116
|
+
File.open(TEST_FILE, 'w'){ |f| loop{ f.puts("someting"); f.flush; sleep 0.3 } }
|
117
|
+
end
|
118
|
+
|
119
|
+
r = Eye::Rotator.new(TEST_FILE, :count => 3)
|
120
|
+
sleep 0.35
|
121
|
+
|
122
|
+
r.rotate_if_needed
|
123
|
+
file.should == ""
|
124
|
+
file(1).should == "someting\nsometing\n"
|
125
|
+
file(2).should == -1
|
126
|
+
file(3).should == -1
|
127
|
+
|
128
|
+
sleep 0.3
|
129
|
+
|
130
|
+
r.rotate_if_needed
|
131
|
+
file.should == ""
|
132
|
+
file(1).should == "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000someting\n"
|
133
|
+
file(2).should == "someting\nsometing\n"
|
134
|
+
file(3).should == -1
|
135
|
+
end
|
136
|
+
|
137
|
+
it "rotate only if file > than min_size" do
|
138
|
+
r = Eye::Rotator.new(TEST_FILE, :count => 3, :min_size => 2000)
|
139
|
+
create_test_file
|
140
|
+
|
141
|
+
r.rotate_if_needed
|
142
|
+
r.rotate_if_needed
|
143
|
+
r.rotate_if_needed
|
144
|
+
|
145
|
+
file.should == test_content
|
146
|
+
file(1).should == -1
|
147
|
+
file(2).should == -1
|
148
|
+
file(3).should == -1
|
149
|
+
file(4).should == -1
|
150
|
+
|
151
|
+
File.open(TEST_FILE, 'w') { |f| f.write("a" * 2500) }
|
152
|
+
|
153
|
+
r.rotate_if_needed
|
154
|
+
file.should == ""
|
155
|
+
file(1).should == "a" * 2500
|
156
|
+
file(2).should == -1
|
157
|
+
file(3).should == -1
|
158
|
+
file(4).should == -1
|
159
|
+
end
|
160
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
Bundler.require
|
3
|
+
require 'eye-rotate/rotator'
|
4
|
+
|
5
|
+
TEST_FILE = File.expand_path(File.dirname(__FILE__) + "/test.log")
|
6
|
+
|
7
|
+
def test_content(size = 1000)
|
8
|
+
"a" * size
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_test_file(size = 1000)
|
12
|
+
File.open(TEST_FILE, 'w') { |f|
|
13
|
+
f.write(test_content(size))
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear_test_files
|
18
|
+
Dir[TEST_FILE + "*"].each do |f|
|
19
|
+
FileUtils.rm(f)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def file(num = nil)
|
24
|
+
unless num
|
25
|
+
File.read(TEST_FILE)
|
26
|
+
else
|
27
|
+
File.read(TEST_FILE + ".#{num}")
|
28
|
+
end
|
29
|
+
rescue
|
30
|
+
-1
|
31
|
+
end
|
32
|
+
|
33
|
+
def filegz(num = nil)
|
34
|
+
unless num
|
35
|
+
File.read(TEST_FILE)
|
36
|
+
else
|
37
|
+
content = ""
|
38
|
+
Zlib::GzipReader.open(TEST_FILE + ".#{num}.gz") do |gz|
|
39
|
+
content = gz.read
|
40
|
+
end
|
41
|
+
content
|
42
|
+
end
|
43
|
+
rescue
|
44
|
+
-1
|
45
|
+
end
|
46
|
+
|
47
|
+
def fixture(name)
|
48
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', name))
|
49
|
+
end
|
50
|
+
|
51
|
+
Eye::Logger.link_logger(File.join(File.dirname(__FILE__), ["spec.log"]))
|
52
|
+
Celluloid.logger = Eye::Logger.inner_logger
|
53
|
+
|
54
|
+
RSpec.configure do |config|
|
55
|
+
config.before { Celluloid.boot; clear_test_files }
|
56
|
+
config.after { Celluloid.shutdown; clear_test_files }
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eye-rotate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ! '''Konstantin Makarchev'''
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eye
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: logrotate
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ! ' Rotate logs for eye gem '
|
84
|
+
email:
|
85
|
+
- ! '''kostya27@gmail.com'''
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- examples/default.eye
|
96
|
+
- examples/manual.eye
|
97
|
+
- eye-rotate.gemspec
|
98
|
+
- lib/eye-rotate.rb
|
99
|
+
- lib/eye-rotate/extension.rb
|
100
|
+
- lib/eye-rotate/log_rotate.rb
|
101
|
+
- lib/eye-rotate/rotator.rb
|
102
|
+
- lib/eye-rotate/version.rb
|
103
|
+
- spec/eye_spec.rb
|
104
|
+
- spec/fixtures/default.eye
|
105
|
+
- spec/fixtures/filename.eye
|
106
|
+
- spec/fixtures/manual.eye
|
107
|
+
- spec/rotate_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
homepage: https://github.com/kostya/eye-rotate
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.2.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Rotate logs for eye gem
|
133
|
+
test_files:
|
134
|
+
- spec/eye_spec.rb
|
135
|
+
- spec/fixtures/default.eye
|
136
|
+
- spec/fixtures/filename.eye
|
137
|
+
- spec/fixtures/manual.eye
|
138
|
+
- spec/rotate_spec.rb
|
139
|
+
- spec/spec_helper.rb
|