scrolls 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/scrolls/version.rb +1 -1
- data/lib/scrolls.rb +26 -22
- data/scrolls.gemspec +1 -0
- metadata +14 -3
data/lib/scrolls/version.rb
CHANGED
data/lib/scrolls.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "thread"
|
2
|
+
require "atomic"
|
2
3
|
|
3
4
|
require "scrolls/version"
|
4
5
|
|
@@ -13,8 +14,12 @@ module Scrolls
|
|
13
14
|
Log.log_exception(data, e)
|
14
15
|
end
|
15
16
|
|
17
|
+
def global_context(data)
|
18
|
+
Log.global_context = data
|
19
|
+
end
|
20
|
+
|
16
21
|
def context(data, &blk)
|
17
|
-
Log.
|
22
|
+
Log.with_context(data, &blk)
|
18
23
|
end
|
19
24
|
|
20
25
|
module Log
|
@@ -34,7 +39,15 @@ module Scrolls
|
|
34
39
|
"debug" => 7
|
35
40
|
}
|
36
41
|
|
37
|
-
attr_accessor :stream
|
42
|
+
attr_accessor :stream
|
43
|
+
|
44
|
+
def context
|
45
|
+
Thread.current[:scrolls_context] ||= {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def context=(hash)
|
49
|
+
Thread.current[:scrolls_context] = hash
|
50
|
+
end
|
38
51
|
|
39
52
|
def start(out = nil)
|
40
53
|
# This allows log_exceptions below to pick up the defined output,
|
@@ -42,6 +55,7 @@ module Scrolls
|
|
42
55
|
@defined = out.nil? ? false : true
|
43
56
|
|
44
57
|
sync_stream(out)
|
58
|
+
@global_context = Atomic.new({})
|
45
59
|
end
|
46
60
|
|
47
61
|
def sync_stream(out = nil)
|
@@ -87,11 +101,8 @@ module Scrolls
|
|
87
101
|
end
|
88
102
|
|
89
103
|
def log(data, &blk)
|
90
|
-
|
91
|
-
|
92
|
-
else
|
93
|
-
logdata = data
|
94
|
-
end
|
104
|
+
merged_context = @global_context.value.merge(context)
|
105
|
+
logdata = merged_context.merge(data)
|
95
106
|
|
96
107
|
unless blk
|
97
108
|
write(logdata)
|
@@ -145,23 +156,16 @@ module Scrolls
|
|
145
156
|
end
|
146
157
|
end
|
147
158
|
|
148
|
-
def
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
@context = @context.merge(prefix)
|
155
|
-
|
156
|
-
if blk
|
157
|
-
yield
|
158
|
-
@context = @stash.pop
|
159
|
-
end
|
159
|
+
def with_context(prefix)
|
160
|
+
return unless block_given?
|
161
|
+
old_context = context
|
162
|
+
self.context = old_context.merge(prefix)
|
163
|
+
yield if block_given?
|
164
|
+
self.context = old_context
|
160
165
|
end
|
161
166
|
|
162
|
-
def
|
163
|
-
@
|
164
|
-
@context = {}
|
167
|
+
def global_context=(data)
|
168
|
+
@global_context.update { |_| data }
|
165
169
|
end
|
166
170
|
|
167
171
|
end
|
data/scrolls.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrolls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,19 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-04-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: atomic
|
16
|
+
requirement: &70343059161980 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70343059161980
|
14
25
|
description: Logging, easier, more consistent.
|
15
26
|
email:
|
16
27
|
- curt@heroku.com
|