tagged_logger 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
data/lib/tagged_logger.rb CHANGED
@@ -34,7 +34,7 @@ class TaggedLogger
34
34
 
35
35
  def debug(what, where = {}, &block) output(:debug, what, where, &block) end
36
36
  def info(what, where = {}, &block) output(:info, what, where, &block) end
37
- def warn(what, where = {}, &block) output(:wanr, what, where, &block) end
37
+ def warn(what, where = {}, &block) output(:warn, what, where, &block) end
38
38
  def error(what, where = {}, &block) output(:error, what, where, &block) end
39
39
  def fatal(what, where = {}, &block) output(:fatal, what, where, &block) end
40
40
 
@@ -88,16 +88,18 @@ class TaggedLogger
88
88
 
89
89
  def self.match?(spec, tag)
90
90
  t = tag.to_s
91
- case spec
92
- when Regexp
93
- t =~ spec
94
- when Class
95
- t == spec.name
96
- when Array
97
- spec.any? {|s| match?(s, tag)}
98
- else
99
- spec.to_s == t
100
- end
91
+ result = case spec
92
+ when Regexp
93
+ t =~ spec
94
+ when Class
95
+ t == spec.name
96
+ when Array
97
+ spec.any? {|s| match?(s, tag)}
98
+ else
99
+ spec.to_s == t
100
+ end
101
+ return result if result
102
+ self.match?(spec, tag.superclass) if tag.class == Class && tag.superclass != Class
101
103
  end
102
104
  end #TagMatcher
103
105
 
@@ -142,7 +144,7 @@ class TaggedLogger
142
144
  def initialize(klass)
143
145
  @klass = klass
144
146
  [:debug, :warn, :info, :error, :fatal].each do |level|
145
- blocks = TaggedLogger.blocks_for(level, klass.to_s)
147
+ blocks = TaggedLogger.blocks_for(level, klass)
146
148
  eigenclass.send(:define_method, level) do |msg|
147
149
  blocks.each { |(tag_alias, block)| block.call(level, tag_alias, msg) }
148
150
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tagged_logger}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Fedor Kocherga"]
12
- s.date = %q{2010-01-16}
12
+ s.date = %q{2010-03-30}
13
13
  s.email = %q{fkocherga@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.html",
@@ -34,12 +34,13 @@ Gem::Specification.new do |s|
34
34
  "test/expected_examples_output.txt",
35
35
  "test/test.rb",
36
36
  "test/test_examples.rb",
37
+ "test/test_performance.rb",
37
38
  "todo.txt"
38
39
  ]
39
40
  s.homepage = %q{http://github.com/fkocherga/tagged_logger}
40
41
  s.rdoc_options = ["--charset=UTF-8"]
41
42
  s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.5}
43
+ s.rubygems_version = %q{1.3.6}
43
44
  s.summary = %q{Detaches _what_ is logged from _how_ it is logged.}
44
45
  s.test_files = [
45
46
  "test/test.rb",
data/test/test.rb CHANGED
@@ -79,7 +79,16 @@ class TaggedLoggerTest < Test::Unit::TestCase
79
79
  @b.foo
80
80
  end
81
81
 
82
- context "@logger2 with stub output @@stub_out_aux;" do
82
+ should "use default tag equal to class name for class methods" do
83
+ def A.bar
84
+ logger.info "bar"
85
+ end
86
+ mock(@@stub_out).write("#{self.class}::A: bar")
87
+ A.bar
88
+ end
89
+
90
+
91
+ context "@logger2 with stub output @@stub_out_aux;" do
83
92
  setup { @@stub_out_aux = TestLogDevice.new }
84
93
 
85
94
  should "be possible to add logging to @@stub_out_aux for A" do
@@ -92,6 +101,20 @@ class TaggedLoggerTest < Test::Unit::TestCase
92
101
  @b.foo
93
102
  end
94
103
 
104
+ should "do logging in subclasses if superclass match the rules" do
105
+ TaggedLogger.rules { debug A, :to => Logger.new(@@stub_out_aux) }
106
+ class C < A; include Foo; end
107
+ mock(@@stub_out_aux).write("#{self.class}::C: foo")
108
+ C.new.foo
109
+ end
110
+
111
+ should "do logging in superclass if being called from subclass" do
112
+ TaggedLogger.rules { debug A, :to => Logger.new(@@stub_out_aux) }
113
+ class C < A; end
114
+ mock(@@stub_out_aux).write("#{self.class}::C: foo")
115
+ C.new.foo
116
+ end
117
+
95
118
  should "be possible to speialize logging for tag A by providing block" do
96
119
  TaggedLogger.rules do
97
120
  debug A do |level, tag, msg|
@@ -128,14 +151,6 @@ class TaggedLoggerTest < Test::Unit::TestCase
128
151
  @b.foo
129
152
  end
130
153
 
131
- should "use default tag equal to class name for class methods" do
132
- def A.bar
133
- logger.info "bar"
134
- end
135
- mock(@@stub_out).write("#{self.class}::A: bar")
136
- A.bar
137
- end
138
-
139
154
  context "class A and class B with logger.debug() in their method #bar;" do
140
155
  setup do
141
156
  module Bar; def bar; logger.debug("bar"); end; end
@@ -151,7 +166,7 @@ class TaggedLoggerTest < Test::Unit::TestCase
151
166
  @a.bar
152
167
  end
153
168
  end
154
- end
169
+ end
155
170
 
156
171
  end
157
172
  end
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../tagged_logger'
3
+ require 'logger'
4
+
5
+ class TestLogDevice
6
+ def write(msg); end
7
+ def close; end
8
+ def clear; end
9
+ end
10
+
11
+ def measure_debug_time(a_logger, name)
12
+ start_time = Time.now
13
+ 10_000.times { a_logger.debug("DEBUG")}
14
+ puts "DEBUG: %s: %5.4f\n" % [name, (Time.now - start_time)]
15
+ end
16
+
17
+ std_logger = Logger.new(TestLogDevice.new)
18
+ std_logger.level = Logger::INFO
19
+
20
+ TaggedLogger.rules do
21
+ info /.*/, :to => std_logger
22
+ end
23
+
24
+ measure_debug_time(std_logger, "Standard Logger")
25
+ measure_debug_time(logger, "Tagged Logger")
data/todo.txt CHANGED
@@ -1,7 +1,34 @@
1
+ * figure out how profiling info could be displayed on New Relic
2
+ May be:
3
+
4
+ instrument object, :method
5
+
6
+ monkey patchs method with
7
+
8
+ logger.debug("MethodName()/started")
9
+ ...
10
+ logger.debug("MethodName()/stopped")
11
+
12
+
13
+ create special logger for instrumentation:
14
+ StatisticsLogger
15
+
16
+ so somebody may write:
17
+
18
+ instrument object, :method, :to => StatisticsLogger.new( file, :interval => 100 )
19
+ #may be not a file, but mongodb connection
20
+
21
+ instrument object, :method, :to => NewRelicLogger.new
22
+
23
+ The StatisticsLogger is for monitoring/troubleshouting, it supposed to help answer questions like:
24
+ - how my app behaves in average
25
+
26
+ The NewRelicLogger simply redirects all sampling to newrelic_rpm
27
+
1
28
  - logger.debug method (and alike) should accept block for performance reason
2
- - logger called within Base does not log when Derived is instantiated
3
29
  - writing messages in any encoding
4
30
  - test against 'logging' framework
5
- - test agains 1.8.6 and 1.9.1
31
+ - test agains 1.9.1
32
+ - test agains 1.8.6 (really?)
6
33
  - test with Rails
7
34
  - when logger specified in :to => ... then lib must complain unless formatting and logging code to that specific logger class was not defined
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagged_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 1
9
+ version: 0.3.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Fedor Kocherga
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-16 00:00:00 -06:00
17
+ date: 2010-03-30 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -41,6 +46,7 @@ files:
41
46
  - test/expected_examples_output.txt
42
47
  - test/test.rb
43
48
  - test/test_examples.rb
49
+ - test/test_performance.rb
44
50
  - todo.txt
45
51
  - README.html
46
52
  has_rdoc: true
@@ -56,18 +62,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
62
  requirements:
57
63
  - - ">="
58
64
  - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
59
67
  version: "0"
60
- version:
61
68
  required_rubygems_version: !ruby/object:Gem::Requirement
62
69
  requirements:
63
70
  - - ">="
64
71
  - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
65
74
  version: "0"
66
- version:
67
75
  requirements: []
68
76
 
69
77
  rubyforge_project:
70
- rubygems_version: 1.3.5
78
+ rubygems_version: 1.3.6
71
79
  signing_key:
72
80
  specification_version: 3
73
81
  summary: Detaches _what_ is logged from _how_ it is logged.