errlog 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17e96f6052645fe7624fcde6a74b51d026cd1411
4
- data.tar.gz: bd1de2e4d3b099273b6431e1f960cd799c991a96
3
+ metadata.gz: 54e8865dba485273e01719ecce629f3eadeb2c45
4
+ data.tar.gz: 4a90e337de26a0fc931c96f1082e5b1481186d62
5
5
  SHA512:
6
- metadata.gz: 50139bfaecb2c2efce08c9e2026c975b5dc5be3c191b5053f5d93db96d2ba8e4b8d2c8b779b73f1332c10062c00a6b549bb69274740157643993e2976b83a3a5
7
- data.tar.gz: bbc4e3a5e7736f4df68572c4d3ff020fc263e4be04a38c6a315666c5c5eb34a7f613145178d3fd2ce19e9ab51c760d2b4ae32f668855cb3c8533738938a3f808
6
+ metadata.gz: bc317d9befb4e5afd34df91bba2e17fb965ac19b3291d24884f72bf0996646489bb41046926ae377dfa9178fc2153f2fdb62520b21c6eaf7c05bf825d9e9baae
7
+ data.tar.gz: e12f81821ae131d2987e9218d5577aacc5122459cba5d3e0397a811b2d55c2389cf26e75b6146e9ac18b06c43b2610b5484d9f51ff22fe38c6684dcbe6042190
data/README.md CHANGED
@@ -58,6 +58,10 @@ details are available at http://errorlog.co/help/rails
58
58
 
59
59
  As the service is under active development, be sure to `bundle update errlog` regularly.
60
60
 
61
+ ## Clients for other platforms:
62
+
63
+ * iPhone IOS (objectiveC): https://github.com/sergeych/errlog-ios
64
+
61
65
  ## Contributing
62
66
 
63
67
  1. Fork it
@@ -15,27 +15,37 @@ if defined?(Rails)
15
15
  require 'errlog/rails_controller_extensions'
16
16
  end
17
17
 
18
+ =begin
19
+ The reporting module for errlog service, see http://errorlog.com for details.
20
+
21
+ The usage is quite simple:
22
+
23
+ Errlog.configure(
24
+ account_id, account_secret,
25
+ :application => 'MyGreatApplication')
26
+
27
+ And use any of {Errlog.context} and {Errlog::Context} methods to report exceptions,
28
+ collect logs, traces and so on.
29
+
30
+ See http://errorlog.co/help for more.
31
+ =end
32
+
18
33
  module Errlog
19
34
 
20
35
  include Errlog::Constants
36
+ extend Errlog::Constants
21
37
 
22
- def self.severity_name code
23
- case code
24
- when TRACE...WARNING;
25
- 'trace'
26
- when WARNING...ERROR;
27
- 'warning'
28
- else
29
- ; 'error'
30
- end
31
- end
32
-
38
+ # @return [Errlog::Packager] packager instance for configured credentials, see {Errorlog.configure}
33
39
  def self.packager id, key
34
40
  return Packager.new id, key
35
41
  end
36
42
 
37
43
  @@configured = false
38
44
 
45
+ # Configure your instance. Sbhould be called before any other methods. Follow http://errorlog.co/help/rails
46
+ # to get your credentials
47
+ #
48
+ # @param [string] id account id
39
49
  def self.configure id, key, opts={}
40
50
  @@configured = true
41
51
  @@app_id, @@app_secret, @options = id, key, opts
@@ -49,7 +59,9 @@ module Errlog
49
59
  @@component = nil
50
60
 
51
61
  if @@rails && !opts[:no_catch_logs]
52
- @@logger = Rails.logger = ChainLogger.new Rails.logger
62
+ if Rails.env != 'test'
63
+ @@logger = Rails.logger = ChainLogger.new Rails.logger
64
+ end
53
65
  ActionController::Base.logger = ChainLogger.new ActionController::Base.logger
54
66
  if defined?(ActiveRecord)
55
67
  ActiveRecord::Base.logger = ChainLogger.new ActiveRecord::Base.logger
@@ -63,8 +75,15 @@ module Errlog
63
75
  end
64
76
  end
65
77
 
66
- def self.logger
67
- @@logger ||= ChainLogger.new
78
+ # Create logger that will report its content on {Errlog.error}, {Errlog.trace} and {Errlog.warning}
79
+ # and {ErrlogContext} reporting funtions. It can user existing logger to pass through, ot will create
80
+ # {Logger} with STDOUT
81
+ #
82
+ # @param logger existing logger to pass log to, If nil, STDOUT Logger will be created
83
+ # @return [ChainLogger] new instance.
84
+ def self.logger logger = nil
85
+ logger ||= Logger.new(STDOUT)
86
+ @@logger ||= ChainLogger.new logger
68
87
  end
69
88
 
70
89
  def self.use_logging?
@@ -91,6 +110,10 @@ module Errlog
91
110
  @@rails
92
111
  end
93
112
 
113
+ def self.rails_test?
114
+ @rails_test == nil and @rails_test = @@rails && Rails.env == 'test'
115
+ end
116
+
94
117
  def self.pack data
95
118
  @@packager.pack(data)
96
119
  end
@@ -137,7 +160,8 @@ module Errlog
137
160
 
138
161
  def self.post src
139
162
  if @@rails && Rails.env == 'test'
140
- Rails.logger.info "Errlog: sending: #{src[:text]}"
163
+ Rails.logger.info "Errlog: #{severity_name(src[:severity])}: #{src['text']}"
164
+ stack=src['stack'] and Rails.logger.info " #{stack.join("\n ")}"
141
165
  return
142
166
  end
143
167
  data = pack(src)
@@ -24,13 +24,19 @@ module Errlog
24
24
 
25
25
  # @return current log level
26
26
  def level
27
- @prev_logger and @prev_logger.level
27
+ @prev_logger ? @prev_logger.level : super
28
28
  end
29
29
 
30
30
  # Standard add log method, see (Logger#add)
31
31
  def add severity, message = nil, progname = nil
32
32
  message = yield if block_given?
33
- @prev_logger and @prev_logger.add(severity, message, progname)
33
+ if Errlog.rails_test?
34
+ Rails.logger.add(severity, message, progname)
35
+ else
36
+ @prev_logger and @prev_logger.add(severity, message, progname)
37
+ end
38
+ # Rails.logger.info "- #{@prev_logger}: #{progname} ="
39
+ #puts message #if Errlog.rails_test?
34
40
  Errlog.context.add_log_record [severity, Time.now, message, progname]
35
41
  end
36
42
 
@@ -10,6 +10,8 @@ module Errlog
10
10
  NOT_FOUND = 49
11
11
  TRACE = 1
12
12
 
13
+ STAT_DATA = 1001
14
+
13
15
  # @!endgroup
14
16
 
15
17
  def is_error?(code)
@@ -23,5 +25,20 @@ module Errlog
23
25
  def is_trace? code
24
26
  code >= TRACE && code < WARNING
25
27
  end
28
+
29
+ # @return [String] name of the corresponding severity code
30
+ def severity_name code
31
+ case code
32
+ when NOT_FOUND;
33
+ 'not found'
34
+ when TRACE...WARNING;
35
+ 'trace'
36
+ when WARNING...ERROR;
37
+ 'warning'
38
+ else
39
+ ; 'error'
40
+ end
41
+ end
42
+
26
43
  end
27
44
  end
@@ -1,5 +1,9 @@
1
1
 
2
2
  begin
3
+ # Delayed_job integration automatically detects delayed_job presence
4
+ # and report all uncaught exceptions from your delayed jobs. It also
5
+ # takes care of properly clearing the context and collection per-job
6
+ # logs
3
7
  class Delayed::Worker
4
8
  def handle_failed_job_with_errlog(job, error)
5
9
  Errlog.context.component = 'DJ'
@@ -1,45 +1,69 @@
1
1
  require 'base64'
2
2
  require 'openssl'
3
3
  require 'digest/md5'
4
+ require 'digest/sha2'
4
5
  require 'boss-protocol'
6
+ require 'stringio'
7
+ require 'json'
5
8
 
6
9
  module Errlog
7
10
 
11
+ # Packager does (un)packing data to effectively and (where possible) safely
12
+ # transfer the report over the network. Normally you don't use it directly.
8
13
  class Packager
9
14
 
10
- # class InvalidPackage < Exception; end
11
-
12
15
  def initialize app_id, app_key
13
16
  @appid = app_id
14
- @key = app_key.length == 16 ? app_key : Base64.decode64(app_key)
17
+ @key = app_key.length == 16 ? app_key : Base64.decode64(app_key)
15
18
  end
16
19
 
20
+ # AES-128 encrypt the block
17
21
  def encrypt data
18
22
  cipher = OpenSSL::Cipher.new('AES-128-CBC')
19
23
  cipher.encrypt
20
- iv = cipher.random_iv
24
+ iv = cipher.random_iv
21
25
  cipher.key = @key
22
26
  iv + cipher.update(data) + cipher.update(Digest::MD5.digest(data)) + cipher.final
23
27
  end
24
28
 
29
+ # AES-128 decrypt the block
25
30
  def decrypt ciphertext
26
31
  cipher = OpenSSL::Cipher.new('AES-128-CBC')
27
32
  cipher.decrypt
28
- cipher.iv = ciphertext[0..15]
29
- cipher.key = @key
30
- data = cipher.update(ciphertext[16..-1]) + cipher.final
33
+ cipher.iv = ciphertext[0..15]
34
+ cipher.key = @key
35
+ data = cipher.update(ciphertext[16..-1]) + cipher.final
31
36
  data, digest = data[0...-16], data[-16..-1]
32
37
  digest == Digest::MD5.digest(data) ? data : nil
33
38
  end
34
39
 
40
+ # @return [binary] packed payload using the default block format
35
41
  def pack payload
36
42
  "\x00#{encrypt(Boss.dump @appid, payload)}"
37
43
  end
38
44
 
45
+ # @return [Hash] unpacked payload or nil if block format is unknown or block seems
46
+ # to be broken (e.g. wrong credentials used)
47
+ #
48
+ # @note packager can unpack v1 (boss, encrypted) and v2 (json, unencrypted) but it does
49
+ # not pack to v2 as it is no secure and limited to US export laws castrated platforms
50
+ # like iPhone and is not recommended to be used anywhere else.
39
51
  def unpack block
40
- block[0].to_i == 0 or return nil
41
- id, payload = Boss.load_all(decrypt(block[1..-1]))
42
- id == @appid ? payload : nil
52
+ case block[0].ord
53
+ when 0
54
+ id, payload = Boss.load_all(decrypt(block[1..-1]))
55
+ id == @appid ? payload : nil
56
+ when 1
57
+ data = block[1...-32]
58
+ sign = block[-32..-1]
59
+ if sign != Digest::SHA256.digest(data + @key)
60
+ nil
61
+ else
62
+ JSON.parse Zlib::GzipReader.new(StringIO.new(data)).read
63
+ end
64
+ else
65
+ nil
66
+ end
43
67
  rescue
44
68
  nil
45
69
  end
@@ -2,10 +2,12 @@ module Errlog
2
2
  module ControllerFilter
3
3
 
4
4
  def self.included base
5
- base.send :prepend_before_filter, :errlog_connect_context
6
- base.send :rescue_from, Exception, :with => :errlog_report_exceptons
7
- base.send :helper_method, :errlog_context
8
- base.send :helper_method, :errlog_not_found
5
+ if Rails.env != 'test'
6
+ base.send :prepend_before_filter, :errlog_connect_context
7
+ base.send :rescue_from, Exception, :with => :errlog_report_exceptons
8
+ base.send :helper_method, :errlog_context
9
+ base.send :helper_method, :errlog_not_found
10
+ end
9
11
  end
10
12
 
11
13
 
@@ -1,3 +1,3 @@
1
1
  module Errlog
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.6"
3
3
  end
@@ -38,4 +38,12 @@ describe 'Packager' do
38
38
  payload = { 'type' => 'log', 'payload' => 'The test payload again' }
39
39
  @packager.unpack(Errlog.pack(payload)).should == payload
40
40
  end
41
+
42
+ it 'should unpack v1 packages' do
43
+ # V1 format uses GZip stream, no encryption and sha256 signature
44
+ b64 = 'AR+LCAAAAAAAAAOrVvJIzcnJV7KKVirPL8pJMVTSgTCMlGJrAQuX/j4dAAAAz/urvrAsvKusrC9PvECtQERrhNoH+95xE7EzR1HoThU='
45
+ data = b64.unpack('m')[0]
46
+ @packager = Errlog.packager 'TheTestId', '6rA/5Ud1WEYoTz3h9umdXw=='.unpack('m')[0]
47
+ @packager.unpack(data).should == {'Hello' => ['world1', 'world2']}
48
+ end
41
49
  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.4
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergeych
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-15 00:00:00.000000000 Z
11
+ date: 2013-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: boss-protocol