semlogger 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/semlogger.rb +6 -4
- data/lib/semlogger/rack.rb +22 -7
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.10
|
data/lib/semlogger.rb
CHANGED
@@ -72,9 +72,10 @@ class Semlogger < ::Logger
|
|
72
72
|
class <<self
|
73
73
|
attr_accessor :progname, :logger
|
74
74
|
|
75
|
-
def new_rails_logger config
|
75
|
+
def new_rails_logger config, logdev = nil
|
76
76
|
require 'semlogger/rack'
|
77
|
-
logdev
|
77
|
+
logdev ||= ::Rails.root.join 'log', "#{::Rails.env.to_s.gsub('%', '%%')}.%Y-%m-%d.%$.log"
|
78
|
+
logdev = logdev.to_s
|
78
79
|
logger = nil
|
79
80
|
if Rails.env.production?
|
80
81
|
logger = new logdev
|
@@ -106,11 +107,12 @@ class Semlogger < ::Logger
|
|
106
107
|
end
|
107
108
|
|
108
109
|
def tagged *tags, &e
|
109
|
-
@tags += tags
|
110
|
+
@tags += tags.flatten.compact
|
110
111
|
tags = tags.size
|
111
112
|
yield
|
112
113
|
ensure
|
113
|
-
tags.times { @tags.pop }
|
114
|
+
#tags.times { @tags.pop }
|
115
|
+
@tags.slice! -tags .. -1
|
114
116
|
end
|
115
117
|
|
116
118
|
def add severity, message = nil, progname = nil, &block
|
data/lib/semlogger/rack.rb
CHANGED
@@ -1,28 +1,43 @@
|
|
1
1
|
class Semlogger::Rack < Rails::Rack::Logger
|
2
2
|
def initialize app, tags = nil, data = nil
|
3
3
|
super app, tags
|
4
|
-
@data = data
|
4
|
+
@data = data || {}
|
5
5
|
end
|
6
6
|
|
7
7
|
def call_app request, env
|
8
8
|
path = request.filtered_path
|
9
|
-
|
9
|
+
Rails.logger.custom( :connection, request.ip, Thread.current.object_id, request.request_method, path).info
|
10
10
|
@app.call env
|
11
11
|
ensure
|
12
12
|
ActiveSupport::LogSubscriber.flush_all!
|
13
13
|
end
|
14
14
|
|
15
15
|
def call env
|
16
|
-
|
17
|
-
|
16
|
+
request = ActionDispatch::Request.new env
|
17
|
+
compute_tagged_ request do
|
18
|
+
compute_data_ request do
|
19
|
+
call_app request, env
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def compute_tagged_ request
|
25
|
+
if Rails.logger.respond_to? :tagged
|
26
|
+
Rails.logger.tagged( compute_tags( request)) { yield }
|
18
27
|
else
|
19
|
-
|
28
|
+
yield
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
23
|
-
def
|
24
|
-
|
32
|
+
def compute_data_ request
|
33
|
+
if Rails.logger.respond_to? :data
|
34
|
+
Rails.logger.data( compute_data( request)) { yield }
|
35
|
+
else
|
36
|
+
yield
|
37
|
+
end
|
38
|
+
end
|
25
39
|
|
40
|
+
def compute_data request
|
26
41
|
data = @data.dup
|
27
42
|
data.each do |k, v|
|
28
43
|
case v
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semlogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|