lumberjack 1.0.13 → 1.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +129 -0
- data/{MIT_LICENSE → MIT_LICENSE.txt} +0 -0
- data/README.md +142 -23
- data/VERSION +1 -1
- data/lib/lumberjack.rb +70 -22
- data/lib/lumberjack/context.rb +35 -0
- data/lib/lumberjack/device.rb +22 -8
- data/lib/lumberjack/device/date_rolling_log_file.rb +9 -9
- data/lib/lumberjack/device/log_file.rb +14 -3
- data/lib/lumberjack/device/multi.rb +46 -0
- data/lib/lumberjack/device/null.rb +1 -3
- data/lib/lumberjack/device/rolling_log_file.rb +45 -21
- data/lib/lumberjack/device/size_rolling_log_file.rb +10 -10
- data/lib/lumberjack/device/writer.rb +92 -61
- data/lib/lumberjack/formatter.rb +97 -28
- data/lib/lumberjack/formatter/date_time_formatter.rb +25 -0
- data/lib/lumberjack/formatter/exception_formatter.rb +25 -2
- data/lib/lumberjack/formatter/id_formatter.rb +23 -0
- data/lib/lumberjack/formatter/object_formatter.rb +12 -0
- data/lib/lumberjack/formatter/pretty_print_formatter.rb +4 -4
- data/lib/lumberjack/formatter/string_formatter.rb +1 -1
- data/lib/lumberjack/formatter/strip_formatter.rb +12 -0
- data/lib/lumberjack/formatter/structured_formatter.rb +63 -0
- data/lib/lumberjack/log_entry.rb +44 -16
- data/lib/lumberjack/logger.rb +275 -69
- data/lib/lumberjack/rack.rb +3 -2
- data/lib/lumberjack/rack/context.rb +18 -0
- data/lib/lumberjack/rack/request_id.rb +4 -4
- data/lib/lumberjack/rack/unit_of_work.rb +1 -1
- data/lib/lumberjack/severity.rb +11 -10
- data/lib/lumberjack/tag_formatter.rb +96 -0
- data/lib/lumberjack/tagged_logger_support.rb +66 -0
- data/lib/lumberjack/tagged_logging.rb +29 -0
- data/lib/lumberjack/tags.rb +42 -0
- data/lib/lumberjack/template.rb +81 -33
- data/lumberjack.gemspec +31 -0
- metadata +26 -53
- data/Rakefile +0 -40
- data/spec/device/date_rolling_log_file_spec.rb +0 -73
- data/spec/device/log_file_spec.rb +0 -48
- data/spec/device/null_spec.rb +0 -12
- data/spec/device/rolling_log_file_spec.rb +0 -151
- data/spec/device/size_rolling_log_file_spec.rb +0 -58
- data/spec/device/writer_spec.rb +0 -118
- data/spec/formatter/exception_formatter_spec.rb +0 -20
- data/spec/formatter/inspect_formatter_spec.rb +0 -13
- data/spec/formatter/pretty_print_formatter_spec.rb +0 -14
- data/spec/formatter/string_formatter_spec.rb +0 -12
- data/spec/formatter_spec.rb +0 -45
- data/spec/log_entry_spec.rb +0 -69
- data/spec/logger_spec.rb +0 -411
- data/spec/lumberjack_spec.rb +0 -29
- data/spec/rack/request_id_spec.rb +0 -48
- data/spec/rack/unit_of_work_spec.rb +0 -26
- data/spec/severity_spec.rb +0 -23
- data/spec/spec_helper.rb +0 -32
- data/spec/template_spec.rb +0 -34
data/lumberjack.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lumberjack"
|
3
|
+
spec.version = File.read(File.join(__dir__, "VERSION")).strip
|
4
|
+
spec.authors = ["Brian Durand"]
|
5
|
+
spec.email = ["bbdurand@gmail.com"]
|
6
|
+
|
7
|
+
spec.summary = "A simple, powerful, and very fast logging utility that can be a drop in replacement for Logger or ActiveSupport::BufferedLogger."
|
8
|
+
spec.homepage = "https://github.com/bdurand/lumberjack"
|
9
|
+
spec.license = "MIT"
|
10
|
+
|
11
|
+
# Specify which files should be added to the gem when it is released.
|
12
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
13
|
+
ignore_files = %w[
|
14
|
+
.
|
15
|
+
Appraisals
|
16
|
+
Gemfile
|
17
|
+
Gemfile.lock
|
18
|
+
Rakefile
|
19
|
+
gemfiles/
|
20
|
+
spec/
|
21
|
+
]
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| ignore_files.any? { |path| f.start_with?(path) } }
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.required_ruby_version = ">= 2.3.0"
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler"
|
31
|
+
end
|
metadata
CHANGED
@@ -1,103 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lumberjack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
27
|
-
|
28
|
-
name: timecop
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.8'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.8'
|
41
|
-
description: A simple, powerful, and very fast logging utility that can be a drop
|
42
|
-
in replacement for Logger or ActiveSupport::BufferedLogger. Provides support for
|
43
|
-
automatically rolling log files even with multiple processes writing the same log
|
44
|
-
file.
|
26
|
+
version: '0'
|
27
|
+
description:
|
45
28
|
email:
|
46
29
|
- bbdurand@gmail.com
|
47
30
|
executables: []
|
48
31
|
extensions: []
|
49
32
|
extra_rdoc_files: []
|
50
33
|
files:
|
51
|
-
-
|
34
|
+
- CHANGELOG.md
|
35
|
+
- MIT_LICENSE.txt
|
52
36
|
- README.md
|
53
|
-
- Rakefile
|
54
37
|
- VERSION
|
55
38
|
- lib/lumberjack.rb
|
39
|
+
- lib/lumberjack/context.rb
|
56
40
|
- lib/lumberjack/device.rb
|
57
41
|
- lib/lumberjack/device/date_rolling_log_file.rb
|
58
42
|
- lib/lumberjack/device/log_file.rb
|
43
|
+
- lib/lumberjack/device/multi.rb
|
59
44
|
- lib/lumberjack/device/null.rb
|
60
45
|
- lib/lumberjack/device/rolling_log_file.rb
|
61
46
|
- lib/lumberjack/device/size_rolling_log_file.rb
|
62
47
|
- lib/lumberjack/device/writer.rb
|
63
48
|
- lib/lumberjack/formatter.rb
|
49
|
+
- lib/lumberjack/formatter/date_time_formatter.rb
|
64
50
|
- lib/lumberjack/formatter/exception_formatter.rb
|
51
|
+
- lib/lumberjack/formatter/id_formatter.rb
|
65
52
|
- lib/lumberjack/formatter/inspect_formatter.rb
|
53
|
+
- lib/lumberjack/formatter/object_formatter.rb
|
66
54
|
- lib/lumberjack/formatter/pretty_print_formatter.rb
|
67
55
|
- lib/lumberjack/formatter/string_formatter.rb
|
56
|
+
- lib/lumberjack/formatter/strip_formatter.rb
|
57
|
+
- lib/lumberjack/formatter/structured_formatter.rb
|
68
58
|
- lib/lumberjack/log_entry.rb
|
69
59
|
- lib/lumberjack/logger.rb
|
70
60
|
- lib/lumberjack/rack.rb
|
61
|
+
- lib/lumberjack/rack/context.rb
|
71
62
|
- lib/lumberjack/rack/request_id.rb
|
72
63
|
- lib/lumberjack/rack/unit_of_work.rb
|
73
64
|
- lib/lumberjack/severity.rb
|
65
|
+
- lib/lumberjack/tag_formatter.rb
|
66
|
+
- lib/lumberjack/tagged_logger_support.rb
|
67
|
+
- lib/lumberjack/tagged_logging.rb
|
68
|
+
- lib/lumberjack/tags.rb
|
74
69
|
- lib/lumberjack/template.rb
|
75
|
-
-
|
76
|
-
- spec/device/log_file_spec.rb
|
77
|
-
- spec/device/null_spec.rb
|
78
|
-
- spec/device/rolling_log_file_spec.rb
|
79
|
-
- spec/device/size_rolling_log_file_spec.rb
|
80
|
-
- spec/device/writer_spec.rb
|
81
|
-
- spec/formatter/exception_formatter_spec.rb
|
82
|
-
- spec/formatter/inspect_formatter_spec.rb
|
83
|
-
- spec/formatter/pretty_print_formatter_spec.rb
|
84
|
-
- spec/formatter/string_formatter_spec.rb
|
85
|
-
- spec/formatter_spec.rb
|
86
|
-
- spec/log_entry_spec.rb
|
87
|
-
- spec/logger_spec.rb
|
88
|
-
- spec/lumberjack_spec.rb
|
89
|
-
- spec/rack/request_id_spec.rb
|
90
|
-
- spec/rack/unit_of_work_spec.rb
|
91
|
-
- spec/severity_spec.rb
|
92
|
-
- spec/spec_helper.rb
|
93
|
-
- spec/template_spec.rb
|
70
|
+
- lumberjack.gemspec
|
94
71
|
homepage: https://github.com/bdurand/lumberjack
|
95
72
|
licenses:
|
96
73
|
- MIT
|
97
|
-
metadata:
|
98
|
-
homepage_uri: https://github.com/bdurand/lumberjack
|
99
|
-
changelog_uri: https://github.com/bdurand/lumberjack/blob/master/CHANGELOG.md
|
100
|
-
source_code_uri: https://github.com/bdurand/lumberjack
|
74
|
+
metadata: {}
|
101
75
|
post_install_message:
|
102
76
|
rdoc_options: []
|
103
77
|
require_paths:
|
@@ -106,15 +80,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
80
|
requirements:
|
107
81
|
- - ">="
|
108
82
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
83
|
+
version: 2.3.0
|
110
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
85
|
requirements:
|
112
86
|
- - ">="
|
113
87
|
- !ruby/object:Gem::Version
|
114
88
|
version: '0'
|
115
89
|
requirements: []
|
116
|
-
|
117
|
-
rubygems_version: 2.5.2.2
|
90
|
+
rubygems_version: 3.0.3
|
118
91
|
signing_key:
|
119
92
|
specification_version: 4
|
120
93
|
summary: A simple, powerful, and very fast logging utility that can be a drop in replacement
|
data/Rakefile
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rubygems/package_task'
|
4
|
-
|
5
|
-
desc 'Default: run unit tests.'
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
desc 'RVM likes to call it tests'
|
9
|
-
task :tests => :test
|
10
|
-
|
11
|
-
begin
|
12
|
-
require 'rspec'
|
13
|
-
require 'rspec/core/rake_task'
|
14
|
-
desc 'Run the unit tests'
|
15
|
-
RSpec::Core::RakeTask.new(:test)
|
16
|
-
rescue LoadError
|
17
|
-
task :test do
|
18
|
-
STDERR.puts "You must have rspec 2.0 installed to run the tests"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
namespace :rbx do
|
23
|
-
desc "Cleanup *.rbc files in lib directory"
|
24
|
-
task :delete_rbc_files do
|
25
|
-
FileList["**/*.rbc"].each do |rbc_file|
|
26
|
-
File.delete(rbc_file)
|
27
|
-
end
|
28
|
-
nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
spec_file = File.expand_path('../lumberjack.gemspec', __FILE__)
|
33
|
-
if File.exist?(spec_file)
|
34
|
-
spec = eval(File.read(spec_file))
|
35
|
-
|
36
|
-
Gem::PackageTask.new(spec) do |p|
|
37
|
-
p.gem_spec = spec
|
38
|
-
end
|
39
|
-
Rake.application["package"].prerequisites.unshift("rbx:delete_rbc_files")
|
40
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::Device::DateRollingLogFile do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
create_tmp_dir
|
7
|
-
end
|
8
|
-
|
9
|
-
after :all do
|
10
|
-
delete_tmp_dir
|
11
|
-
end
|
12
|
-
|
13
|
-
before :each do
|
14
|
-
delete_tmp_files
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:one_day){ 60 * 60 * 24 }
|
18
|
-
|
19
|
-
it "should roll the file daily" do
|
20
|
-
now = Time.now
|
21
|
-
log_file = File.join(tmp_dir, "a#{rand(1000000000)}.log")
|
22
|
-
device = Lumberjack::Device::DateRollingLogFile.new(log_file, :roll => :daily, :template => ":message", :min_roll_check => 0)
|
23
|
-
logger = Lumberjack::Logger.new(device, :buffer_size => 2)
|
24
|
-
Timecop.travel(now) do
|
25
|
-
logger.error("test day one")
|
26
|
-
logger.flush
|
27
|
-
end
|
28
|
-
Timecop.travel(now + one_day) do
|
29
|
-
logger.error("test day two")
|
30
|
-
logger.close
|
31
|
-
end
|
32
|
-
|
33
|
-
File.read("#{log_file}.#{now.to_date.strftime('%Y-%m-%d')}").should == "test day one#{Lumberjack::LINE_SEPARATOR}"
|
34
|
-
File.read(log_file).should == "test day two#{Lumberjack::LINE_SEPARATOR}"
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should roll the file weekly" do
|
38
|
-
now = Time.now
|
39
|
-
log_file = File.join(tmp_dir, "b#{rand(1000000000)}.log")
|
40
|
-
device = Lumberjack::Device::DateRollingLogFile.new(log_file, :roll => :weekly, :template => ":message", :min_roll_check => 0)
|
41
|
-
logger = Lumberjack::Logger.new(device, :buffer_size => 2)
|
42
|
-
Timecop.freeze(now) do
|
43
|
-
logger.error("test week one")
|
44
|
-
logger.flush
|
45
|
-
end
|
46
|
-
Timecop.freeze(now + (7 * one_day)) do
|
47
|
-
logger.error("test week two")
|
48
|
-
logger.close
|
49
|
-
end
|
50
|
-
|
51
|
-
File.read("#{log_file}.#{now.to_date.strftime('week-of-%Y-%m-%d')}").should == "test week one#{Lumberjack::LINE_SEPARATOR}"
|
52
|
-
File.read(log_file).should == "test week two#{Lumberjack::LINE_SEPARATOR}"
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should roll the file monthly" do
|
56
|
-
now = Time.now
|
57
|
-
log_file = File.join(tmp_dir, "c#{rand(1000000000)}.log")
|
58
|
-
device = Lumberjack::Device::DateRollingLogFile.new(log_file, :roll => :monthly, :template => ":message", :min_roll_check => 0)
|
59
|
-
logger = Lumberjack::Logger.new(device, :buffer_size => 2)
|
60
|
-
Timecop.freeze(now) do
|
61
|
-
logger.error("test month one")
|
62
|
-
logger.flush
|
63
|
-
end
|
64
|
-
Timecop.freeze(now + (31 * one_day)) do
|
65
|
-
logger.error("test month two")
|
66
|
-
logger.close
|
67
|
-
end
|
68
|
-
|
69
|
-
File.read("#{log_file}.#{now.to_date.strftime('%Y-%m')}").should == "test month one#{Lumberjack::LINE_SEPARATOR}"
|
70
|
-
File.read(log_file).should == "test month two#{Lumberjack::LINE_SEPARATOR}"
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe Lumberjack::Device::LogFile do
|
5
|
-
|
6
|
-
before :all do
|
7
|
-
create_tmp_dir
|
8
|
-
end
|
9
|
-
|
10
|
-
after :all do
|
11
|
-
delete_tmp_dir
|
12
|
-
end
|
13
|
-
|
14
|
-
before :each do
|
15
|
-
delete_tmp_files
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should append to a file" do
|
19
|
-
log_file = File.join(tmp_dir, "a#{rand(1000000000)}.log")
|
20
|
-
File.open(log_file, 'w') do |f|
|
21
|
-
f.puts("Existing contents")
|
22
|
-
end
|
23
|
-
|
24
|
-
device = Lumberjack::Device::LogFile.new(log_file, :template => ":message")
|
25
|
-
device.write(Lumberjack::LogEntry.new(Time.now, 1, "New log entry", nil, $$, nil))
|
26
|
-
device.close
|
27
|
-
|
28
|
-
File.read(log_file).should == "Existing contents\nNew log entry#{Lumberjack::LINE_SEPARATOR}"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "properly handles messages with broken UTF-8 characters" do
|
32
|
-
log_file = File.join(tmp_dir, "test_6.log")
|
33
|
-
device = Lumberjack::Device::LogFile.new(log_file,
|
34
|
-
:keep => 2, :buffer_size => 32767)
|
35
|
-
|
36
|
-
message = [0xC4, 0x90, 0xE1, 0xBB].pack("c*").force_encoding "ASCII-8BIT"
|
37
|
-
entry = Lumberjack::LogEntry.new(Time.now, 1, message, nil, $$, nil)
|
38
|
-
device.write entry
|
39
|
-
|
40
|
-
message = "проверка"
|
41
|
-
entry = Lumberjack::LogEntry.new(Time.now, 1, message, nil, $$, nil)
|
42
|
-
device.write entry
|
43
|
-
|
44
|
-
expect do
|
45
|
-
device.flush
|
46
|
-
end.to_not raise_error
|
47
|
-
end
|
48
|
-
end
|
data/spec/device/null_spec.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::Device::Null do
|
4
|
-
|
5
|
-
it "should not generate any output" do
|
6
|
-
device = Lumberjack::Device::Null.new
|
7
|
-
device.write(Lumberjack::LogEntry.new(Time.now, 1, "New log entry", nil, $$, nil))
|
8
|
-
device.flush
|
9
|
-
device.close
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::Device::RollingLogFile do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
Lumberjack::Device::SizeRollingLogFile #needed by jruby
|
7
|
-
create_tmp_dir
|
8
|
-
end
|
9
|
-
|
10
|
-
after :all do
|
11
|
-
delete_tmp_dir
|
12
|
-
end
|
13
|
-
|
14
|
-
before :each do
|
15
|
-
delete_tmp_files
|
16
|
-
end
|
17
|
-
|
18
|
-
let(:entry){ Lumberjack::LogEntry.new(Time.now, 1, "New log entry", nil, $$, nil) }
|
19
|
-
|
20
|
-
it "should check for rolling the log file on flush" do
|
21
|
-
device = Lumberjack::Device::RollingLogFile.new(File.join(tmp_dir, "test.log"), :buffer_size => 32767, :min_roll_check => 0)
|
22
|
-
device.write(entry)
|
23
|
-
expect(device).to receive(:roll_file?).twice.and_return(false)
|
24
|
-
device.flush
|
25
|
-
device.close
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should roll the file by archiving the existing file and opening a new stream and calling after_roll" do
|
29
|
-
log_file = File.join(tmp_dir, "test_2.log")
|
30
|
-
device = Lumberjack::Device::RollingLogFile.new(log_file, :template => ":message", :buffer_size => 32767, :min_roll_check => 0)
|
31
|
-
expect(device).to receive(:roll_file?).and_return(false, true)
|
32
|
-
expect(device).to receive(:after_roll)
|
33
|
-
device.stub(:archive_file_suffix => "rolled")
|
34
|
-
device.write(entry)
|
35
|
-
device.flush
|
36
|
-
device.write(Lumberjack::LogEntry.new(Time.now, 1, "Another log entry", nil, $$, nil))
|
37
|
-
device.close
|
38
|
-
File.read("#{log_file}.rolled").should == "New log entry#{Lumberjack::LINE_SEPARATOR}"
|
39
|
-
File.read(log_file).should == "Another log entry#{Lumberjack::LINE_SEPARATOR}"
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should reopen the file if the stream inode doesn't match the file path inode" do
|
43
|
-
log_file = File.join(tmp_dir, "test_3.log")
|
44
|
-
device = Lumberjack::Device::RollingLogFile.new(log_file, :template => ":message", :min_roll_check => 0)
|
45
|
-
device.stub(:roll_file? => false)
|
46
|
-
device.write(entry)
|
47
|
-
device.flush
|
48
|
-
File.rename(log_file, "#{log_file}.rolled")
|
49
|
-
device.flush
|
50
|
-
device.write(Lumberjack::LogEntry.new(Time.now, 1, "Another log entry", nil, $$, nil))
|
51
|
-
device.close
|
52
|
-
File.read("#{log_file}.rolled").should == "New log entry#{Lumberjack::LINE_SEPARATOR}"
|
53
|
-
File.read(log_file).should == "Another log entry#{Lumberjack::LINE_SEPARATOR}"
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should roll the file properly with multiple thread and processes using it" do
|
57
|
-
log_file = File.join(tmp_dir, "test_4.log")
|
58
|
-
process_count = 8
|
59
|
-
thread_count = 4
|
60
|
-
entry_count = 400
|
61
|
-
max_size = 128
|
62
|
-
severity = Lumberjack::Severity::INFO
|
63
|
-
message = "This is a test message that is written to the log file to indicate what the state of the application is."
|
64
|
-
|
65
|
-
logger_test = lambda do
|
66
|
-
device = Lumberjack::Device::SizeRollingLogFile.new(log_file, :max_size => max_size, :template => ":message", :buffer_size => 32767, :min_roll_check => 0)
|
67
|
-
threads = []
|
68
|
-
thread_count.times do
|
69
|
-
threads << Thread.new do
|
70
|
-
entry_count.times do |i|
|
71
|
-
device.write(Lumberjack::LogEntry.new(Time.now, severity, message, "test", $$, nil))
|
72
|
-
device.flush if i % 10 == 0
|
73
|
-
end
|
74
|
-
device.flush
|
75
|
-
end
|
76
|
-
end
|
77
|
-
threads.each{|thread| thread.value}
|
78
|
-
device.close
|
79
|
-
end
|
80
|
-
|
81
|
-
# Process.fork is unavailable on jruby so we need to use the java threads instead.
|
82
|
-
if RUBY_PLATFORM.match(/java/)
|
83
|
-
outer_threads = []
|
84
|
-
process_count.times do
|
85
|
-
outer_threads << Thread.new(&logger_test)
|
86
|
-
end
|
87
|
-
outer_threads.each{|thread| thread.value}
|
88
|
-
else
|
89
|
-
process_count.times do
|
90
|
-
Process.fork(&logger_test)
|
91
|
-
end
|
92
|
-
Process.waitall
|
93
|
-
end
|
94
|
-
|
95
|
-
line_count = 0
|
96
|
-
file_count = 0
|
97
|
-
Dir.glob("#{log_file}*").each do |file|
|
98
|
-
file_count += 1
|
99
|
-
lines = File.read(file).split(Lumberjack::LINE_SEPARATOR)
|
100
|
-
line_count += lines.size
|
101
|
-
lines.each do |line|
|
102
|
-
line.should == message
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
file_count.should > 3
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should only keep a specified number of archived log files" do
|
110
|
-
log_file = File.join(tmp_dir, "test_5.log")
|
111
|
-
device = Lumberjack::Device::RollingLogFile.new(log_file, :template => ":message", :keep => 2, :buffer_size => 32767, :min_roll_check => 0)
|
112
|
-
expect(device).to receive(:roll_file?).and_return(false, true, true, true)
|
113
|
-
expect(device).to receive(:archive_file_suffix).and_return("delete", "another", "keep")
|
114
|
-
t = Time.now
|
115
|
-
expect(File).to receive(:ctime).with("#{log_file}.delete").at_least(1).times.and_return(t + 1)
|
116
|
-
expect(File).to receive(:ctime).with("#{log_file}.another").at_least(1).times.and_return(t + 2)
|
117
|
-
expect(File).to receive(:ctime).with("#{log_file}.keep").at_least(1).times.and_return(t + 3)
|
118
|
-
device.write(entry)
|
119
|
-
device.flush
|
120
|
-
device.write(entry)
|
121
|
-
device.flush
|
122
|
-
device.write(entry)
|
123
|
-
device.flush
|
124
|
-
device.write(entry)
|
125
|
-
device.close
|
126
|
-
Dir.glob("#{log_file}*").sort.should == [log_file, "#{log_file}.another", "#{log_file}.keep"]
|
127
|
-
end
|
128
|
-
|
129
|
-
context "when file is rolled" do
|
130
|
-
let(:log_file) { File.join(tmp_dir, "test_6.log") }
|
131
|
-
|
132
|
-
let(:device) do
|
133
|
-
device = Lumberjack::Device::RollingLogFile.new(log_file, :template => ":message", :keep => 2, :buffer_size => 32767, :min_roll_check => 0)
|
134
|
-
device.stub(:roll_file?).and_return(true)
|
135
|
-
device.stub(:archive_file_suffix => "rolled")
|
136
|
-
device
|
137
|
-
end
|
138
|
-
|
139
|
-
before do
|
140
|
-
device.write(entry)
|
141
|
-
device.flush
|
142
|
-
end
|
143
|
-
|
144
|
-
it "reopens file with proper encoding" do
|
145
|
-
encoding = device.send(:stream).external_encoding
|
146
|
-
expect(encoding).to_not be_nil
|
147
|
-
expect(encoding.name).to eq "ASCII-8BIT"
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|