yell 1.4.0 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +6 -2
- data/.ruby-version +1 -0
- data/.travis.yml +16 -13
- data/Gemfile +15 -8
- data/LICENSE.txt +1 -1
- data/README.md +10 -3
- data/Rakefile +1 -3
- data/examples/002.1-log-level-basics.rb +2 -2
- data/examples/002.2-log-level-on-certain-severities-only.rb +5 -4
- data/examples/002.3-log-level-within-range.rb +7 -5
- data/examples/003.1-formatting-DefaultFormat.rb +3 -3
- data/examples/003.2-formatting-BasicFormat.rb +3 -3
- data/examples/003.3-formatting-ExtendedFormat.rb +3 -3
- data/examples/003.4-formatting-on-your-own.rb +3 -3
- data/examples/004.1-colorizing-the-log-output.rb +3 -3
- data/examples/005.1-repository.rb +3 -3
- data/examples/006.1-the-loggable-module.rb +2 -2
- data/examples/006.2-the-loggable-module-with-inheritance.rb +2 -2
- data/lib/core_ext/logger.rb +17 -0
- data/lib/yell/adapters/base.rb +17 -22
- data/lib/yell/adapters/datefile.rb +23 -22
- data/lib/yell/adapters/file.rb +3 -7
- data/lib/yell/adapters/io.rb +9 -15
- data/lib/yell/adapters/streams.rb +0 -5
- data/lib/yell/adapters.rb +41 -10
- data/lib/yell/configuration.rb +2 -4
- data/lib/yell/event.rb +46 -10
- data/lib/yell/formatter.rb +134 -54
- data/lib/yell/helpers/{adapters.rb → adapter.rb} +7 -17
- data/lib/yell/helpers/base.rb +0 -1
- data/lib/yell/helpers/formatter.rb +8 -8
- data/lib/yell/helpers/level.rb +7 -4
- data/lib/yell/helpers/silencer.rb +3 -5
- data/lib/yell/helpers/tracer.rb +6 -7
- data/lib/yell/level.rb +19 -16
- data/lib/yell/loggable.rb +11 -7
- data/lib/yell/logger.rb +47 -68
- data/lib/yell/repository.rb +3 -5
- data/lib/yell/silencer.rb +30 -14
- data/lib/yell/version.rb +1 -4
- data/lib/yell.rb +29 -11
- data/yell.gemspec +22 -15
- metadata +19 -50
- data/spec/fixtures/yell.yml +0 -7
- data/spec/spec_helper.rb +0 -50
- data/spec/threaded/yell_spec.rb +0 -100
- data/spec/yell/adapters/base_spec.rb +0 -43
- data/spec/yell/adapters/datefile_spec.rb +0 -168
- data/spec/yell/adapters/file_spec.rb +0 -75
- data/spec/yell/adapters/io_spec.rb +0 -72
- data/spec/yell/adapters/streams_spec.rb +0 -26
- data/spec/yell/adapters_spec.rb +0 -45
- data/spec/yell/configuration_spec.rb +0 -36
- data/spec/yell/event_spec.rb +0 -97
- data/spec/yell/formatter_spec.rb +0 -136
- data/spec/yell/level_spec.rb +0 -200
- data/spec/yell/loggable_spec.rb +0 -20
- data/spec/yell/logger_spec.rb +0 -263
- data/spec/yell/repository_spec.rb +0 -70
- data/spec/yell/silencer_spec.rb +0 -49
- data/spec/yell_spec.rb +0 -102
data/yell.gemspec
CHANGED
@@ -1,21 +1,28 @@
|
|
1
|
-
#
|
2
|
-
require File.expand_path( '../lib/yell/version', __FILE__ )
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
s.authors = ["Rudolf Schmidt"]
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'yell/version'
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'yell'
|
9
|
+
spec.version = Yell::VERSION
|
10
|
+
spec.authors = ['Rudolf Schmidt']
|
11
|
+
spec.license = 'MIT'
|
12
12
|
|
13
|
-
|
13
|
+
spec.summary = 'Yell - Your Extensible Logging Library'
|
14
|
+
spec.description = "Yell - Your Extensible Logging Library. Define multiple adapters, various log level combinations or message formatting options like you've never done before"
|
15
|
+
spec.homepage = 'https://github.com/rudionrails/yell'
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/rudionrails/yell'
|
18
19
|
|
19
|
-
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
20
28
|
end
|
21
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rudolf Schmidt
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Yell - Your Extensible Logging Library. Define multiple adapters, various
|
14
14
|
log level combinations or message formatting options like you've never done before
|
@@ -17,8 +17,9 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- .gitignore
|
21
|
-
- .
|
20
|
+
- ".gitignore"
|
21
|
+
- ".ruby-version"
|
22
|
+
- ".travis.yml"
|
22
23
|
- Gemfile
|
23
24
|
- LICENSE.txt
|
24
25
|
- README.md
|
@@ -35,6 +36,7 @@ files:
|
|
35
36
|
- examples/005.1-repository.rb
|
36
37
|
- examples/006.1-the-loggable-module.rb
|
37
38
|
- examples/006.2-the-loggable-module-with-inheritance.rb
|
39
|
+
- lib/core_ext/logger.rb
|
38
40
|
- lib/yell.rb
|
39
41
|
- lib/yell/adapters.rb
|
40
42
|
- lib/yell/adapters/base.rb
|
@@ -45,7 +47,7 @@ files:
|
|
45
47
|
- lib/yell/configuration.rb
|
46
48
|
- lib/yell/event.rb
|
47
49
|
- lib/yell/formatter.rb
|
48
|
-
- lib/yell/helpers/
|
50
|
+
- lib/yell/helpers/adapter.rb
|
49
51
|
- lib/yell/helpers/base.rb
|
50
52
|
- lib/yell/helpers/formatter.rb
|
51
53
|
- lib/yell/helpers/level.rb
|
@@ -57,64 +59,31 @@ files:
|
|
57
59
|
- lib/yell/repository.rb
|
58
60
|
- lib/yell/silencer.rb
|
59
61
|
- lib/yell/version.rb
|
60
|
-
- spec/fixtures/yell.yml
|
61
|
-
- spec/spec_helper.rb
|
62
|
-
- spec/threaded/yell_spec.rb
|
63
|
-
- spec/yell/adapters/base_spec.rb
|
64
|
-
- spec/yell/adapters/datefile_spec.rb
|
65
|
-
- spec/yell/adapters/file_spec.rb
|
66
|
-
- spec/yell/adapters/io_spec.rb
|
67
|
-
- spec/yell/adapters/streams_spec.rb
|
68
|
-
- spec/yell/adapters_spec.rb
|
69
|
-
- spec/yell/configuration_spec.rb
|
70
|
-
- spec/yell/event_spec.rb
|
71
|
-
- spec/yell/formatter_spec.rb
|
72
|
-
- spec/yell/level_spec.rb
|
73
|
-
- spec/yell/loggable_spec.rb
|
74
|
-
- spec/yell/logger_spec.rb
|
75
|
-
- spec/yell/repository_spec.rb
|
76
|
-
- spec/yell/silencer_spec.rb
|
77
|
-
- spec/yell_spec.rb
|
78
62
|
- yell.gemspec
|
79
|
-
homepage:
|
80
|
-
licenses:
|
81
|
-
|
63
|
+
homepage: https://github.com/rudionrails/yell
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata:
|
67
|
+
homepage_uri: https://github.com/rudionrails/yell
|
68
|
+
source_code_uri: https://github.com/rudionrails/yell
|
82
69
|
post_install_message:
|
83
70
|
rdoc_options: []
|
84
71
|
require_paths:
|
85
72
|
- lib
|
86
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
87
74
|
requirements:
|
88
|
-
- -
|
75
|
+
- - ">="
|
89
76
|
- !ruby/object:Gem::Version
|
90
77
|
version: '0'
|
91
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
79
|
requirements:
|
93
|
-
- -
|
80
|
+
- - ">="
|
94
81
|
- !ruby/object:Gem::Version
|
95
82
|
version: '0'
|
96
83
|
requirements: []
|
97
|
-
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.6.11
|
99
86
|
signing_key:
|
100
87
|
specification_version: 4
|
101
88
|
summary: Yell - Your Extensible Logging Library
|
102
|
-
test_files:
|
103
|
-
- spec/fixtures/yell.yml
|
104
|
-
- spec/spec_helper.rb
|
105
|
-
- spec/threaded/yell_spec.rb
|
106
|
-
- spec/yell/adapters/base_spec.rb
|
107
|
-
- spec/yell/adapters/datefile_spec.rb
|
108
|
-
- spec/yell/adapters/file_spec.rb
|
109
|
-
- spec/yell/adapters/io_spec.rb
|
110
|
-
- spec/yell/adapters/streams_spec.rb
|
111
|
-
- spec/yell/adapters_spec.rb
|
112
|
-
- spec/yell/configuration_spec.rb
|
113
|
-
- spec/yell/event_spec.rb
|
114
|
-
- spec/yell/formatter_spec.rb
|
115
|
-
- spec/yell/level_spec.rb
|
116
|
-
- spec/yell/loggable_spec.rb
|
117
|
-
- spec/yell/logger_spec.rb
|
118
|
-
- spec/yell/repository_spec.rb
|
119
|
-
- spec/yell/silencer_spec.rb
|
120
|
-
- spec/yell_spec.rb
|
89
|
+
test_files: []
|
data/spec/fixtures/yell.yml
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
$:.unshift File.expand_path('..', __FILE__)
|
2
|
-
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
-
|
4
|
-
ENV['YELL_ENV'] = 'test'
|
5
|
-
|
6
|
-
require 'rspec/core'
|
7
|
-
require 'rspec/expectations'
|
8
|
-
require 'rr'
|
9
|
-
require 'timecop'
|
10
|
-
|
11
|
-
begin
|
12
|
-
require 'coveralls'
|
13
|
-
|
14
|
-
require 'simplecov'
|
15
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
16
|
-
SimpleCov::Formatter::HTMLFormatter,
|
17
|
-
Coveralls::SimpleCov::Formatter
|
18
|
-
]
|
19
|
-
|
20
|
-
SimpleCov.start do
|
21
|
-
add_filter 'spec'
|
22
|
-
end
|
23
|
-
rescue LoadError
|
24
|
-
STDERR.puts "Not running coverage..."
|
25
|
-
end
|
26
|
-
|
27
|
-
require 'yell'
|
28
|
-
|
29
|
-
RSpec.configure do |config|
|
30
|
-
config.mock_framework = :rr
|
31
|
-
|
32
|
-
config.before do
|
33
|
-
Yell::Repository.loggers.clear
|
34
|
-
|
35
|
-
Dir[ fixture_path + "/*.log" ].each { |f| File.delete f }
|
36
|
-
end
|
37
|
-
|
38
|
-
config.after do
|
39
|
-
Timecop.return # release time after each test
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def fixture_path
|
46
|
-
File.expand_path( "fixtures", File.dirname(__FILE__) )
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
data/spec/threaded/yell_spec.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "running Yell multi-threaded" do
|
4
|
-
let( :threads ) { 100 }
|
5
|
-
let( :range ) { (1..threads) }
|
6
|
-
|
7
|
-
let( :filename ) { fixture_path + '/threaded.log' }
|
8
|
-
let( :lines ) { `wc -l #{filename}`.to_i }
|
9
|
-
|
10
|
-
context "one instance" do
|
11
|
-
before do
|
12
|
-
logger = Yell.new filename
|
13
|
-
|
14
|
-
range.map do |count|
|
15
|
-
Thread.new { 10.times { logger.info count } }
|
16
|
-
end.each(&:join)
|
17
|
-
|
18
|
-
sleep 0.5
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should write all messages" do
|
22
|
-
lines.should == 10*threads
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# context "one instance per thread" do
|
27
|
-
# before do
|
28
|
-
# range.map do |count|
|
29
|
-
# Thread.new do
|
30
|
-
# logger = Yell.new( filename )
|
31
|
-
|
32
|
-
# 10.times { logger.info count }
|
33
|
-
# end
|
34
|
-
# end.each(&:join)
|
35
|
-
|
36
|
-
# sleep 0.5
|
37
|
-
# end
|
38
|
-
|
39
|
-
# it "should write all messages" do
|
40
|
-
# lines.should == 10*threads
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
|
44
|
-
context "one instance in the repository" do
|
45
|
-
before do
|
46
|
-
Yell[ 'threaded' ] = Yell.new( filename )
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should write all messages" do
|
50
|
-
range.map do |count|
|
51
|
-
Thread.new { 10.times { Yell['threaded'].info count } }
|
52
|
-
end.each(&:join)
|
53
|
-
|
54
|
-
lines.should == 10*threads
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "multiple datefile instances" do
|
59
|
-
let( :threadlist ) { [] }
|
60
|
-
let( :date ) { Time.now }
|
61
|
-
|
62
|
-
before do
|
63
|
-
Timecop.freeze( date - 86400 )
|
64
|
-
|
65
|
-
range.each do |count|
|
66
|
-
threadlist << Thread.new do
|
67
|
-
logger = Yell.new :datefile, :filename => filename, :keep => 2
|
68
|
-
loop { logger.info :info; sleep 0.1 }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
sleep 0.3 # sleep to get some messages into the file
|
73
|
-
end
|
74
|
-
|
75
|
-
after do
|
76
|
-
threadlist.each(&:kill)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should safely rollover" do
|
80
|
-
# now cycle the days
|
81
|
-
7.times do |count|
|
82
|
-
Timecop.freeze( date + 86400*count )
|
83
|
-
sleep 0.3
|
84
|
-
|
85
|
-
files = Dir[ fixture_path + '/*.*.log' ]
|
86
|
-
files.size.should == 2
|
87
|
-
|
88
|
-
# files.last.should match( datefile_pattern_for(Time.now) ) # today
|
89
|
-
# files.first.should match( datefile_pattern_for(Time.now-86400) ) # yesterday
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
private
|
95
|
-
|
96
|
-
def datefile_pattern_for( time )
|
97
|
-
time.strftime(Yell::Adapters::Datefile::DefaultDatePattern)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yell::Adapters::Base do
|
4
|
-
|
5
|
-
context "initialize" do
|
6
|
-
context ":level" do
|
7
|
-
let(:level) { Yell::Level.new(:warn) }
|
8
|
-
|
9
|
-
it "should set the level" do
|
10
|
-
adapter = Yell::Adapters::Base.new(:level => level)
|
11
|
-
|
12
|
-
expect(adapter.level).to eq(level)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should set the level when block was given" do
|
16
|
-
adapter = Yell::Adapters::Base.new { |a| a.level = level }
|
17
|
-
|
18
|
-
expect(adapter.level).to eq(level)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "#write" do
|
24
|
-
let(:logger) { Yell::Logger.new }
|
25
|
-
subject { Yell::Adapters::Base.new(:level => 1) }
|
26
|
-
|
27
|
-
it "should delegate :event to :write!" do
|
28
|
-
event = Yell::Event.new(logger, 1, "Hello World!")
|
29
|
-
mock(subject).write!(event)
|
30
|
-
|
31
|
-
subject.write(event)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should not write when event does not have the right level" do
|
35
|
-
event = Yell::Event.new(logger, 0, "Hello World!")
|
36
|
-
dont_allow(subject).write!(event)
|
37
|
-
|
38
|
-
subject.write(event)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
@@ -1,168 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yell::Adapters::Datefile do
|
4
|
-
let(:logger) { Yell::Logger.new }
|
5
|
-
let(:message) { "Hello World" }
|
6
|
-
let(:event) { Yell::Event.new(logger, 1, message) }
|
7
|
-
|
8
|
-
let(:today) { Time.now }
|
9
|
-
let(:tomorrow) { Time.now + 86400 }
|
10
|
-
|
11
|
-
let(:filename) { fixture_path + '/test.log' }
|
12
|
-
let(:today_filename) { fixture_path + "/test.#{today.strftime(Yell::Adapters::Datefile::DefaultDatePattern)}.log" }
|
13
|
-
let(:tomorrow_filename) { fixture_path + "/test.#{tomorrow.strftime(Yell::Adapters::Datefile::DefaultDatePattern)}.log" }
|
14
|
-
|
15
|
-
let(:adapter) { Yell::Adapters::Datefile.new(:filename => filename, :format => "%m") }
|
16
|
-
|
17
|
-
before do
|
18
|
-
Timecop.freeze(today)
|
19
|
-
end
|
20
|
-
|
21
|
-
it { should be_kind_of Yell::Adapters::File }
|
22
|
-
|
23
|
-
describe "#write" do
|
24
|
-
let(:today_lines) { File.readlines(today_filename) }
|
25
|
-
|
26
|
-
before do
|
27
|
-
adapter.write(event)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should be output to filename with date pattern" do
|
31
|
-
expect(File.exist?(today_filename)).to be_true
|
32
|
-
|
33
|
-
expect(today_lines.size).to eq(2) # includes header line
|
34
|
-
expect(today_lines.last).to match(message)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should output to the same file" do
|
38
|
-
adapter.write(event)
|
39
|
-
|
40
|
-
expect(File.exist?(today_filename)).to be_true
|
41
|
-
expect(today_lines.size).to eq(3) # includes header line
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not open file handle again" do
|
45
|
-
dont_allow(File).open(anything, anything)
|
46
|
-
|
47
|
-
adapter.write(event)
|
48
|
-
end
|
49
|
-
|
50
|
-
context "on rollover" do
|
51
|
-
let(:tomorrow_lines) { File.readlines(tomorrow_filename) }
|
52
|
-
|
53
|
-
before do
|
54
|
-
Timecop.freeze(tomorrow) { adapter.write(event) }
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should rotate file" do
|
58
|
-
expect(File.exist?(tomorrow_filename)).to be_true
|
59
|
-
|
60
|
-
expect(tomorrow_lines.size).to eq(2) # includes header line
|
61
|
-
expect(tomorrow_lines.last).to match(message)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "#keep" do
|
67
|
-
before do
|
68
|
-
adapter.symlink = false # to not taint the Dir
|
69
|
-
adapter.keep = 2
|
70
|
-
|
71
|
-
adapter.write(event)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should keep the specified number or files upon rollover" do
|
75
|
-
expect(Dir[fixture_path + '/*.log'].size).to eq(1)
|
76
|
-
|
77
|
-
Timecop.freeze(tomorrow) { adapter.write(event) }
|
78
|
-
expect(Dir[fixture_path + '/*.log'].size).to eq(2)
|
79
|
-
|
80
|
-
Timecop.freeze(tomorrow + 86400 ) { adapter.write(event) }
|
81
|
-
expect(Dir[fixture_path + '/*.log'].size).to eq(2)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#symlink" do
|
86
|
-
context "when true (default)" do
|
87
|
-
before do
|
88
|
-
adapter.write(event)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should be created on the original filename" do
|
92
|
-
expect(File.symlink?(filename)).to be_true
|
93
|
-
expect(File.readlink(filename)).to eq(today_filename)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should be recreated upon rollover" do
|
97
|
-
Timecop.freeze(tomorrow) { adapter.write(event) }
|
98
|
-
|
99
|
-
expect(File.symlink?(filename)).to be_true
|
100
|
-
expect(File.readlink(filename)).to eq(tomorrow_filename)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "when false" do
|
105
|
-
before do
|
106
|
-
adapter.symlink = false
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should not create the sylink the original filename" do
|
110
|
-
adapter.write( event )
|
111
|
-
|
112
|
-
expect(File.symlink?(filename)).to be_false
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#header" do
|
118
|
-
let(:header) { File.open(today_filename, &:readline) }
|
119
|
-
|
120
|
-
context "when true (default)" do
|
121
|
-
before do
|
122
|
-
adapter.write(event)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should be written" do
|
126
|
-
expect(header).to match(Yell::Adapters::Datefile::HeaderRegexp)
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should be rewritten upon rollover" do
|
130
|
-
Timecop.freeze(tomorrow) { adapter.write(event) }
|
131
|
-
|
132
|
-
expect(File.symlink?(filename)).to be_true
|
133
|
-
expect(File.readlink(filename)).to eq(tomorrow_filename)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context "when false" do
|
138
|
-
before do
|
139
|
-
adapter.header = false
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should not be written" do
|
143
|
-
adapter.write(event)
|
144
|
-
|
145
|
-
expect(header).to eq("Hello World\n")
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "another adapter with the same :filename" do
|
151
|
-
let(:another_adapter) { Yell::Adapters::Datefile.new(:filename => filename) }
|
152
|
-
|
153
|
-
before do
|
154
|
-
adapter.write(event)
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should not write the header again" do
|
158
|
-
another_adapter.write(event)
|
159
|
-
|
160
|
-
# 1: header
|
161
|
-
# 2: adapter write
|
162
|
-
# 3: another_adapter: write
|
163
|
-
expect(File.readlines(today_filename).size).to eq(3)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yell::Adapters::File do
|
4
|
-
let(:devnull) { File.new('/dev/null', 'w') }
|
5
|
-
|
6
|
-
before do
|
7
|
-
stub(File).open(anything, anything) { devnull }
|
8
|
-
end
|
9
|
-
|
10
|
-
it { should be_kind_of(Yell::Adapters::Io) }
|
11
|
-
|
12
|
-
context "#stream" do
|
13
|
-
subject { Yell::Adapters::File.new.send(:stream) }
|
14
|
-
|
15
|
-
it { should be_kind_of(File) }
|
16
|
-
end
|
17
|
-
|
18
|
-
context "#write" do
|
19
|
-
let(:logger) { Yell::Logger.new }
|
20
|
-
let(:event) { Yell::Event.new(logger, 1, "Hello World") }
|
21
|
-
|
22
|
-
context "default filename" do
|
23
|
-
let(:filename) { File.expand_path "#{Yell.env}.log" }
|
24
|
-
let(:adapter) { Yell::Adapters::File.new }
|
25
|
-
|
26
|
-
it "should print to file" do
|
27
|
-
mock(File).open(filename, File::WRONLY|File::APPEND|File::CREAT) { devnull }
|
28
|
-
|
29
|
-
adapter.write(event)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "with given :filename" do
|
34
|
-
let(:filename) { fixture_path + '/filename.log' }
|
35
|
-
let(:adapter) { Yell::Adapters::File.new(:filename => filename) }
|
36
|
-
|
37
|
-
it "should print to file" do
|
38
|
-
mock(File).open(filename, File::WRONLY|File::APPEND|File::CREAT) { devnull }
|
39
|
-
|
40
|
-
adapter.write(event)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "with given :pathname" do
|
45
|
-
let(:pathname) { Pathname.new(fixture_path).join('filename.log') }
|
46
|
-
let(:adapter) { Yell::Adapters::File.new( :filename => pathname ) }
|
47
|
-
|
48
|
-
it "should accept pathanme as filename" do
|
49
|
-
mock(File).open(pathname.to_s, File::WRONLY|File::APPEND|File::CREAT) { devnull }
|
50
|
-
|
51
|
-
adapter.write(event)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
context "#sync" do
|
56
|
-
let(:adapter) { Yell::Adapters::File.new }
|
57
|
-
|
58
|
-
it "should sync by default" do
|
59
|
-
mock(devnull).sync=(true)
|
60
|
-
|
61
|
-
adapter.write(event)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "pass the option to File" do
|
65
|
-
adapter.sync = false
|
66
|
-
|
67
|
-
mock(devnull).sync=(false)
|
68
|
-
|
69
|
-
adapter.write(event)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yell::Adapters::Io do
|
4
|
-
|
5
|
-
it { should be_kind_of Yell::Adapters::Base }
|
6
|
-
|
7
|
-
context "initialize" do
|
8
|
-
it "should set default :format" do
|
9
|
-
adapter = Yell::Adapters::Io.new
|
10
|
-
|
11
|
-
expect(adapter.format).to be_kind_of(Yell::Formatter)
|
12
|
-
end
|
13
|
-
|
14
|
-
context ":level" do
|
15
|
-
let(:level) { Yell::Level.new(:warn) }
|
16
|
-
|
17
|
-
it "should set the level" do
|
18
|
-
adapter = Yell::Adapters::Io.new(:level => level)
|
19
|
-
|
20
|
-
expect(adapter.level).to eq(level)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should set the level when block was given" do
|
24
|
-
adapter = Yell::Adapters::Io.new { |a| a.level = level }
|
25
|
-
|
26
|
-
expect(adapter.level).to eq(level)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context ":format" do
|
31
|
-
let(:format) { Yell::Formatter.new }
|
32
|
-
|
33
|
-
it "should set the level" do
|
34
|
-
adapter = Yell::Adapters::Io.new(:format => format)
|
35
|
-
|
36
|
-
expect(adapter.format).to eq(format)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should set the level when block was given" do
|
40
|
-
adapter = Yell::Adapters::Io.new { |a| a.format = format }
|
41
|
-
|
42
|
-
expect(adapter.format).to eq(format)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context "#write" do
|
48
|
-
let(:logger) { Yell::Logger.new }
|
49
|
-
let(:event) { Yell::Event.new(logger, 1, "Hello World") }
|
50
|
-
let(:adapter) { Yell::Adapters::Io.new }
|
51
|
-
let(:stream) { File.new('/dev/null', 'w') }
|
52
|
-
|
53
|
-
before do
|
54
|
-
stub(adapter).stream { stream }
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should format the message" do
|
58
|
-
mock.proxy(adapter.format).format( event )
|
59
|
-
|
60
|
-
adapter.write(event)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should print formatted message to stream" do
|
64
|
-
formatted = Yell::Formatter.new.format( event )
|
65
|
-
mock(stream).syswrite( formatted << "\n" )
|
66
|
-
|
67
|
-
adapter.write(event)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|