sawmill 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +17 -0
- data/lib/sawmill/entry.rb +17 -1
- data/lib/sawmill/entry_processor/build_records.rb +10 -7
- data/lib/sawmill/entry_processor/compile_report.rb +115 -0
- data/lib/sawmill/entry_processor/conditionals.rb +22 -23
- data/lib/sawmill/entry_processor/count_entries.rb +112 -0
- data/lib/sawmill/entry_processor/{filter_basic_fields.rb → filter_by_basic_fields.rb} +3 -3
- data/lib/sawmill/entry_processor/filter_by_block.rb +96 -0
- data/lib/sawmill/entry_processor/format.rb +9 -1
- data/lib/sawmill/entry_processor/simple_queue.rb +2 -1
- data/lib/sawmill/entry_processor.rb +68 -5
- data/lib/sawmill/errors.rb +7 -0
- data/lib/sawmill/interface.rb +324 -0
- data/lib/sawmill/logger.rb +8 -7
- data/lib/sawmill/record.rb +14 -0
- data/lib/sawmill/record_processor/compile_report.rb +113 -0
- data/lib/sawmill/record_processor/conditionals.rb +12 -13
- data/lib/sawmill/record_processor/count_records.rb +84 -0
- data/lib/sawmill/record_processor/decompose.rb +2 -2
- data/lib/sawmill/record_processor/filter_by_attributes.rb +2 -1
- data/lib/sawmill/record_processor/filter_by_block.rb +95 -0
- data/lib/sawmill/record_processor/filter_by_record_id.rb +2 -1
- data/lib/sawmill/record_processor/format.rb +8 -2
- data/lib/sawmill/record_processor/simple_queue.rb +2 -1
- data/lib/sawmill/record_processor.rb +69 -5
- data/lib/sawmill/rotater/date_based_log_file.rb +8 -8
- data/lib/sawmill/rotater/shifting_log_file.rb +7 -6
- data/lib/sawmill/util/processor_tools.rb +71 -0
- data/lib/sawmill/version.rb +1 -3
- data/lib/sawmill.rb +9 -1
- data/tests/tc_entry_processors.rb +7 -7
- data/tests/tc_reports.rb +101 -0
- metadata +13 -3
data/tests/tc_reports.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Sawmill: tests reports
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2009 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
|
35
|
+
|
36
|
+
require 'test/unit'
|
37
|
+
require 'stringio'
|
38
|
+
require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/sawmill.rb")
|
39
|
+
|
40
|
+
|
41
|
+
module Sawmill
|
42
|
+
module Tests # :nodoc:
|
43
|
+
|
44
|
+
class TestMultiParser < ::Test::Unit::TestCase # :nodoc:
|
45
|
+
|
46
|
+
|
47
|
+
def setup
|
48
|
+
@levels = ::Sawmill::STANDARD_LEVELS
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# Test entry report.
|
53
|
+
|
54
|
+
def test_entry_report
|
55
|
+
processor_ = EntryProcessor.build do
|
56
|
+
CompileReport(If(FilterByBasicFields(:level => :WARN),
|
57
|
+
CountEntries(:label => 'warn: ')),
|
58
|
+
If(FilterByBasicFields(:level => :ERROR),
|
59
|
+
CountEntries(:label => 'error: ')))
|
60
|
+
end
|
61
|
+
logger_ = Logger.new(:processor => processor_)
|
62
|
+
logger_.info("hello 1")
|
63
|
+
logger_.warn("hello 2")
|
64
|
+
logger_.info("hello 3")
|
65
|
+
logger_.error("hello 4")
|
66
|
+
logger_.fatal("hello 5")
|
67
|
+
logger_.info("hello 6")
|
68
|
+
assert_equal("warn: 3\nerror: 2", logger_.close)
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# Test record report.
|
73
|
+
|
74
|
+
def test_record_report
|
75
|
+
processor_ = RecordProcessor.build do
|
76
|
+
CompileReport(If(FilterByAttributes('user' => 'daniel'),
|
77
|
+
CountRecords(:label => 'daniel: ')),
|
78
|
+
If(FilterByAttributes('location' => 'seattle'),
|
79
|
+
CountRecords(:label => 'seattle: ')))
|
80
|
+
end
|
81
|
+
logger_ = Logger.new(:processor => Sawmill::RecordBuilder.new(processor_))
|
82
|
+
logger_.begin_record
|
83
|
+
logger_.set_attribute('user', 'daniel')
|
84
|
+
logger_.set_attribute('location', 'tacoma')
|
85
|
+
logger_.end_record
|
86
|
+
logger_.begin_record
|
87
|
+
logger_.set_attribute('user', 'daniel')
|
88
|
+
logger_.set_attribute('location', 'seattle')
|
89
|
+
logger_.end_record
|
90
|
+
logger_.begin_record
|
91
|
+
logger_.set_attribute('user', 'bill')
|
92
|
+
logger_.set_attribute('location', 'tacoma')
|
93
|
+
logger_.end_record
|
94
|
+
assert_equal("daniel: 2\nseattle: 1", logger_.close)
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sawmill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-01 01:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -45,21 +45,28 @@ files:
|
|
45
45
|
- lib/sawmill/entry.rb
|
46
46
|
- lib/sawmill/entry_classifier.rb
|
47
47
|
- lib/sawmill/entry_processor/build_records.rb
|
48
|
+
- lib/sawmill/entry_processor/compile_report.rb
|
48
49
|
- lib/sawmill/entry_processor/conditionals.rb
|
49
|
-
- lib/sawmill/entry_processor/
|
50
|
+
- lib/sawmill/entry_processor/count_entries.rb
|
51
|
+
- lib/sawmill/entry_processor/filter_by_basic_fields.rb
|
52
|
+
- lib/sawmill/entry_processor/filter_by_block.rb
|
50
53
|
- lib/sawmill/entry_processor/format.rb
|
51
54
|
- lib/sawmill/entry_processor/simple_queue.rb
|
52
55
|
- lib/sawmill/entry_processor.rb
|
53
56
|
- lib/sawmill/errors.rb
|
57
|
+
- lib/sawmill/interface.rb
|
54
58
|
- lib/sawmill/level.rb
|
55
59
|
- lib/sawmill/log_record_middleware.rb
|
56
60
|
- lib/sawmill/logger.rb
|
57
61
|
- lib/sawmill/multi_parser.rb
|
58
62
|
- lib/sawmill/parser.rb
|
59
63
|
- lib/sawmill/record.rb
|
64
|
+
- lib/sawmill/record_processor/compile_report.rb
|
60
65
|
- lib/sawmill/record_processor/conditionals.rb
|
66
|
+
- lib/sawmill/record_processor/count_records.rb
|
61
67
|
- lib/sawmill/record_processor/decompose.rb
|
62
68
|
- lib/sawmill/record_processor/filter_by_attributes.rb
|
69
|
+
- lib/sawmill/record_processor/filter_by_block.rb
|
63
70
|
- lib/sawmill/record_processor/filter_by_record_id.rb
|
64
71
|
- lib/sawmill/record_processor/format.rb
|
65
72
|
- lib/sawmill/record_processor/simple_queue.rb
|
@@ -69,6 +76,7 @@ files:
|
|
69
76
|
- lib/sawmill/rotater/shifting_log_file.rb
|
70
77
|
- lib/sawmill/rotater.rb
|
71
78
|
- lib/sawmill/util/heap.rb
|
79
|
+
- lib/sawmill/util/processor_tools.rb
|
72
80
|
- lib/sawmill/util/queue.rb
|
73
81
|
- lib/sawmill/version.rb
|
74
82
|
- lib/sawmill.rb
|
@@ -79,6 +87,7 @@ files:
|
|
79
87
|
- tests/tc_multi_parser.rb
|
80
88
|
- tests/tc_record_processors.rb
|
81
89
|
- tests/tc_records.rb
|
90
|
+
- tests/tc_reports.rb
|
82
91
|
- History.rdoc
|
83
92
|
- README.rdoc
|
84
93
|
- Rakefile
|
@@ -118,3 +127,4 @@ test_files:
|
|
118
127
|
- tests/tc_multi_parser.rb
|
119
128
|
- tests/tc_record_processors.rb
|
120
129
|
- tests/tc_records.rb
|
130
|
+
- tests/tc_reports.rb
|