tagged_logger 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << "test"
6
- t.test_files = FileList['test/test.rb', 'test/test_rails.rb', 'test/test_examples.rb']
6
+ t.test_files = FileList['test/test.rb', 'test/test_rails.rb', 'test/test_examples.rb', 'test/test_performance.rb']
7
7
  t.verbose = true
8
8
  end
9
9
 
@@ -0,0 +1,72 @@
1
+ ### The *level* param in rule below appears to be obsolete:
2
+
3
+ debug /something/ do |level, tag, msg|
4
+ end
5
+
6
+ We specify *debug* rule, so what the need to pass it as a param? May be:
7
+
8
+ any_level /something/ do |level, tag, msg|
9
+ end
10
+
11
+ and
12
+
13
+ debug /something/ do |tag, msg|
14
+ end
15
+
16
+
17
+
18
+ ### Integration with Rails instrumenation, may be somewhat like:
19
+
20
+ debug 'sql.active_record' do |msg| do
21
+ # custom handling for Rails 'sql.active_record' instrumentation
22
+ end
23
+
24
+ ### Documentation
25
+
26
+ ### Ability to accept blocks as arguments for #debug, #info, and alike, i.e.:
27
+
28
+ logger.info { "That message takes some time to build' }
29
+
30
+ so message is evaluated only when actual logging happens, and no-op otherwise
31
+
32
+
33
+ ### Writing messages in any encoding (tests)
34
+
35
+ ### Tests against 'logging' framework: http://github.com/TwP/logging
36
+
37
+ ### When logger specified in :to => ... then lib must complain if it cannot find standard logger methods there (and formatting setter)
38
+
39
+ ### :fsync convenience option, so instead:
40
+
41
+ log = open(File.join(log_path, 'log.log'),"w")
42
+ debug GData::Cacher, :to => Logger.new(log) do
43
+ log.fsync
44
+ end
45
+
46
+ one could write:
47
+
48
+ debug GData::Cacher, :to => Logger.new('log.log'), :fsync => true
49
+
50
+ ### Non-intrusive instrumentation, for example:
51
+
52
+ instrument "SomeClass#method", :debug
53
+
54
+ which in turn wraps *SomeClass#method* with before call:
55
+
56
+ logger.debug("SomeClass#method/started [timestamp]")
57
+
58
+ and after call:
59
+
60
+ logger.debug("SomeClass#method/stopped [timestamp]")
61
+
62
+ so instrumentation is defined just as a special case for logging and
63
+ it is regulated by same rules mechanism, i.e. it could be turned on by rule:
64
+
65
+ debugger SomeClass do |level, info, msg| do
66
+ end
67
+
68
+ sometimes we want to know an average information across many method call, so may be:
69
+
70
+ instrument "SomeClass#method", :debug, :average_for => 100
71
+
72
+ It is needed for better profiling
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
- require 'tagged_logger'
3
- require 'logger'
1
+ require File.join(File.dirname(__FILE__), '/examples_helper')
4
2
 
5
3
  puts "\n<<<#{File.basename(__FILE__, ".rb")}>>> \n".upcase
6
4
 
@@ -0,0 +1,5 @@
1
+ dir = File.dirname(__FILE__) + '/../lib'
2
+ $LOAD_PATH.unshift dir unless $LOAD_PATH.include? dir
3
+ require 'rubygems'
4
+ require 'tagged_logger'
5
+ require 'logger'
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
- require 'tagged_logger'
3
- require 'logger'
1
+ require File.join(File.dirname(__FILE__), '/examples_helper')
4
2
 
5
3
  puts "\n<<<#{File.basename(__FILE__, ".rb")}>>> \n".upcase
6
4
 
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
- require 'tagged_logger'
3
- require 'logger'
1
+ require File.join(File.dirname(__FILE__), '/examples_helper')
4
2
 
5
3
  puts "\n<<<#{File.basename(__FILE__, ".rb")}>>> \n".upcase
6
4
 
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
- require 'tagged_logger'
3
- require 'logger'
1
+ require File.join(File.dirname(__FILE__), '/examples_helper')
4
2
 
5
3
  puts "\n<<<#{File.basename(__FILE__, ".rb")}>>> \n".upcase
6
4
 
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
- require 'tagged_logger'
3
- require 'logger'
1
+ require File.join(File.dirname(__FILE__), '/examples_helper')
4
2
 
5
3
  puts "\n<<<#{File.basename(__FILE__, ".rb")}>>> \n".upcase
6
4
 
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
- require 'tagged_logger'
3
- require 'logger'
1
+ require File.join(File.dirname(__FILE__), '/examples_helper')
4
2
 
5
3
  puts "\n<<<#{File.basename(__FILE__, ".rb")}>>> \n".upcase
6
4
 
@@ -57,6 +57,11 @@ module TaggedLogger
57
57
  def warn(what, where = {}, &block) output(:warn, what, where, &block) end
58
58
  def error(what, where = {}, &block) output(:error, what, where, &block) end
59
59
  def fatal(what, where = {}, &block) output(:fatal, what, where, &block) end
60
+ def any_level(what, where = {}, &block)
61
+ [:debug, :info, :warn, :error, :fatal].each do |level|
62
+ output(level, what, where, &block)
63
+ end
64
+ end
60
65
 
61
66
  def format(&block)
62
67
  @formatter = block
@@ -1,6 +1,4 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'test_helper'
3
-
1
+ require File.join(File.dirname(__FILE__), '/test_helper')
4
2
 
5
3
  class TaggedLoggerTest < Test::Unit::TestCase
6
4
  include RR::Adapters::TestUnit
@@ -1,3 +1,4 @@
1
+
1
2
  root_dir = File.dirname(File.expand_path(__FILE__)) + '/../'
2
3
  examples_output = `find -s #{root_dir}examples -iname '*.rb' -exec ruby {} \\;`
3
4
  expected_output = File.read("#{root_dir}test/expected_examples_output.txt")
@@ -1,8 +1,11 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../'
1
+ lib_dir = File.dirname(__FILE__) + '/../lib'
2
+ $LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include? lib_dir
3
+
2
4
  require 'rubygems'
3
- require 'tagged_logger'
5
+ require "#{lib_dir}/tagged_logger"
6
+ require "#{lib_dir}/../test/test_log_device"
7
+ require 'logger'
4
8
  require 'test/unit'
5
9
  require 'shoulda'
6
- require 'logger'
7
10
  require 'rr'
8
- require 'test_log_device'
11
+
@@ -1,8 +1,6 @@
1
- require 'rubygems'
2
- require File.dirname(__FILE__) + '/../tagged_logger'
3
- require 'logger'
1
+ require File.join(File.dirname(__FILE__), '/test_helper')
4
2
 
5
- class TestLogDevice
3
+ class DummyTestLogDevice
6
4
  def write(msg); end
7
5
  def close; end
8
6
  def clear; end
@@ -11,15 +9,18 @@ end
11
9
  def measure_debug_time(a_logger, name)
12
10
  start_time = Time.now
13
11
  10_000.times { a_logger.debug("DEBUG")}
14
- puts "DEBUG: %s: %5.4f\n" % [name, (Time.now - start_time)]
12
+ diff = Time.now - start_time
13
+ puts "Performance(10,000 logger.debug calls) for %s: %5.4f sec\n" % [name, diff]
14
+ diff
15
15
  end
16
16
 
17
- std_logger = Logger.new(TestLogDevice.new)
17
+ std_logger = Logger.new(DummyTestLogDevice.new)
18
18
  std_logger.level = Logger::INFO
19
19
 
20
20
  TaggedLogger.rules do
21
21
  info /.*/, :to => std_logger
22
22
  end
23
23
 
24
- measure_debug_time(std_logger, "Standard Logger")
25
- measure_debug_time(logger, "Tagged Logger")
24
+ std_logger_time = measure_debug_time(std_logger, "Standard Logger")
25
+ tagged_logger_time = measure_debug_time(logger, "Tagged Logger")
26
+ puts "Tagger/Standard Logger speed = %2.2f" % (tagged_logger_time/std_logger_time)
@@ -1,5 +1,4 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__)
2
- require 'test_helper'
1
+ require File.join(File.dirname(__FILE__), '/test_helper')
3
2
  require 'rails/all'
4
3
 
5
4
  module Test
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tagged_logger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aleksandr Furmanov
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-21 00:00:00 -05:00
18
+ date: 2010-10-23 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -90,6 +90,7 @@ files:
90
90
  - MIT-LICENSE
91
91
  - Rakefile
92
92
  - README.markdown
93
+ - TODO.markdown
93
94
  - lib/tagged_logger/railtie.rb
94
95
  - lib/tagged_logger/tagged_logger.rb
95
96
  - lib/tagged_logger.rb
@@ -101,6 +102,7 @@ files:
101
102
  - test/test_performance.rb
102
103
  - test/test_rails.rb
103
104
  - examples/changing_format.rb
105
+ - examples/examples_helper.rb
104
106
  - examples/one_log_per_classes.rb
105
107
  - examples/one_tag_per_classes.rb
106
108
  - examples/per_class_customization.rb