logasm 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/lib/logasm.rb +0 -1
- data/lib/logasm/adapters/stdout_adapter.rb +1 -1
- data/lib/logasm/adapters/stdout_json_adapter.rb +1 -1
- data/lib/logasm/utils.rb +24 -2
- data/logasm.gemspec +13 -3
- data/spec/adapters/stdout_json_adapter_spec.rb +2 -1
- data/spec/utils_spec.rb +41 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b337bd71343caed24d803eb66ef0894db28cd135
|
4
|
+
data.tar.gz: 61c6bdcdf09b7309e335c996388933e315b892bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5206acdaa98e5fcfa8a5565d3be91dda8db603f23d722234dbb261104d380899564ac0692d93813eee76950bdcd9f5bc2ee196edde1890fb8998c9a1a0302d2b
|
7
|
+
data.tar.gz: 7e754346d1e30e11f827fad0db9438741e0a471ccf3315140b6d73acd2d6e9b66a89deb0a7e7bc4f9082d7d2f106bdd96c815fc7890b268a86aa9a62fc64fe85
|
data/.travis.yml
ADDED
data/lib/logasm.rb
CHANGED
@@ -19,7 +19,7 @@ class Logasm
|
|
19
19
|
data = metadata.select { |key, value| key != :message }
|
20
20
|
log_data = [
|
21
21
|
message,
|
22
|
-
data.empty? ? nil :
|
22
|
+
data.empty? ? nil : Utils.generate_json(data)
|
23
23
|
].compact.join(' ')
|
24
24
|
|
25
25
|
@logger.public_send level, log_data
|
@@ -10,7 +10,7 @@ class Logasm
|
|
10
10
|
def log(level, metadata = {})
|
11
11
|
if meets_threshold?(level)
|
12
12
|
message = Utils.build_event(metadata, level, @application_name)
|
13
|
-
STDOUT.puts(
|
13
|
+
STDOUT.puts(Utils.generate_json(message))
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
data/lib/logasm/utils.rb
CHANGED
@@ -13,10 +13,10 @@ class Logasm
|
|
13
13
|
# @return [Hash]
|
14
14
|
def self.build_event(metadata, level, application_name)
|
15
15
|
overwritable_params
|
16
|
-
.merge(
|
16
|
+
.merge(metadata)
|
17
17
|
.merge(
|
18
18
|
application: application_name,
|
19
|
-
level: level
|
19
|
+
level: level
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
@@ -54,6 +54,28 @@ class Logasm
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
if RUBY_PLATFORM =~ /java/
|
58
|
+
require 'jrjackson'
|
59
|
+
|
60
|
+
DUMP_OPTIONS = {
|
61
|
+
timezone: 'utc',
|
62
|
+
date_format: "YYYY-MM-dd'T'HH:mm:ss.SSSX"
|
63
|
+
}.freeze
|
64
|
+
|
65
|
+
def self.generate_json(obj)
|
66
|
+
JrJackson::Json.dump(obj, DUMP_OPTIONS)
|
67
|
+
end
|
68
|
+
else
|
69
|
+
require 'oj'
|
70
|
+
DUMP_OPTIONS = { mode: :compat, time_format: :ruby }.freeze
|
71
|
+
|
72
|
+
def self.generate_json(obj)
|
73
|
+
serialize_time_objects!(obj)
|
74
|
+
|
75
|
+
Oj.dump(obj, DUMP_OPTIONS)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
57
79
|
def self.underscore(input)
|
58
80
|
word = input.to_s.dup
|
59
81
|
word.gsub!(/::/, '/')
|
data/logasm.gemspec
CHANGED
@@ -3,8 +3,13 @@ lib = File.expand_path('../lib', __FILE__)
|
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
|
-
|
7
|
-
|
6
|
+
if RUBY_PLATFORM =~ /java/
|
7
|
+
gem.name = 'logasm-jruby'
|
8
|
+
else
|
9
|
+
gem.name = 'logasm'
|
10
|
+
end
|
11
|
+
|
12
|
+
gem.version = '1.2.0'
|
8
13
|
gem.authors = ["Salemove"]
|
9
14
|
gem.email = ["support@salemove.com"]
|
10
15
|
gem.description = %q{It's logasmic}
|
@@ -17,7 +22,12 @@ Gem::Specification.new do |gem|
|
|
17
22
|
gem.require_paths = ["lib"]
|
18
23
|
|
19
24
|
gem.add_dependency 'lru_redux'
|
20
|
-
|
25
|
+
|
26
|
+
if RUBY_PLATFORM =~ /java/
|
27
|
+
gem.add_dependency 'jrjackson'
|
28
|
+
else
|
29
|
+
gem.add_dependency 'oj'
|
30
|
+
end
|
21
31
|
|
22
32
|
gem.add_development_dependency "bundler", "~> 1.3"
|
23
33
|
gem.add_development_dependency "rake"
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'json'
|
2
3
|
require_relative '../../lib/logasm/adapters/stdout_json_adapter'
|
3
4
|
|
4
5
|
describe Logasm::Adapters::StdoutJsonAdapter do
|
@@ -12,7 +13,7 @@ describe Logasm::Adapters::StdoutJsonAdapter do
|
|
12
13
|
let(:adapter) { described_class.new(debug_level_code, service_name) }
|
13
14
|
let(:metadata) { {x: 'y'} }
|
14
15
|
let(:event) { {a: 'b', x: 'y'} }
|
15
|
-
let(:serialized_event) {
|
16
|
+
let(:serialized_event) { JSON.dump(event) }
|
16
17
|
let(:service_name) { 'my-service' }
|
17
18
|
let(:application_name) { 'my_service' }
|
18
19
|
|
data/spec/utils_spec.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Logasm::Utils do
|
4
|
+
let(:now) { Time.utc(2015, 10, 11, 23, 10, 21, 123456) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
allow(Time).to receive(:now) { now }
|
8
|
+
end
|
9
|
+
|
4
10
|
describe '.build_event' do
|
5
11
|
subject(:event) { described_class.build_event(metadata, level, application_name) }
|
6
12
|
|
@@ -8,16 +14,12 @@ describe Logasm::Utils do
|
|
8
14
|
let(:level) { :info }
|
9
15
|
let(:metadata) { {x: 'y'} }
|
10
16
|
|
11
|
-
before do
|
12
|
-
allow(Time).to receive(:now) { Time.utc(2015, 10, 11, 23, 10, 21, 123456) }
|
13
|
-
end
|
14
|
-
|
15
17
|
it 'includes it in the event as application' do
|
16
18
|
expect(event[:application]).to eq(application_name)
|
17
19
|
end
|
18
20
|
|
19
21
|
it 'includes log level' do
|
20
|
-
expect(event[:level]).to eq(
|
22
|
+
expect(event[:level]).to eq(:info)
|
21
23
|
end
|
22
24
|
|
23
25
|
it 'includes timestamp' do
|
@@ -41,13 +43,42 @@ describe Logasm::Utils do
|
|
41
43
|
expect(subject[:host]).to eq('xyz')
|
42
44
|
end
|
43
45
|
end
|
46
|
+
end
|
44
47
|
|
45
|
-
|
46
|
-
|
48
|
+
describe '.serialize_time_objects!' do
|
49
|
+
let(:object) do
|
50
|
+
{
|
51
|
+
time: Time.now,
|
52
|
+
hash: {
|
53
|
+
time: Time.now
|
54
|
+
},
|
55
|
+
array: [
|
56
|
+
Time.now,
|
57
|
+
{
|
58
|
+
time: Time.now
|
59
|
+
}
|
60
|
+
]
|
61
|
+
}
|
62
|
+
end
|
47
63
|
|
48
|
-
|
49
|
-
|
50
|
-
|
64
|
+
let(:serialized_time) { now.iso8601 }
|
65
|
+
|
66
|
+
it 'recursively serializes time objects to iso8601' do
|
67
|
+
o = object.dup
|
68
|
+
described_class.serialize_time_objects!(o)
|
69
|
+
|
70
|
+
expect(o).to eq(
|
71
|
+
time: serialized_time,
|
72
|
+
hash: {
|
73
|
+
time: serialized_time
|
74
|
+
},
|
75
|
+
array: [
|
76
|
+
serialized_time,
|
77
|
+
{
|
78
|
+
time: serialized_time
|
79
|
+
}
|
80
|
+
]
|
81
|
+
)
|
51
82
|
end
|
52
83
|
end
|
53
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logasm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salemove
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lru_redux
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- ".rspec"
|
106
106
|
- ".ruby-gemset"
|
107
107
|
- ".ruby-version"
|
108
|
+
- ".travis.yml"
|
108
109
|
- Gemfile
|
109
110
|
- README.md
|
110
111
|
- Rakefile
|