errlog 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e34622fa375c0d03a9146d8c33a2c0de3800d6c
4
- data.tar.gz: c5b0c688c78cb5bc0d69377c7d80f52dcba770be
3
+ metadata.gz: d90364c90b687b6ecaa2bcf73018f281eff1aaff
4
+ data.tar.gz: ec8ebdc1660cdbd7ad5d2542da2652785d76c6cf
5
5
  SHA512:
6
- metadata.gz: 9a24d4280575e54d3bb551e5cb485b14507c49f6ef13496cab175b64dc962589f623d4888c8c396f88b781271d1216674c899145b52bbfa05f5bbb57b4e4f4cc
7
- data.tar.gz: 2515dcbef0f0a7cd3bc42d703c3b1129abd3cb2f06c54b4842324341612b3c4adae16be27e81227cf5fc22f24bb0809af105b94f2eab4a561128a5015d82bc6a
6
+ metadata.gz: 8b62f8568e4cd90b0bd8cc73d1139d0f7f4e8b1751a03483119f5a95f39832107bc08b53407504b162f7c0c383f32494bfbc6d5de002d109b1c36dca102f0555
7
+ data.tar.gz: a4e69d69a7b12f6486a1730ef464466b79dd9d13ebb9c332b35681c206f570d44316db8e8c745c468ef57ddca67c076349c750942b4c9e85bb4d75edde9a1dad
data/.gitignore CHANGED
@@ -17,4 +17,5 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  .idea
20
- .rbx
20
+ .rbx
21
+ .errlog.yml
@@ -30,6 +30,10 @@ Parameters
30
30
  -a appname
31
31
  set the application name. 'default' if not set.
32
32
 
33
+ -t test package
34
+ This mode allows developer to test the packed data. Pass your packed in base64 form instead of the
35
+ text and you will either see the unpacked data or an error message.
36
+
33
37
  Some/all of there parameters might be set in the .errlog.yml file in the current path
34
38
  or down the tree. Command-line parameters override these from configuration file.
35
39
 
@@ -51,20 +55,22 @@ end
51
55
  usage if ARGV.length == 0
52
56
 
53
57
  key, id, text, host, app, platform = nil, nil, '', nil, nil, nil
54
- severity = 100
58
+ severity = 100
59
+
60
+ test_mode = false
55
61
 
56
62
  begin
57
63
  n = 0
58
64
  while n < ARGV.length do
59
65
  arg = ARGV[n]
60
- n += 1
66
+ n += 1
61
67
  case arg
62
68
  when '-k'
63
69
  key = ARGV[n]
64
- n += 1
70
+ n += 1
65
71
  when '-i'
66
72
  id = ARGV[n]
67
- n += 1
73
+ n += 1
68
74
  when /^--local/
69
75
  host = "http://localhost:8080"
70
76
  when /^--warn/
@@ -73,10 +79,12 @@ begin
73
79
  severity = Errlog::TRACE
74
80
  when '-a'
75
81
  app = ARGV[n]
76
- n += 1
82
+ n += 1
77
83
  when '-p'
78
84
  platform = ARGV[n]
79
- n += 1
85
+ n += 1
86
+ when '-t'
87
+ test_mode = true
80
88
  else
81
89
  text = arg.strip
82
90
  break
@@ -99,10 +107,10 @@ if !key || !id
99
107
  error "Neither id/key or configuration file was found"
100
108
  usage
101
109
  end
102
- cfg = OpenStruct.new YAML::load_file(cfile)
103
- id ||= cfg.account_id
104
- key ||= cfg.account_key
105
- app ||= cfg.application
110
+ cfg = OpenStruct.new YAML::load_file(cfile)
111
+ id ||= cfg.account_id
112
+ key ||= cfg.account_key
113
+ app ||= cfg.application
106
114
  platform ||= cfg.platform
107
115
  end
108
116
 
@@ -113,12 +121,21 @@ end
113
121
 
114
122
  usage if !key || !id || text.length == 0
115
123
 
116
- Errlog.configure id, key, {host: host}
117
- Errlog.context.platform = platform
124
+ Errlog.configure id, key, { host: host }
125
+ Errlog.context.platform = platform
118
126
  Errlog.context.application = app
119
127
 
120
- Errlog.report text, severity do |error|
121
- STDERR.puts "Error: #{error}".red if error
122
- exit error ? 10 : 0
128
+ if test_mode
129
+ packager = Errlog.default_packager
130
+ packager.throw_errors = true
131
+ puts "Decoded valid errlog package: \n#{packager.unpack(Base64.decode64(text)).inspect}"
132
+ exit 0
123
133
  end
124
- Errlog.wait
134
+
135
+ Errlog.report text, severity
136
+ if Errlog.wait
137
+ STDERR.puts "Error sending the report".red
138
+ exit 10
139
+ end
140
+
141
+ exit 0
@@ -41,6 +41,7 @@ module Errlog
41
41
  end
42
42
 
43
43
  @@configured = false
44
+ @@send_error = false
44
45
 
45
46
  # Configure your instance. Sbhould be called before any other methods. Follow http://errorlog.co/help/rails
46
47
  # to get your credentials
@@ -118,6 +119,10 @@ module Errlog
118
119
  @@packager.pack(data)
119
120
  end
120
121
 
122
+ def self.default_packager
123
+ @@packager
124
+ end
125
+
121
126
  def self.protect component_name=nil, options={}, &block
122
127
  context.protect component_name, options, &block
123
128
  end
@@ -156,6 +161,12 @@ module Errlog
156
161
  Thread.current[:errlog_context] || clear_context
157
162
  end
158
163
 
164
+ def self.wait
165
+ @@send_threads.each { |t| t.weakref_alive? and t.join }
166
+ @@send_threads == []
167
+ @@send_error
168
+ end
169
+
159
170
  private
160
171
 
161
172
  def self.post src
@@ -175,19 +186,14 @@ module Errlog
175
186
  error = "report refused: #{res.status}" if res.status != 200
176
187
  rescue Exception => e
177
188
  error = e
189
+ @@send_error = error
178
190
  end
179
191
  STDERR.puts "Error sending errlog: #{error}" if error
180
- #puts "sent" unless error
181
192
  yield error if block_given?
182
193
  }
183
194
  @@send_threads << WeakRef.new(t)
184
195
  end
185
196
 
186
- def self.wait
187
- @@send_threads.each { |t| t.weakref_alive? and t.join }
188
- @@send_threads == []
189
- end
190
-
191
197
  end
192
198
 
193
199
  if defined?(Rails) && Rails.env == 'test'
@@ -12,9 +12,14 @@ module Errlog
12
12
  # transfer the report over the network. Normally you don't use it directly.
13
13
  class Packager
14
14
 
15
- def initialize app_id, app_key
15
+ attr_accessor :throw_errors
16
+
17
+ class Exception < Exception; end;
18
+
19
+ def initialize app_id, app_key, throw_errors = false
16
20
  @appid = app_id
17
21
  @key = app_key.length == 16 ? app_key : Base64.decode64(app_key)
22
+ @throw_errors = throw_errors
18
23
  end
19
24
 
20
25
  # AES-128 encrypt the block
@@ -57,14 +62,18 @@ module Errlog
57
62
  data = block[1...-32]
58
63
  sign = block[-32..-1]
59
64
  if sign != Digest::SHA256.digest(data + @key)
65
+ puts "Sign does not match"
66
+ @throw_errors and raise Exception, "Wrong signature"
60
67
  nil
61
68
  else
62
69
  JSON.parse Zlib::GzipReader.new(StringIO.new(data)).read
63
70
  end
64
71
  else
72
+ @throw_errors and raise Exception, "Unknown block type: #{block[0].ord}"
65
73
  nil
66
74
  end
67
75
  rescue
76
+ @throw_errors and raise
68
77
  nil
69
78
  end
70
79
 
@@ -1,3 +1,3 @@
1
1
  module Errlog
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergeych
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-18 00:00:00.000000000 Z
11
+ date: 2013-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: boss-protocol