Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/asir/log.rb | 80 | 65 | 41.25%
|
27.69%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 module ASIR |
2 # !SLIDE |
3 # Diagnostic Logging |
4 # |
5 # Logging mixin. |
6 module Log |
7 attr_accessor :_logger |
8 |
9 def self.included target |
10 super |
11 target.send(:extend, ClassMethods) |
12 end |
13 |
14 @@enabled = false |
15 def self.enabled |
16 @@enabled |
17 end |
18 def self.enabled= x |
19 @@enabled = x |
20 end |
21 |
22 module ClassMethods |
23 def _log_enabled= x |
24 (Thread.current[:'ASIR::Log.enabled'] ||= { })[self] = x |
25 end |
26 def _log_enabled? |
27 (Thread.current[:'ASIR::Log.enabled'] ||= { })[self] |
28 end |
29 end |
30 |
31 def _log_enabled= x |
32 @_log_enabled = x |
33 end |
34 |
35 def _log_enabled? |
36 ASIR::Log.enabled || |
37 @_log_enabled || |
38 self.class._log_enabled? |
39 end |
40 |
41 def _log msg = nil |
42 return unless _log_enabled? |
43 msg ||= yield if block_given? |
44 msg = String === msg ? msg : _log_format(msg) |
45 msg = " #{$$} #{Module === self ? self : self.class} #{msg}" |
46 case @_logger |
47 when Proc |
48 @_logger.call msg |
49 when IO |
50 @_logger.puts msg |
51 else |
52 $stderr.puts msg |
53 end |
54 nil |
55 end |
56 |
57 def _log_result msg |
58 _log { |
59 msg = String === msg ? msg : _log_format(msg); |
60 "#{msg} => ..." } |
61 result = yield |
62 _log { "#{msg} => \n #{result.inspect}" } |
63 result |
64 end |
65 |
66 def _log_format obj |
67 case obj |
68 when Exception |
69 "#{obj.inspect}\n #{obj.backtrace * "\n "}" |
70 when Array |
71 obj.map { | x | _log_format x } * ", " |
72 else |
73 obj.inspect |
74 end |
75 end |
76 end # module |
77 end # module |
78 |
79 |
80 |
Generated on Fri Jan 27 17:37:46 -0600 2012 with rcov 0.9.8