errlog 0.1.1
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 +7 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rvmrc +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/bin/errlogr +122 -0
- data/errlog.gemspec +28 -0
- data/lib/errlog.rb +120 -0
- data/lib/errlog/chain_loggger.rb +31 -0
- data/lib/errlog/constants.rb +21 -0
- data/lib/errlog/context.rb +44 -0
- data/lib/errlog/packager.rb +49 -0
- data/lib/errlog/version.rb +3 -0
- data/spec/errlog_spec.rb +89 -0
- data/spec/packager_spec.rb +41 -0
- data/spec/spec_helper.rb +17 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bbd26baa17726137322c3d5df046b9cbcdffd189
|
4
|
+
data.tar.gz: d4cc1c6f7e80b69c68b35c3f2b616588ca6cbc52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8ff796221f1b57d49247a1905a8ca00abb2e55119fe574a0fbeb38a771f331bf2c496de08c49557122fbcdfffe44c3b29a06a82141aeca5d6c04d585e30480e0
|
7
|
+
data.tar.gz: a74925cff35f45f5d496892413e64a2c28f83c04e91275e60b814d73a2c75c6b5270e2dd27aa55b5524ffca173dbfc9a41d982de05ce10c6ec19cbbe0fd478da
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 sergeych
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Errlog
|
2
|
+
|
3
|
+
*ATTENTION!*
|
4
|
+
|
5
|
+
This is a reporting tool tor errlog service, that is not yet open for public test.
|
6
|
+
|
7
|
+
|
8
|
+
The rest is a template for not to type it later on. Please ignore.
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'errlog'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install errlog
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/errlogr
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'errlog'
|
3
|
+
require 'yaml'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'colorize'
|
6
|
+
|
7
|
+
def usage
|
8
|
+
puts <<End
|
9
|
+
|
10
|
+
Errlog reporting tool (visit http://errlog.com for details)
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
|
14
|
+
errlog [params] "text to report"
|
15
|
+
|
16
|
+
Parameters
|
17
|
+
|
18
|
+
--warn, --trace
|
19
|
+
report as warning or trace, respectively (default is error)
|
20
|
+
|
21
|
+
-k <acc_key>
|
22
|
+
account key (should obtain it in http://logger.com)
|
23
|
+
|
24
|
+
-i <acc_id>
|
25
|
+
account id (should obtain it in http://logger.com)
|
26
|
+
|
27
|
+
-p platform
|
28
|
+
set the platform value
|
29
|
+
|
30
|
+
-a appname
|
31
|
+
set the application name
|
32
|
+
|
33
|
+
Some/all of there parameters might be set in the .errlog.yml file in the current path
|
34
|
+
or down the tree. Command-line parameters override these from configuration file.
|
35
|
+
|
36
|
+
Note that configuration file will not be used if both id and key are set in the command line
|
37
|
+
arguments!
|
38
|
+
|
39
|
+
exit status: 100 - error in arguments, 10 - failed to send, 0 - successfully sent
|
40
|
+
End
|
41
|
+
exit 100
|
42
|
+
end
|
43
|
+
|
44
|
+
def error text
|
45
|
+
STDOUT.puts "\n*** Error: #{text}".red
|
46
|
+
usage
|
47
|
+
end
|
48
|
+
|
49
|
+
usage if ARGV.length == 0
|
50
|
+
|
51
|
+
key, id, text, host, app, platform = nil, nil, '', nil, nil, nil
|
52
|
+
severity = 100
|
53
|
+
|
54
|
+
begin
|
55
|
+
n = 0
|
56
|
+
while n < ARGV.length do
|
57
|
+
arg = ARGV[n]
|
58
|
+
n += 1
|
59
|
+
case arg
|
60
|
+
when '-k'
|
61
|
+
key = ARGV[n]
|
62
|
+
n += 1
|
63
|
+
when '-i'
|
64
|
+
id = ARGV[n]
|
65
|
+
n += 1
|
66
|
+
when /^--local/
|
67
|
+
host = "http://localhost:3000"
|
68
|
+
when /^--warn/
|
69
|
+
severity = Errlog::WARNING
|
70
|
+
when /^--trace/
|
71
|
+
severity = Errlog::TRACE
|
72
|
+
when '-a'
|
73
|
+
app = ARGV[n]
|
74
|
+
n += 1
|
75
|
+
when '-p'
|
76
|
+
platform = ARGV[n]
|
77
|
+
n += 1
|
78
|
+
else
|
79
|
+
text = arg.strip
|
80
|
+
break
|
81
|
+
end
|
82
|
+
end
|
83
|
+
rescue
|
84
|
+
error "Error parsing arguments"
|
85
|
+
end
|
86
|
+
|
87
|
+
def search_down_the_tree(path, name)
|
88
|
+
n = File.join path, name
|
89
|
+
return n if File.exists?(n)
|
90
|
+
root = File::split(path)[0]
|
91
|
+
return nil if root == path
|
92
|
+
search_down_the_tree root, name
|
93
|
+
end
|
94
|
+
|
95
|
+
if !key || !id
|
96
|
+
unless (cfile = search_down_the_tree(Dir::pwd, '.errlog.yml'))
|
97
|
+
error "Neither id/key or configuration file was found"
|
98
|
+
usage
|
99
|
+
end
|
100
|
+
cfg = OpenStruct.new YAML::load_file(cfile)
|
101
|
+
id ||= cfg.account_id
|
102
|
+
key ||= cfg.account_key
|
103
|
+
app ||= cfg.application
|
104
|
+
platform ||= cfg.platform
|
105
|
+
end
|
106
|
+
|
107
|
+
if !key || !id || text==''
|
108
|
+
error "You must specify at least id, key and text"
|
109
|
+
usage
|
110
|
+
end
|
111
|
+
|
112
|
+
usage if !key || !id || text.length == 0
|
113
|
+
|
114
|
+
Errlog.configure id, key, {host: host}
|
115
|
+
Errlog.context.platform = platform
|
116
|
+
Errlog.context.application = app
|
117
|
+
|
118
|
+
Errlog.report text, severity do |error|
|
119
|
+
STDERR.puts "Error: #{error}".red if error
|
120
|
+
exit error ? 10 : 0
|
121
|
+
end
|
122
|
+
Errlog.wait
|
data/errlog.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'errlog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "errlog"
|
8
|
+
gem.version = Errlog::VERSION
|
9
|
+
gem.authors = ["sergeych"]
|
10
|
+
gem.email = ["real.sergeych@gmail.com"]
|
11
|
+
gem.description = %q{Logger and error reporter agent for errlog service}
|
12
|
+
gem.summary = %q{under development}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.bindir = 'bin'
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 1.9.2'
|
22
|
+
|
23
|
+
gem.add_dependency 'boss-protocol', '>= 0.1.3'
|
24
|
+
gem.add_dependency 'hashie', '>= 1.2.0'
|
25
|
+
gem.add_dependency 'httpclient', '>= 2.3'
|
26
|
+
gem.add_dependency 'colorize'
|
27
|
+
gem.add_development_dependency "rspec"
|
28
|
+
end
|
data/lib/errlog.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'errlog/version'
|
2
|
+
require 'errlog/packager'
|
3
|
+
require 'errlog/constants'
|
4
|
+
require 'errlog/chain_loggger'
|
5
|
+
require 'boss-protocol'
|
6
|
+
require 'errlog/context'
|
7
|
+
require 'hashie'
|
8
|
+
require 'thread'
|
9
|
+
require 'httpclient'
|
10
|
+
require 'weakref'
|
11
|
+
|
12
|
+
module Errlog
|
13
|
+
|
14
|
+
include Errlog::Constants
|
15
|
+
|
16
|
+
def self.severity_name code
|
17
|
+
case code
|
18
|
+
when TRACE...WARNING;
|
19
|
+
'trace'
|
20
|
+
when WARNING...ERROR;
|
21
|
+
'warning'
|
22
|
+
else
|
23
|
+
; 'error'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.packager id, key
|
28
|
+
return Packager.new id, key
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.configure id, key, opts={}
|
32
|
+
@@app_id, @@app_secret, @options = id, key, opts
|
33
|
+
@@app_name = opts[:app_name]
|
34
|
+
@@packager = packager @@app_id, @@app_secret
|
35
|
+
@@host = opts[:host] || "http://errlog.com"
|
36
|
+
@@client = HTTPClient.new
|
37
|
+
begin
|
38
|
+
Rails.env
|
39
|
+
@@rails = true
|
40
|
+
rescue
|
41
|
+
@@rails = false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.app_name
|
46
|
+
@@app_name #rescue nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.configured?
|
50
|
+
@@app_id && @@app_secret
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.default_platform
|
54
|
+
@@rails ? 'rails' : 'ruby'
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.rails?
|
58
|
+
@@rails
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.pack data
|
62
|
+
@@packager.pack(data)
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.create_logger with_logger=nil
|
66
|
+
self.context.create_logger with_logger
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.protect component_name=nil, options={}, &block
|
70
|
+
context.protect component_name, options, &block
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.protect_rethrow component_name=nil, &block
|
74
|
+
context.protect_rethrow component_name, &block
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.report_exception e, &block
|
78
|
+
self.context.report_exception e, &block
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.report text, severity = Errlog::ERROR, &block
|
82
|
+
self.context.report text, severity, &block
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.clear_context
|
86
|
+
ctx = Errlog::Context.new
|
87
|
+
Thread.current[:errlog_context] = ctx
|
88
|
+
ctx
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.context
|
92
|
+
Thread.current[:errlog_context] || clear_context
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def self.post src
|
98
|
+
data = pack(src)
|
99
|
+
@@send_threads ||= []
|
100
|
+
|
101
|
+
t = Thread.start {
|
102
|
+
#puts "sending to #{@@host}"
|
103
|
+
error = nil
|
104
|
+
begin
|
105
|
+
res = @@client.post "#{@@host}/reports/log", app_id: @@app_id, data: Base64::encode64(data)
|
106
|
+
error = "report refused: #{res.status}" if res.status != 200
|
107
|
+
rescue Exception => e
|
108
|
+
error = e
|
109
|
+
end
|
110
|
+
yield error if block_given?
|
111
|
+
}
|
112
|
+
@@send_threads << WeakRef.new(t)
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.wait
|
116
|
+
@@send_threads.each { |t| t.weakref_alive? and t.join }
|
117
|
+
@@send_threads == []
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Errlog
|
4
|
+
|
5
|
+
class ChainLogger < Logger
|
6
|
+
|
7
|
+
attr_reader :buffer, :prev_logger
|
8
|
+
|
9
|
+
def initialize prev
|
10
|
+
@buffer = []
|
11
|
+
@prev_logger = prev
|
12
|
+
super(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
def level= l
|
16
|
+
@prev_logger.level = l
|
17
|
+
end
|
18
|
+
|
19
|
+
def level
|
20
|
+
@prev_logger.level
|
21
|
+
end
|
22
|
+
|
23
|
+
def add severity, message = nil, progname = nil
|
24
|
+
message = yield if block_given?
|
25
|
+
@prev_logger and @prev_logger.add(severity, message, progname)
|
26
|
+
@buffer << [severity, Time.now, message, progname]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Errlog
|
2
|
+
module Constants
|
3
|
+
|
4
|
+
ERROR = 100
|
5
|
+
WARNING = 50
|
6
|
+
NOT_FOUND = 50
|
7
|
+
TRACE = 1
|
8
|
+
|
9
|
+
def is_error?(code)
|
10
|
+
code >= ERROR
|
11
|
+
end
|
12
|
+
|
13
|
+
def is_warning? code
|
14
|
+
code >= WARNING && code < ERROR
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_trace? code
|
18
|
+
code >= TRACE && code < WARNING
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Errlog
|
4
|
+
class Context < Hashie::Mash
|
5
|
+
|
6
|
+
def protect component_name=nil, options={}
|
7
|
+
component_name and self.component_name = component_name
|
8
|
+
begin
|
9
|
+
yield self
|
10
|
+
rescue Exception => e
|
11
|
+
report_exception e
|
12
|
+
options[:retrhow] and raise
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def protect_rethrow component_name=nil, &block
|
17
|
+
self.protect component_name, retrhow: true, &block
|
18
|
+
end
|
19
|
+
|
20
|
+
def report_exception e, &block
|
21
|
+
self.stack = e.backtrace
|
22
|
+
report "#{e.class.name}: #{e.to_s}", Errlog::ERROR
|
23
|
+
end
|
24
|
+
|
25
|
+
def report text, severity = Errlog::ERROR, &block
|
26
|
+
raise 'Errlog is not configured. Use Errlog.config' unless Errlog.configured?
|
27
|
+
!self.app_name and self.app_name = Errlog.app_name
|
28
|
+
self.time = Time.now
|
29
|
+
self.severity = severity
|
30
|
+
self.platform ||= Errlog.default_platform
|
31
|
+
self.stack ||= caller
|
32
|
+
self.text = text
|
33
|
+
@loggers and self.log = @loggers.reduce([]){ |all,x| all + x.buffer }.sort { |x,y| x[1] <=> y[1] }
|
34
|
+
Errlog.rails? and self.rails_root = Rails.root.to_s
|
35
|
+
Errlog.post(self.to_hash, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_logger with_logger=nil
|
39
|
+
l = Errlog::ChainLogger.new(with_logger)
|
40
|
+
(@loggers ||= []) << l
|
41
|
+
l
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'boss-protocol'
|
5
|
+
|
6
|
+
module Errlog
|
7
|
+
|
8
|
+
class Packager
|
9
|
+
|
10
|
+
# class InvalidPackage < Exception; end
|
11
|
+
|
12
|
+
def initialize app_id, app_key
|
13
|
+
@appid = app_id
|
14
|
+
@key = app_key.length == 16 ? app_key : Base64.decode64(app_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def encrypt data
|
18
|
+
cipher = OpenSSL::Cipher.new('AES-128-CBC')
|
19
|
+
cipher.encrypt
|
20
|
+
iv = cipher.random_iv
|
21
|
+
cipher.key = @key
|
22
|
+
iv + cipher.update(data) + cipher.update(Digest::MD5.digest(data)) + cipher.final
|
23
|
+
end
|
24
|
+
|
25
|
+
def decrypt ciphertext
|
26
|
+
cipher = OpenSSL::Cipher.new('AES-128-CBC')
|
27
|
+
cipher.decrypt
|
28
|
+
cipher.iv = ciphertext[0..15]
|
29
|
+
cipher.key = @key
|
30
|
+
data = cipher.update(ciphertext[16..-1]) + cipher.final
|
31
|
+
data, digest = data[0...-16], data[-16..-1]
|
32
|
+
digest == Digest::MD5.digest(data) ? data : nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def pack payload
|
36
|
+
"\x00#{encrypt(Boss.dump @appid, payload)}"
|
37
|
+
end
|
38
|
+
|
39
|
+
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
|
43
|
+
rescue
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/errlog_spec.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# logger_spec.rb
|
2
|
+
|
3
|
+
require 'spec_helper.rb'
|
4
|
+
require 'hashie'
|
5
|
+
require 'errlog'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
describe Errlog do
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
Errlog.configure 'TheTestId', '1234567890123456'
|
12
|
+
@packager = Errlog.packager 'TheTestId', '1234567890123456'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should have context' do
|
16
|
+
Errlog.context.value = 'test'
|
17
|
+
Errlog.context.value.should == 'test'
|
18
|
+
Errlog.clear_context
|
19
|
+
Errlog.context.value.should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
# This spec checks the whole chain - protect, report_exception, report, but does not check post
|
23
|
+
it 'should provide protection' do
|
24
|
+
Errlog.should_receive(:post).exactly(3).times do |payload|
|
25
|
+
payload = Hashie::Mash.new payload
|
26
|
+
payload.should_not be_nil
|
27
|
+
payload.stack[0].should =~ /errlog_spec/
|
28
|
+
payload.text.should == 'RuntimeError: TestError'
|
29
|
+
payload.time.should be_within(5000).of(Time.now)
|
30
|
+
payload.component_name.should == 'test'
|
31
|
+
payload.test.should == '123'
|
32
|
+
end
|
33
|
+
|
34
|
+
Errlog.protect 'test' do |ctx|
|
35
|
+
Errlog.clear_context
|
36
|
+
ctx.test = '123'
|
37
|
+
raise 'TestError'
|
38
|
+
end
|
39
|
+
|
40
|
+
-> {
|
41
|
+
Errlog.protect_rethrow 'test' do |ctx|
|
42
|
+
ctx.test = '123'
|
43
|
+
raise 'TestError'
|
44
|
+
end
|
45
|
+
}.should raise_error
|
46
|
+
|
47
|
+
Errlog.context.test = '123'
|
48
|
+
Errlog.report 'RuntimeError: TestError'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should provide logs' do
|
52
|
+
Errlog.should_receive(:post).exactly(1).times do |payload|
|
53
|
+
payload = Hashie::Mash.new payload
|
54
|
+
payload.text.should == 'LogTest'
|
55
|
+
payload.log.length.should == 2
|
56
|
+
payload.log[0][3].should == 'test info'
|
57
|
+
payload.log[1][3].should == 'test warning'
|
58
|
+
end
|
59
|
+
sio = StringIO.new
|
60
|
+
l1 = Errlog.create_logger
|
61
|
+
l2 = Errlog.create_logger Logger.new(sio)
|
62
|
+
l1.info 'test info'
|
63
|
+
l2.warn 'test warning'
|
64
|
+
Errlog.report 'LogTest', Errlog::TRACE
|
65
|
+
sio.string.should match( /W, \[.*\] WARN -- : test warning/)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should provide constants' do
|
69
|
+
extend Errlog::Constants
|
70
|
+
|
71
|
+
is_error?(Errlog::ERROR).should be_true
|
72
|
+
is_error?(Errlog::WARNING).should_not be_true
|
73
|
+
is_error?(Errlog::TRACE).should_not be_true
|
74
|
+
|
75
|
+
|
76
|
+
is_warning?(Errlog::ERROR).should_not be_true
|
77
|
+
is_warning?(Errlog::WARNING).should be_true
|
78
|
+
is_warning?(Errlog::TRACE).should_not be_true
|
79
|
+
|
80
|
+
is_trace?(Errlog::ERROR).should_not be_true
|
81
|
+
is_trace?(Errlog::WARNING).should_not be_true
|
82
|
+
is_trace?(Errlog::TRACE).should be_true
|
83
|
+
|
84
|
+
Errlog.severity_name(Errlog::ERROR).should == 'error'
|
85
|
+
Errlog.severity_name(Errlog::WARNING).should == 'warning'
|
86
|
+
Errlog.severity_name(Errlog::TRACE).should == 'trace'
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'errlog'
|
3
|
+
|
4
|
+
describe 'Packager' do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@packager = Errlog.packager 'TheTestId', '1234567890123456'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should properly cipher' do
|
11
|
+
data = 'The test data to encrypt/decrypt, just a test but long enough'
|
12
|
+
cdata = @packager.encrypt data
|
13
|
+
@packager.decrypt(cdata).should == data
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should accept base64-encoded keys too' do
|
17
|
+
p2 = Errlog.packager 'TheOtherId', Base64.encode64('1234567890123456')
|
18
|
+
data = 'The test data to encrypt/decrypt, just a test but long enough, and for another purpose'
|
19
|
+
cdata = @packager.encrypt data
|
20
|
+
p2.decrypt(cdata).should == data
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should create and parse the package' do
|
24
|
+
payload = { 'type' => 'log', 'payload' => 'The test payload' }
|
25
|
+
data = @packager.pack payload
|
26
|
+
@packager.unpack(data).should == payload
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should check that package is valid (signed)' do
|
30
|
+
payload = { 'type' => 'log', 'payload' => 'The test payload' }
|
31
|
+
data = @packager.pack payload
|
32
|
+
p2 = Errlog.packager 'TheOtherId', Base64.encode64('123456789012345678901234')
|
33
|
+
p2.unpack(data).should == nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should provide settings-driven packer' do
|
37
|
+
Errlog.configure 'TheTestId', '1234567890123456'
|
38
|
+
payload = { 'type' => 'log', 'payload' => 'The test payload again' }
|
39
|
+
@packager.unpack(Errlog.pack(payload)).should == payload
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: errlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sergeych
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: boss-protocol
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httpclient
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Logger and error reporter agent for errlog service
|
84
|
+
email:
|
85
|
+
- real.sergeych@gmail.com
|
86
|
+
executables:
|
87
|
+
- errlogr
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- .rspec
|
93
|
+
- .rvmrc
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/errlogr
|
99
|
+
- errlog.gemspec
|
100
|
+
- lib/errlog.rb
|
101
|
+
- lib/errlog/chain_loggger.rb
|
102
|
+
- lib/errlog/constants.rb
|
103
|
+
- lib/errlog/context.rb
|
104
|
+
- lib/errlog/packager.rb
|
105
|
+
- lib/errlog/version.rb
|
106
|
+
- spec/errlog_spec.rb
|
107
|
+
- spec/packager_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
homepage: ''
|
110
|
+
licenses: []
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 1.9.2
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.0.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: under development
|
132
|
+
test_files:
|
133
|
+
- spec/errlog_spec.rb
|
134
|
+
- spec/packager_spec.rb
|
135
|
+
- spec/spec_helper.rb
|