scrolls 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/scrolls.rb +22 -11
  2. data/lib/scrolls/version.rb +1 -1
  3. metadata +1 -1
data/lib/scrolls.rb CHANGED
@@ -18,12 +18,20 @@ module Scrolls
18
18
 
19
19
  attr_accessor :stream
20
20
 
21
- def start(stream = STDOUT)
22
- @stream = stream
23
- @stream.sync = true
21
+ def start(out = nil)
22
+ # This allows log_exceptions below to pick up the defined output,
23
+ # otherwise stream out to STDERR
24
+ @defined = out.nil? ? false : true
25
+ sync_stream(out)
24
26
  log(:log => true, :start => true)
25
27
  end
26
28
 
29
+ def sync_stream(out = nil)
30
+ out = STDOUT if out.nil?
31
+ @stream = out
32
+ @stream.sync = true
33
+ end
34
+
27
35
  def mtx
28
36
  @mtx ||= Mutex.new
29
37
  end
@@ -31,7 +39,7 @@ module Scrolls
31
39
  def write(data)
32
40
  msg = unparse(data)
33
41
  mtx.synchronize do
34
- stream.puts(msg)
42
+ @stream.puts(msg)
35
43
  end
36
44
  end
37
45
 
@@ -80,19 +88,22 @@ module Scrolls
80
88
  end
81
89
 
82
90
  def log_exception(data, e)
91
+ sync_stream(STDERR) unless @defined
83
92
  log(data.merge(
84
93
  :exception => true,
85
94
  :class => e.class,
86
95
  :message => e.message,
87
96
  :exception_id => e.object_id.abs
88
97
  ))
89
- bt = e.backtrace.reverse
90
- bt[0, bt.size-6].each do |line|
91
- log(data.merge(
92
- :exception => true,
93
- :exception_id => e.object_id.abs,
94
- :site => line.gsub(/[`'"]/, "")
95
- ))
98
+ if e.backtrace
99
+ bt = e.backtrace.reverse
100
+ bt[0, bt.size-6].each do |line|
101
+ log(data.merge(
102
+ :exception => true,
103
+ :exception_id => e.object_id.abs,
104
+ :site => line.gsub(/[`'"]/, "")
105
+ ))
106
+ end
96
107
  end
97
108
  end
98
109
  end
@@ -1,3 +1,3 @@
1
1
  module Scrolls
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: