lumberjack 1.0.13 → 1.1.0
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 +5 -5
- data/CHANGELOG.md +74 -0
- data/README.md +92 -20
- data/VERSION +1 -1
- data/lib/lumberjack.rb +51 -16
- data/lib/lumberjack/context.rb +35 -0
- data/lib/lumberjack/device.rb +20 -6
- data/lib/lumberjack/device/date_rolling_log_file.rb +2 -2
- data/lib/lumberjack/device/log_file.rb +12 -1
- data/lib/lumberjack/device/multi.rb +46 -0
- data/lib/lumberjack/device/null.rb +0 -2
- data/lib/lumberjack/device/rolling_log_file.rb +2 -2
- data/lib/lumberjack/device/size_rolling_log_file.rb +1 -1
- data/lib/lumberjack/device/writer.rb +86 -55
- data/lib/lumberjack/formatter.rb +54 -18
- data/lib/lumberjack/formatter/date_time_formatter.rb +26 -0
- data/lib/lumberjack/formatter/id_formatter.rb +23 -0
- data/lib/lumberjack/formatter/object_formatter.rb +12 -0
- data/lib/lumberjack/formatter/structured_formatter.rb +31 -0
- data/lib/lumberjack/log_entry.rb +41 -16
- data/lib/lumberjack/logger.rb +168 -63
- 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/severity.rb +11 -9
- data/lib/lumberjack/tags.rb +24 -0
- data/lib/lumberjack/template.rb +74 -32
- data/lumberjack.gemspec +35 -0
- metadata +48 -37
- 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/spec/lumberjack_spec.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack do
|
4
|
-
|
5
|
-
context "unit of work" do
|
6
|
-
it "should create a unit work with a unique id in a block" do
|
7
|
-
Lumberjack.unit_of_work_id.should == nil
|
8
|
-
Lumberjack.unit_of_work do
|
9
|
-
id_1 = Lumberjack.unit_of_work_id
|
10
|
-
id_1.should match(/^[0-9a-f]{12}$/)
|
11
|
-
Lumberjack.unit_of_work do
|
12
|
-
id_2 = Lumberjack.unit_of_work_id
|
13
|
-
id_2.should match(/^[0-9a-f]{12}$/)
|
14
|
-
id_2.should_not == id_1
|
15
|
-
end
|
16
|
-
id_1.should == Lumberjack.unit_of_work_id
|
17
|
-
end
|
18
|
-
Lumberjack.unit_of_work_id.should == nil
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should allow you to specify a unit of work id for a block" do
|
22
|
-
Lumberjack.unit_of_work("foo") do
|
23
|
-
Lumberjack.unit_of_work_id.should == "foo"
|
24
|
-
end
|
25
|
-
Lumberjack.unit_of_work_id.should == nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::Rack::RequestId do
|
4
|
-
|
5
|
-
it "should use the action dispatch request id if it exists" do
|
6
|
-
app = lambda{|env| [200, {"Content-Type" => env["Content-Type"], "Unit-Of-Work" => Lumberjack.unit_of_work_id.to_s}, ["OK"]]}
|
7
|
-
handler = Lumberjack::Rack::RequestId.new(app)
|
8
|
-
|
9
|
-
response = handler.call("Content-Type" => "text/plain", "action_dispatch.request_id" => "0123-4567-89ab-cdef")
|
10
|
-
response[0].should == 200
|
11
|
-
response[1]["Content-Type"].should == "text/plain"
|
12
|
-
response[1]["Unit-Of-Work"].should == "0123-4567-89ab-cdef"
|
13
|
-
response[2].should == ["OK"]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should use an abbreviated action dispatch request id if abbreviated is true" do
|
17
|
-
app = lambda{|env| [200, {"Content-Type" => env["Content-Type"], "Unit-Of-Work" => Lumberjack.unit_of_work_id.to_s}, ["OK"]]}
|
18
|
-
handler = Lumberjack::Rack::RequestId.new(app, true)
|
19
|
-
|
20
|
-
response = handler.call("Content-Type" => "text/plain", "action_dispatch.request_id" => "0123-4567-89ab-cdef")
|
21
|
-
response[0].should == 200
|
22
|
-
response[1]["Content-Type"].should == "text/plain"
|
23
|
-
response[1]["Unit-Of-Work"].should == "0123"
|
24
|
-
response[2].should == ["OK"]
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should create a unit of work in a middleware stack if the request id doesn't exist" do
|
28
|
-
app = lambda{|env| [200, {"Content-Type" => env["Content-Type"], "Unit-Of-Work" => Lumberjack.unit_of_work_id.to_s}, ["OK"]]}
|
29
|
-
handler = Lumberjack::Rack::RequestId.new(app)
|
30
|
-
|
31
|
-
response = handler.call("Content-Type" => "text/plain")
|
32
|
-
response[0].should == 200
|
33
|
-
response[1]["Content-Type"].should == "text/plain"
|
34
|
-
unit_of_work_1 = response[1]["Unit-Of-Work"]
|
35
|
-
response[2].should == ["OK"]
|
36
|
-
|
37
|
-
response = handler.call("Content-Type" => "text/html")
|
38
|
-
response[0].should == 200
|
39
|
-
response[1]["Content-Type"].should == "text/html"
|
40
|
-
unit_of_work_2 = response[1]["Unit-Of-Work"]
|
41
|
-
response[2].should == ["OK"]
|
42
|
-
|
43
|
-
unit_of_work_1.should_not == nil
|
44
|
-
unit_of_work_2.should_not == nil
|
45
|
-
unit_of_work_1.should_not == unit_of_work_2
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::Rack::UnitOfWork do
|
4
|
-
|
5
|
-
it "should create a unit of work in a middleware stack" do
|
6
|
-
app = lambda{|env| [200, {"Content-Type" => env["Content-Type"], "Unit-Of-Work" => Lumberjack.unit_of_work_id.to_s}, ["OK"]]}
|
7
|
-
handler = Lumberjack::Rack::UnitOfWork.new(app)
|
8
|
-
|
9
|
-
response = handler.call("Content-Type" => "text/plain")
|
10
|
-
response[0].should == 200
|
11
|
-
response[1]["Content-Type"].should == "text/plain"
|
12
|
-
unit_of_work_1 = response[1]["Unit-Of-Work"]
|
13
|
-
response[2].should == ["OK"]
|
14
|
-
|
15
|
-
response = handler.call("Content-Type" => "text/html")
|
16
|
-
response[0].should == 200
|
17
|
-
response[1]["Content-Type"].should == "text/html"
|
18
|
-
unit_of_work_2 = response[1]["Unit-Of-Work"]
|
19
|
-
response[2].should == ["OK"]
|
20
|
-
|
21
|
-
unit_of_work_1.should_not == nil
|
22
|
-
unit_of_work_2.should_not == nil
|
23
|
-
unit_of_work_1.should_not == unit_of_work_2
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/spec/severity_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::Severity do
|
4
|
-
|
5
|
-
it "should convert a level to a label" do
|
6
|
-
Lumberjack::Severity.level_to_label(Lumberjack::Severity::DEBUG).should == "DEBUG"
|
7
|
-
Lumberjack::Severity.level_to_label(Lumberjack::Severity::INFO).should == "INFO"
|
8
|
-
Lumberjack::Severity.level_to_label(Lumberjack::Severity::WARN).should == "WARN"
|
9
|
-
Lumberjack::Severity.level_to_label(Lumberjack::Severity::ERROR).should == "ERROR"
|
10
|
-
Lumberjack::Severity.level_to_label(Lumberjack::Severity::FATAL).should == "FATAL"
|
11
|
-
Lumberjack::Severity.level_to_label(-1).should == "UNKNOWN"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should convert a label to a level" do
|
15
|
-
Lumberjack::Severity.label_to_level("DEBUG").should == Lumberjack::Severity::DEBUG
|
16
|
-
Lumberjack::Severity.label_to_level(:info).should == Lumberjack::Severity::INFO
|
17
|
-
Lumberjack::Severity.label_to_level(:warn).should == Lumberjack::Severity::WARN
|
18
|
-
Lumberjack::Severity.label_to_level("Error").should == Lumberjack::Severity::ERROR
|
19
|
-
Lumberjack::Severity.label_to_level("FATAL").should == Lumberjack::Severity::FATAL
|
20
|
-
Lumberjack::Severity.label_to_level("???").should == Lumberjack::Severity::UNKNOWN
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require File.expand_path("../../lib/lumberjack.rb", __FILE__)
|
2
|
-
require 'stringio'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'timecop'
|
5
|
-
|
6
|
-
RSpec.configure do |config|
|
7
|
-
config.expect_with :rspec do |c|
|
8
|
-
c.syntax = [:should, :expect]
|
9
|
-
end
|
10
|
-
config.mock_with :rspec do |c|
|
11
|
-
c.syntax = [:should, :expect]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def tmp_dir
|
16
|
-
File.expand_path("../tmp", __FILE__)
|
17
|
-
end
|
18
|
-
|
19
|
-
def create_tmp_dir
|
20
|
-
FileUtils.rm_r(tmp_dir) if File.exist?(tmp_dir)
|
21
|
-
FileUtils.mkdir_p(tmp_dir)
|
22
|
-
end
|
23
|
-
|
24
|
-
def delete_tmp_dir
|
25
|
-
FileUtils.rm_r(tmp_dir)
|
26
|
-
end
|
27
|
-
|
28
|
-
def delete_tmp_files
|
29
|
-
Dir.glob(File.join(tmp_dir, "*")) do |file|
|
30
|
-
File.delete(file)
|
31
|
-
end
|
32
|
-
end
|
data/spec/template_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Lumberjack::Template do
|
4
|
-
|
5
|
-
let(:time_string){ "2011-01-15T14:23:45.123" }
|
6
|
-
let(:time){ Time.parse(time_string) }
|
7
|
-
let(:entry){ Lumberjack::LogEntry.new(time, Lumberjack::Severity::INFO, "line 1#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3", "app", 12345, "ABCD") }
|
8
|
-
|
9
|
-
it "should format a log entry with a template string" do
|
10
|
-
template = Lumberjack::Template.new(":message - :severity, :time, :progname@:pid (:unit_of_work_id)")
|
11
|
-
template.call(entry).should == "line 1 - INFO, 2011-01-15T14:23:45.123, app@12345 (ABCD)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should be able to specify the time format for log entries as microseconds" do
|
15
|
-
template = Lumberjack::Template.new(":message (:time)", :time_format => :microseconds)
|
16
|
-
template.call(entry).should == "line 1 (2011-01-15T14:23:45.123000)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should be able to specify the time format for log entries as milliseconds" do
|
20
|
-
template = Lumberjack::Template.new(":message (:time)", :time_format => :milliseconds)
|
21
|
-
template.call(entry).should == "line 1 (2011-01-15T14:23:45.123)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
|
22
|
-
end
|
23
|
-
|
24
|
-
it "should be able to specify the time format for log entries with a custom format" do
|
25
|
-
template = Lumberjack::Template.new(":message (:time)", :time_format => "%m/%d/%Y, %I:%M:%S %p")
|
26
|
-
template.call(entry).should == "line 1 (01/15/2011, 02:23:45 PM)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should be able to specify a template for additional lines in a message" do
|
30
|
-
template = Lumberjack::Template.new(":message (:time)", :additional_lines => " // :message")
|
31
|
-
template.call(entry).should == "line 1 (2011-01-15T14:23:45.123) // line 2 // line 3"
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|