logasm 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/logasm.rb +0 -1
- data/lib/logasm/adapters/stdout_json_adapter.rb +2 -1
- data/lib/logasm/preprocessors.rb +11 -2
- data/lib/logasm/utils.rb +21 -9
- data/logasm.gemspec +1 -2
- data/spec/adapters/stdout_json_adapter_spec.rb +2 -1
- data/spec/utils_spec.rb +7 -17
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0febb284b9f4f18ecadc490ef8d457561d5b324
|
4
|
+
data.tar.gz: 69a11f1ef1850df831df878f0dced4cac3a4c733
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5360b860e911a0dfbdef2b3eaba176e9eb762f843b5ed5a8b1cb39196d6356394b7fe9b1e1e5316b5118a84ae3a325085a0445621d11bf1905acf446075deee5
|
7
|
+
data.tar.gz: b69312ebcc6f5073d8280aa052ab34a6c38ddb065285634e0d3d8b054ce5de429fe4749cb9a3f7e82f30669d8f45c7d17f0edbd92bb2eb20bdb0222d3ee07f06
|
data/lib/logasm.rb
CHANGED
@@ -4,11 +4,12 @@ class Logasm
|
|
4
4
|
def initialize(level, service_name, *)
|
5
5
|
@level = level
|
6
6
|
@service_name = service_name
|
7
|
+
@application_name = Utils.application_name(service_name)
|
7
8
|
end
|
8
9
|
|
9
10
|
def log(level, metadata = {})
|
10
11
|
if meets_threshold?(level)
|
11
|
-
message = Utils.build_event(metadata, level, @
|
12
|
+
message = Utils.build_event(metadata, level, @application_name)
|
12
13
|
STDOUT.puts(Oj.dump(message, mode: :compat, time_format: :ruby))
|
13
14
|
end
|
14
15
|
end
|
data/lib/logasm/preprocessors.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
class Logasm
|
2
2
|
module Preprocessors
|
3
3
|
def self.get(type, arguments)
|
4
|
-
|
5
|
-
|
4
|
+
preprocessor =
|
5
|
+
case type.to_s
|
6
|
+
when 'blacklist'
|
7
|
+
require_relative 'preprocessors/blacklist'
|
8
|
+
Preprocessors::Blacklist
|
9
|
+
when 'whitelist'
|
10
|
+
require_relative 'preprocessors/whitelist'
|
11
|
+
Preprocessors::Whitelist
|
12
|
+
else
|
13
|
+
raise "Unknown preprocessor: #{type}"
|
14
|
+
end
|
6
15
|
preprocessor.new(arguments)
|
7
16
|
end
|
8
17
|
end
|
data/lib/logasm/utils.rb
CHANGED
@@ -11,12 +11,12 @@ class Logasm
|
|
11
11
|
# @param [String] service_name
|
12
12
|
#
|
13
13
|
# @return [Hash]
|
14
|
-
def self.build_event(metadata, level,
|
14
|
+
def self.build_event(metadata, level, application_name)
|
15
15
|
overwritable_params
|
16
|
-
.merge(serialize_time_objects(metadata))
|
16
|
+
.merge(serialize_time_objects!(metadata.dup))
|
17
17
|
.merge(
|
18
|
-
application: application_name
|
19
|
-
level: level.to_s
|
18
|
+
application: application_name,
|
19
|
+
level: level.to_s
|
20
20
|
)
|
21
21
|
end
|
22
22
|
|
@@ -29,7 +29,7 @@ class Logasm
|
|
29
29
|
#
|
30
30
|
# @return [String]
|
31
31
|
def self.application_name(service_name)
|
32
|
-
|
32
|
+
underscore(service_name)
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.overwritable_params
|
@@ -38,13 +38,15 @@ class Logasm
|
|
38
38
|
}
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.serialize_time_objects(object)
|
41
|
+
def self.serialize_time_objects!(object)
|
42
42
|
if object.is_a?(Hash)
|
43
|
-
object.
|
44
|
-
|
43
|
+
object.each do |key, value|
|
44
|
+
object[key] = serialize_time_objects!(value)
|
45
45
|
end
|
46
46
|
elsif object.is_a?(Array)
|
47
|
-
object.
|
47
|
+
object.each_index do |index|
|
48
|
+
object[index] = serialize_time_objects!(object[index])
|
49
|
+
end
|
48
50
|
elsif object.is_a?(Time) || object.is_a?(Date)
|
49
51
|
object.iso8601
|
50
52
|
else
|
@@ -52,6 +54,16 @@ class Logasm
|
|
52
54
|
end
|
53
55
|
end
|
54
56
|
|
57
|
+
def self.underscore(input)
|
58
|
+
word = input.to_s.dup
|
59
|
+
word.gsub!(/::/, '/')
|
60
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
61
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
62
|
+
word.tr!("-", "_")
|
63
|
+
word.downcase!
|
64
|
+
word
|
65
|
+
end
|
66
|
+
|
55
67
|
private_class_method :overwritable_params
|
56
68
|
end
|
57
69
|
end
|
data/logasm.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "logasm"
|
7
|
-
gem.version = '1.
|
7
|
+
gem.version = '1.1.0'
|
8
8
|
gem.authors = ["Salemove"]
|
9
9
|
gem.email = ["support@salemove.com"]
|
10
10
|
gem.description = %q{It's logasmic}
|
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
17
|
gem.require_paths = ["lib"]
|
18
18
|
|
19
|
-
gem.add_dependency 'inflecto'
|
20
19
|
gem.add_dependency 'lru_redux'
|
21
20
|
gem.add_dependency 'oj'
|
22
21
|
|
@@ -14,10 +14,11 @@ describe Logasm::Adapters::StdoutJsonAdapter do
|
|
14
14
|
let(:event) { {a: 'b', x: 'y'} }
|
15
15
|
let(:serialized_event) { Oj.dump(event, mode: :compat, time_format: :ruby) }
|
16
16
|
let(:service_name) { 'my-service' }
|
17
|
+
let(:application_name) { 'my_service' }
|
17
18
|
|
18
19
|
before do
|
19
20
|
allow(Logasm::Utils).to receive(:build_event)
|
20
|
-
.with(metadata, info_level,
|
21
|
+
.with(metadata, info_level, application_name)
|
21
22
|
.and_return(event)
|
22
23
|
end
|
23
24
|
|
data/spec/utils_spec.rb
CHANGED
@@ -2,31 +2,21 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Logasm::Utils do
|
4
4
|
describe '.build_event' do
|
5
|
-
subject(:event) { described_class.build_event(metadata, level,
|
5
|
+
subject(:event) { described_class.build_event(metadata, level, application_name) }
|
6
6
|
|
7
|
-
let(:
|
8
|
-
let(:level)
|
9
|
-
let(:metadata)
|
7
|
+
let(:application_name) { 'test_service' }
|
8
|
+
let(:level) { :info }
|
9
|
+
let(:metadata) { {x: 'y'} }
|
10
10
|
|
11
11
|
before do
|
12
12
|
allow(Time).to receive(:now) { Time.utc(2015, 10, 11, 23, 10, 21, 123456) }
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
expect(event[:application]).to eq('test_service')
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'when service name is in camelcase' do
|
22
|
-
let(:service_name) { 'InformationService' }
|
23
|
-
|
24
|
-
it 'includes it in the event as lower snake case' do
|
25
|
-
expect(event[:application]).to eq('information_service')
|
26
|
-
end
|
15
|
+
it 'includes it in the event as application' do
|
16
|
+
expect(event[:application]).to eq(application_name)
|
27
17
|
end
|
28
18
|
|
29
|
-
it 'includes level
|
19
|
+
it 'includes log level' do
|
30
20
|
expect(event[:level]).to eq('info')
|
31
21
|
end
|
32
22
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logasm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.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-02-
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: inflecto
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: lru_redux
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|