sawmill 0.1.15 → 0.1.16

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.
Files changed (53) hide show
  1. data/History.rdoc +7 -0
  2. data/Version +1 -1
  3. data/lib/sawmill.rb +6 -6
  4. data/lib/sawmill/entry.rb +108 -108
  5. data/lib/sawmill/entry_classifier.rb +19 -19
  6. data/lib/sawmill/entry_processor.rb +63 -63
  7. data/lib/sawmill/entry_processor/build_records.rb +39 -39
  8. data/lib/sawmill/entry_processor/compile_report.rb +32 -32
  9. data/lib/sawmill/entry_processor/conditionals.rb +110 -110
  10. data/lib/sawmill/entry_processor/count_entries.rb +27 -27
  11. data/lib/sawmill/entry_processor/filter_by_basic_fields.rb +32 -32
  12. data/lib/sawmill/entry_processor/filter_by_block.rb +28 -28
  13. data/lib/sawmill/entry_processor/format.rb +41 -36
  14. data/lib/sawmill/entry_processor/interpret_stats.rb +24 -24
  15. data/lib/sawmill/entry_processor/simple_queue.rb +38 -38
  16. data/lib/sawmill/errors.rb +28 -28
  17. data/lib/sawmill/interface.rb +51 -51
  18. data/lib/sawmill/level.rb +75 -75
  19. data/lib/sawmill/log_record_middleware.rb +21 -21
  20. data/lib/sawmill/logger.rb +94 -94
  21. data/lib/sawmill/multi_parser.rb +28 -28
  22. data/lib/sawmill/parser.rb +32 -32
  23. data/lib/sawmill/railtie.rb +31 -31
  24. data/lib/sawmill/record.rb +74 -74
  25. data/lib/sawmill/record_processor.rb +54 -54
  26. data/lib/sawmill/record_processor/compile_report.rb +32 -32
  27. data/lib/sawmill/record_processor/conditionals.rb +92 -92
  28. data/lib/sawmill/record_processor/count_records.rb +24 -24
  29. data/lib/sawmill/record_processor/decompose.rb +21 -21
  30. data/lib/sawmill/record_processor/filter_by_attributes.rb +22 -22
  31. data/lib/sawmill/record_processor/filter_by_block.rb +29 -29
  32. data/lib/sawmill/record_processor/filter_by_record_id.rb +22 -22
  33. data/lib/sawmill/record_processor/format.rb +24 -24
  34. data/lib/sawmill/record_processor/simple_queue.rb +44 -44
  35. data/lib/sawmill/rotater.rb +60 -60
  36. data/lib/sawmill/rotater/base.rb +28 -28
  37. data/lib/sawmill/rotater/date_based_log_file.rb +50 -50
  38. data/lib/sawmill/rotater/shifting_log_file.rb +34 -34
  39. data/lib/sawmill/stats_middleware.rb +21 -21
  40. data/lib/sawmill/stats_railtie.rb +33 -33
  41. data/lib/sawmill/util/heap.rb +41 -41
  42. data/lib/sawmill/util/processor_tools.rb +17 -17
  43. data/lib/sawmill/util/queue.rb +33 -33
  44. data/lib/sawmill/version.rb +9 -9
  45. data/test/tc_entry_processors.rb +27 -27
  46. data/test/tc_formatter_parser.rb +40 -40
  47. data/test/tc_levels.rb +27 -27
  48. data/test/tc_logger.rb +49 -49
  49. data/test/tc_multi_parser.rb +18 -18
  50. data/test/tc_record_processors.rb +21 -21
  51. data/test/tc_records.rb +39 -39
  52. data/test/tc_reports.rb +19 -19
  53. metadata +10 -5
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill queue utility
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,17 +35,17 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module Util
40
-
41
-
40
+
41
+
42
42
  # A simple queue that optionally provides an upper size limit.
43
-
43
+
44
44
  class Queue
45
-
46
-
45
+
46
+
47
47
  # Recognized options include:
48
- #
48
+ #
49
49
  # [<tt>:limit</tt>]
50
50
  # Size limit for the queue. If not specified, the queue can grow
51
51
  # arbitrarily large.
@@ -53,7 +53,7 @@ module Sawmill
53
53
  # If set to true, then when an item is added to a full queue, the
54
54
  # oldest item is dropped. If set to false or not specified, then
55
55
  # the new item is not added.
56
-
56
+
57
57
  def initialize(opts_={})
58
58
  limit_ = opts_[:limit]
59
59
  @buffer = limit_ ? ::Array.new(limit_) : []
@@ -61,16 +61,16 @@ module Sawmill
61
61
  @pop_ptr = nil
62
62
  @drop_oldest = limit_ && opts_[:drop_oldest]
63
63
  end
64
-
65
-
64
+
65
+
66
66
  # Attempt to push an item on the queue.
67
- #
67
+ #
68
68
  # If the queue is full, then the behavior is determined by the
69
69
  # :drop_oldest setting provided to the constructor.
70
- #
70
+ #
71
71
  # Returns true if the object was pushed on the queue, or false if the
72
72
  # queue was full.
73
-
73
+
74
74
  def enqueue(object_)
75
75
  result_ = true
76
76
  if @push_ptr
@@ -93,10 +93,10 @@ module Sawmill
93
93
  end
94
94
  result_
95
95
  end
96
-
97
-
96
+
97
+
98
98
  # Return the oldest item in the queue, or nil if the queue is empty.
99
-
99
+
100
100
  def dequeue
101
101
  if @push_ptr
102
102
  if @pop_ptr
@@ -113,10 +113,10 @@ module Sawmill
113
113
  @buffer.shift
114
114
  end
115
115
  end
116
-
117
-
116
+
117
+
118
118
  # Return an array of the contents of the queue, in order.
119
-
119
+
120
120
  def dequeue_all
121
121
  if @push_ptr
122
122
  if @pop_ptr
@@ -138,10 +138,10 @@ module Sawmill
138
138
  ret_
139
139
  end
140
140
  end
141
-
142
-
141
+
142
+
143
143
  # Return the size of the queue, which is 0 if the queue is empty.
144
-
144
+
145
145
  def size
146
146
  if @push_ptr
147
147
  if @pop_ptr
@@ -154,11 +154,11 @@ module Sawmill
154
154
  @buffer.size
155
155
  end
156
156
  end
157
-
158
-
157
+
158
+
159
159
  end
160
-
161
-
160
+
161
+
162
162
  end
163
-
163
+
164
164
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill version
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,12 +41,12 @@ end
41
41
 
42
42
 
43
43
  module Sawmill
44
-
44
+
45
45
  # Current gem version, as a frozen string.
46
46
  VERSION_STRING = ::File.read(::File.dirname(__FILE__)+'/../../Version').strip.freeze
47
-
47
+
48
48
  # Current gem version, as a Versionomy::Value if the versionomy library
49
49
  # is available, or as a frozen string if not.
50
50
  VERSION = defined?(::Versionomy) ? ::Versionomy.parse(VERSION_STRING, :standard) : VERSION_STRING
51
-
51
+
52
52
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill: tests on entry processors
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -40,18 +40,18 @@ require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/sawmill.rb")
40
40
 
41
41
  module Sawmill
42
42
  module Tests # :nodoc:
43
-
43
+
44
44
  class TestEntryProcessors < ::Test::Unit::TestCase # :nodoc:
45
-
46
-
45
+
46
+
47
47
  def setup
48
48
  @entries = ::Sawmill::EntryProcessor::SimpleQueue.new
49
49
  @levels = ::Sawmill::STANDARD_LEVELS
50
50
  end
51
-
52
-
51
+
52
+
53
53
  # Test a basic filter that checks the level
54
-
54
+
55
55
  def test_basic_level_filter
56
56
  processor_ = ::Sawmill::EntryProcessor::build do
57
57
  If(FilterByBasicFields(:level => :WARN), @entries)
@@ -64,10 +64,10 @@ module Sawmill
64
64
  assert_equal('Hello 3', @entries.dequeue.message)
65
65
  assert_equal(0, @entries.size)
66
66
  end
67
-
68
-
67
+
68
+
69
69
  # Test a basic filter that checks the progname
70
-
70
+
71
71
  def test_basic_progname_filter
72
72
  processor_ = ::Sawmill::EntryProcessor::build do
73
73
  If(FilterByBasicFields(:progname => 'rails'), @entries)
@@ -79,10 +79,10 @@ module Sawmill
79
79
  assert_equal('Hello 2', @entries.dequeue.message)
80
80
  assert_equal(0, @entries.size)
81
81
  end
82
-
83
-
82
+
83
+
84
84
  # Test an "AND" filter
85
-
85
+
86
86
  def test_conjunction_and
87
87
  processor_ = ::Sawmill::EntryProcessor::build do
88
88
  If(And(FilterByBasicFields(:progname => 'rails'),
@@ -96,10 +96,10 @@ module Sawmill
96
96
  assert_equal('Hello 2', @entries.dequeue.message)
97
97
  assert_equal(0, @entries.size)
98
98
  end
99
-
100
-
99
+
100
+
101
101
  # Test an "OR" filter
102
-
102
+
103
103
  def test_conjunction_or
104
104
  processor_ = ::Sawmill::EntryProcessor::build do
105
105
  If(Or(FilterByBasicFields(:progname => 'rails'),
@@ -115,10 +115,10 @@ module Sawmill
115
115
  assert_equal('Hello 3', @entries.dequeue.message)
116
116
  assert_equal(0, @entries.size)
117
117
  end
118
-
119
-
118
+
119
+
120
120
  # Test a "NOT" filter
121
-
121
+
122
122
  def test_boolean_not
123
123
  processor_ = ::Sawmill::EntryProcessor::build do
124
124
  If(Not(FilterByBasicFields(:progname => 'rails')), @entries)
@@ -131,9 +131,9 @@ module Sawmill
131
131
  assert_equal('Hello 3', @entries.dequeue.message)
132
132
  assert_equal(0, @entries.size)
133
133
  end
134
-
135
-
134
+
135
+
136
136
  end
137
-
137
+
138
138
  end
139
139
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill: tests log file formatting and parsing
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -41,16 +41,16 @@ require ::File.expand_path("#{::File.dirname(__FILE__)}/../lib/sawmill.rb")
41
41
 
42
42
  module Sawmill
43
43
  module Tests # :nodoc:
44
-
44
+
45
45
  class TestFormatterParser < ::Test::Unit::TestCase # :nodoc:
46
-
47
-
46
+
47
+
48
48
  def setup
49
49
  @entries = []
50
50
  @levels = ::Sawmill::STANDARD_LEVELS
51
51
  end
52
-
53
-
52
+
53
+
54
54
  def _run_test(expected_, opts_={})
55
55
  stringio_ = ::StringIO.new
56
56
  formatter_ = ::Sawmill::EntryClassifier.new(::Sawmill::Formatter.new(stringio_, opts_))
@@ -61,58 +61,58 @@ module Sawmill
61
61
  assert_equal(expected_, formatted_string_)
62
62
  stringio_ = ::StringIO.new(formatted_string_)
63
63
  parser_ = ::Sawmill::Parser.new(stringio_, nil)
64
- @entries.each do |expected_|
65
- assert_equal(expected_, parser_.parse_one_entry)
64
+ @entries.each do |entry_|
65
+ assert_equal(entry_, parser_.parse_one_entry)
66
66
  end
67
67
  end
68
-
69
-
68
+
69
+
70
70
  # Test message entry
71
-
71
+
72
72
  def test_basic_message
73
73
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 120000), 'rails', nil, 'Hello')
74
74
  _run_test("[INFO 2009-10-20 08:30:45.12 rails .] Hello\n")
75
75
  end
76
-
77
-
76
+
77
+
78
78
  # Test message with no fractional seconds
79
-
79
+
80
80
  def test_message_with_whole_seconds
81
81
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 0), 'rails', nil, 'Hello')
82
82
  _run_test("[INFO 2009-10-20 08:30:45.00 rails .] Hello\n")
83
83
  end
84
-
85
-
84
+
85
+
86
86
  # Test multiple message entry
87
-
87
+
88
88
  def test_multiple_messages
89
89
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 120000), 'rails', nil, 'Hello')
90
90
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:ERROR), Time.utc(2009, 10, 20, 8, 30, 46, 980000), 'rails', nil, 'Something bad happened!')
91
91
  _run_test("[INFO 2009-10-20 08:30:45.12 rails .] Hello\n[ERROR 2009-10-20 08:30:46.98 rails .] Something bad happened!\n")
92
92
  end
93
-
94
-
93
+
94
+
95
95
  # Test multi-line message entries
96
-
96
+
97
97
  def test_multi_line_messages
98
98
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 120000), 'rails', nil, "Multiple\nLines\n")
99
99
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:ERROR), Time.utc(2009, 10, 20, 8, 30, 46, 980000), 'rails', nil, "Multiple Lines\\\nwith trailing backslashes\\\\\n")
100
100
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:ERROR), Time.utc(2009, 10, 20, 8, 30, 47, 0), 'rails', nil, "More trailing\\\nbackslashes\\\\")
101
101
  _run_test("[INFO 2009-10-20 08:30:45.12 rails .] Multiple\\\nLines\\\n\n[ERROR 2009-10-20 08:30:46.98 rails .] Multiple Lines\\\\\\\nwith trailing backslashes\\\\\\\\\\\n\n[ERROR 2009-10-20 08:30:47.00 rails .] More trailing\\\\\\\nbackslashes\\\\\\\\\n")
102
102
  end
103
-
104
-
103
+
104
+
105
105
  # Test record delimiter entries
106
-
106
+
107
107
  def test_record_delimiters
108
108
  @entries << ::Sawmill::Entry::BeginRecord.new(@levels.get(:ANY), Time.utc(2009, 10, 20, 8, 30, 45, 120000), 'rails', 'abcdefg')
109
109
  @entries << ::Sawmill::Entry::EndRecord.new(@levels.get(:ANY), Time.utc(2009, 10, 20, 8, 30, 46, 980000), 'rails', 'abcdefg')
110
110
  _run_test("[ANY 2009-10-20 08:30:45.12 rails ^] BEGIN abcdefg\n[ANY 2009-10-20 08:30:46.98 rails $] END abcdefg\n")
111
111
  end
112
-
113
-
112
+
113
+
114
114
  # Test attribute entries
115
-
115
+
116
116
  def test_attributes
117
117
  @entries << ::Sawmill::Entry::BeginRecord.new(@levels.get(:ANY), Time.utc(2009, 10, 20, 8, 30, 45, 110000), 'rails', 'abcdefg')
118
118
  @entries << ::Sawmill::Entry::Attribute.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 120000), 'rails', 'abcdefg', 'SIZE', 'small')
@@ -120,26 +120,26 @@ module Sawmill
120
120
  @entries << ::Sawmill::Entry::EndRecord.new(@levels.get(:ANY), Time.utc(2009, 10, 20, 8, 30, 46, 990000), 'rails', 'abcdefg')
121
121
  _run_test("[ANY 2009-10-20 08:30:45.11 rails ^] BEGIN abcdefg\n[INFO 2009-10-20 08:30:45.12 rails =] SIZE = small\n[INFO 2009-10-20 08:30:46.98 rails =] COLOR + red\\\nand\\\nblue\n[ANY 2009-10-20 08:30:46.99 rails $] END abcdefg\n")
122
122
  end
123
-
124
-
123
+
124
+
125
125
  # Test message with include_id
126
-
126
+
127
127
  def test_message_with_include_id
128
128
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 0), 'rails', 'abcdefg', 'Hello 1')
129
129
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 100000), 'rails', nil, 'Hello 2')
130
130
  _run_test("[INFO 2009-10-20 08:30:45.00 rails abcdefg .] Hello 1\n[INFO 2009-10-20 08:30:45.10 rails .] Hello 2\n", :include_id => true)
131
131
  end
132
-
133
-
132
+
133
+
134
134
  # Test message where fractional seconds are turned off
135
-
135
+
136
136
  def test_message_without_fractional_seconds
137
137
  @entries << ::Sawmill::Entry::Message.new(@levels.get(:INFO), Time.utc(2009, 10, 20, 8, 30, 45, 0), 'rails', nil, 'Hello 1')
138
138
  _run_test("[INFO 2009-10-20 08:30:45 rails .] Hello 1\n", :fractional_second_digits => 0)
139
139
  end
140
-
141
-
140
+
141
+
142
142
  end
143
-
143
+
144
144
  end
145
145
  end