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.
Files changed (2) hide show
  1. data/lib/log_block.rb +36 -24
  2. metadata +1 -1
@@ -1,32 +1,44 @@
1
1
  require 'logger'
2
2
 
3
- class Logger
4
- def with( prefix, indent_size = 2 )
5
- yield get_block_logger( prefix, indent_size )
6
- end
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
- class BlockLogger
14
- def initialize( logger, prefix, indent_size = 2 )
15
- @logger = logger
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
- def method_missing( meth, *args )
21
- if [:debug, :info, :warn, :error, :fatal, :unknown].include?(meth)
22
- @logger.send(meth, message(args.first))
23
- else
24
- super
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
- def message( msg )
29
- "#{' ' * @indent_size}#{@prefix}#{msg}"
30
- end
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
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log-block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Moses