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 +1 -1
- data/TODO.markdown +72 -0
- data/examples/changing_format.rb +1 -3
- data/examples/examples_helper.rb +5 -0
- data/examples/one_log_per_classes.rb +1 -3
- data/examples/one_tag_per_classes.rb +1 -3
- data/examples/per_class_customization.rb +1 -3
- data/examples/rule_with_regex.rb +1 -3
- data/examples/simplest_usage.rb +1 -3
- data/lib/tagged_logger/tagged_logger.rb +5 -0
- data/test/test.rb +1 -3
- data/test/test_examples.rb +1 -0
- data/test/test_helper.rb +7 -4
- data/test/test_performance.rb +9 -8
- data/test/test_rails.rb +1 -2
- metadata +6 -4
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
|
|
data/TODO.markdown
ADDED
@@ -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
|
data/examples/changing_format.rb
CHANGED
data/examples/rule_with_regex.rb
CHANGED
data/examples/simplest_usage.rb
CHANGED
@@ -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
|
data/test/test.rb
CHANGED
data/test/test_examples.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
|
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
|
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
|
-
|
11
|
+
|
data/test/test_performance.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require File.dirname(__FILE__) + '/../tagged_logger'
|
3
|
-
require 'logger'
|
1
|
+
require File.join(File.dirname(__FILE__), '/test_helper')
|
4
2
|
|
5
|
-
class
|
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
|
-
|
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(
|
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)
|
data/test/test_rails.rb
CHANGED
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
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-
|
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
|