log-block 0.1.0 → 0.2.0
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.
- data/lib/log_block.rb +36 -24
- metadata +1 -1
data/lib/log_block.rb
CHANGED
@@ -1,32 +1,44 @@
|
|
1
1
|
require 'logger'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def get_block_logger( prefix, indent_size = 2)
|
9
|
-
BlockLogger.new( self, prefix, indent_size )
|
10
|
-
end
|
11
|
-
end
|
3
|
+
module LogBlock
|
4
|
+
module InstanceMethods
|
5
|
+
def with( prefix, indent_size = 2 )
|
6
|
+
yield get_block_logger( prefix, indent_size )
|
7
|
+
end
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@indent_size = indent_size
|
17
|
-
@prefix = prefix
|
9
|
+
def get_block_logger( prefix, indent_size = 2)
|
10
|
+
::LogBlock::BlockLogger.new( self, prefix, indent_size )
|
11
|
+
end
|
18
12
|
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
@logger
|
23
|
-
|
24
|
-
|
14
|
+
class BlockLogger
|
15
|
+
def initialize( logger, prefix, indent_size = 2 )
|
16
|
+
@logger = logger
|
17
|
+
@indent_size = indent_size
|
18
|
+
@prefix = prefix
|
25
19
|
end
|
20
|
+
|
21
|
+
def method_missing( meth, *args )
|
22
|
+
if [:debug, :info, :warn, :error, :fatal, :unknown].include?(meth)
|
23
|
+
@logger.send(meth, message(args.first))
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def message( msg )
|
30
|
+
"#{' ' * @indent_size}#{@prefix}#{msg}"
|
31
|
+
end
|
32
|
+
|
26
33
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
if defined?(Logger)
|
38
|
+
Logger.send(:include, LogBlock::InstanceMethods)
|
39
|
+
end
|
40
|
+
|
41
|
+
if defined?(ActiveSupport) and defined?(ActiveSupport::BufferedLogger)
|
42
|
+
ActiveSupport::BufferedLogger.send(:include, LogBlock::InstanceMethods)
|
32
43
|
end
|
44
|
+
|