buffered_logger 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/buffered_logger.rb +58 -0
  2. metadata +80 -0
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'active_support/buffered_logger'
3
+ require 'forwardable'
4
+
5
+ class BufferedLogger
6
+ extend Forwardable
7
+
8
+ def_delegators :@logger, :level, :flush, :auto_flushing=
9
+
10
+ DEFAULT_FORMATTER = "%s"
11
+ DEFAULT_PADDING = ""
12
+ PADDING_CHAR = " "
13
+
14
+ def initialize(log_file, log_level, log_count = nil, log_size = nil)
15
+ @logger = ActiveSupport::BufferedLogger.new(log_file, log_level)
16
+ @padding, @formatter = {}, {}
17
+ end
18
+
19
+ def buffer
20
+ buf = @logger.send(:buffer)
21
+ buf && buf.join('')
22
+ end
23
+
24
+ # overwrite all the logging methods
25
+ class_eval do
26
+ [:debug, :info, :warn, :error, :fatal, :unknown].each do |method|
27
+ define_method(method) do |message|
28
+ @logger.send(method, (padding + formatter) % message.to_s)
29
+ end
30
+ end
31
+ end
32
+
33
+ def indent(indent_level)
34
+ @padding[Thread.current] = \
35
+ if indent_level == :reset
36
+ ""
37
+ elsif indent_level > 0
38
+ padding + (PADDING_CHAR * indent_level)
39
+ else
40
+ padding[0..(-1+indent_level)]
41
+ end
42
+ end
43
+
44
+ def formatter=(format)
45
+ @formatter[Thread.current] = format
46
+ end
47
+
48
+ protected
49
+
50
+ def padding
51
+ @padding[Thread.current] ||= DEFAULT_PADDING
52
+ end
53
+
54
+ def formatter
55
+ @formatter[Thread.current] ||= DEFAULT_FORMATTER
56
+ end
57
+
58
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buffered_logger
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Alex Skryl
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-24 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activesupport
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: ActiveSupport's BufferedLogger with a few enhancements
36
+ email: rut216@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/buffered_logger.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/skryl
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options: []
51
+
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.6.2
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Extending ActiveSupport's BufferedLogger
79
+ test_files: []
80
+