semlogger 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -2,7 +2,10 @@ require 'json'
2
2
 
3
3
  class Object
4
4
  def to_semlogger
5
- [self.class.name.to_sym, self.respond_to?( :serializable_hash) ? self.serializable_hash : self ]
5
+ [
6
+ self.class.name.to_sym,
7
+ self.respond_to?( :serializable_hash) ? self.serializable_hash : self
8
+ ]
6
9
  end
7
10
  end
8
11
 
@@ -28,14 +31,25 @@ end
28
31
 
29
32
  class Semlogger < ::Logger
30
33
  class Base
34
+ class <<self
35
+ attr_accessor :logger
36
+ end
31
37
  attr_accessor :logger
32
38
 
33
- def add severity, progname = nil, &block
34
- @logger.add severity, self, progname = nil, &block
39
+ def initialize
40
+ @logger = self.class.logger
41
+ end
42
+
43
+ def add severity, logger = nil, &block
44
+ (logger || @logger).add severity, self, &block
35
45
  end
36
46
 
37
47
  ::Semlogger::Severity.constants.each do |severity|
38
- module_eval "def #{severity.downcase}( *a, &e) add #{::Semlogger::Severity.const_get severity}, *a, &e end", __FILE__, __LINE__
48
+ module_eval <<-EOC, __FILE__, __LINE__+1
49
+ def #{severity.downcase} *a, &e
50
+ add #{::Semlogger::Severity.const_get severity}, *a, &e
51
+ end
52
+ EOC
39
53
  end
40
54
  end
41
55
 
@@ -51,16 +65,29 @@ class Semlogger < ::Logger
51
65
 
52
66
  attr_accessor :logdev, :level, :progname
53
67
  class <<self
54
- attr_accessor :progname
55
-
56
- def custom( *a) CustomType.new *a end
57
- end
68
+ attr_accessor :progname, :logger
69
+
70
+ def new_rails_logger config
71
+ require 'semlogger/rack'
72
+ logdev = ::Rails.root.join( 'log', "#{::Rails.env.to_s.gsub('%', '%%')}.%Y-%m-%d.%$.log").to_s
73
+ logger = nil
74
+ if Rails.env.production?
75
+ logger = new logdev
76
+ logger.level = Semlogger::INFO
77
+ elsif Rails.env.development?
78
+ logger = new Semlogger::Multiplex.new( Semlogger::FInfo.new( Semlogger::Printer.new), Semlogger::Writer.new( logdev))
79
+ logger.level = Semlogger::DEBUG
80
+ else
81
+ logger = new logdev
82
+ logger.level = Semlogger::DEBUG
83
+ end
84
+ config.middleware.swap Rails::Rack::Logger, Semlogger::Rack, [], {reqid: :uuid}
85
+ config.logger = logger
86
+ end
58
87
 
59
- def custom *a
60
- r = CustomType.new *a
61
- r.logger = self
62
- r
88
+ def custom( *a) CustomType.new( *a).tap {|t| t.logger = self.logger } end
63
89
  end
90
+ def custom( *a) CustomType.new( *a).tap {|t| t.logger = self } end
64
91
 
65
92
  @@progname = nil
66
93
 
@@ -70,6 +97,7 @@ class Semlogger < ::Logger
70
97
  end
71
98
  @progname = a[0] || @@progname
72
99
  @level, @data, @tags, @logdev = DEBUG, {}, [], logdev
100
+ self.class.logger = self if !self.class.logger && self.class.logger.is_a?( Semlogger::Default)
73
101
  end
74
102
 
75
103
  def tagged *tags, &e
@@ -142,6 +170,11 @@ end
142
170
 
143
171
  require 'semlogger/rotate'
144
172
  require 'semlogger/multiplex'
145
- require 'semlogger/rack'
146
173
  require 'semlogger/filter'
147
174
  require 'semlogger/writer'
175
+
176
+ class Semlogger
177
+ class Default < Semlogger
178
+ end
179
+ self.logger ||= Default.new
180
+ end
@@ -3,7 +3,11 @@ end
3
3
 
4
4
  class Semlogger::Writer < Semlogger::Output
5
5
  def initialize logdev = nil
6
- @logdev = logdev || ::Semlogger::Rotate.new( ::Rails.root.join( 'log', ::Rails.env).to_s.gsub('%', '%%') + '.%Y-%m-%d.%$.log')
6
+ @logdev = case logdev
7
+ when String then ::Semlogger::Rotate.new logdev
8
+ when nil then ::Semlogger::Rotate.new "log/#{File.basename $0}.%Y-%m-%d.%$.log"
9
+ else logdev
10
+ end
7
11
  end
8
12
 
9
13
  def add severity, time, progname, data, tags, message
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 7
9
- version: 0.0.7
8
+ - 8
9
+ version: 0.0.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Denis Knauf
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-10-17 00:00:00 +02:00
17
+ date: 2012-10-19 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency