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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb7e9b0c7705fcdbfd723890c04ccbb1f5aeb944
4
- data.tar.gz: d554034a757044f6880a9e12a8e1fad0ff83d1fb
3
+ metadata.gz: c0febb284b9f4f18ecadc490ef8d457561d5b324
4
+ data.tar.gz: 69a11f1ef1850df831df878f0dced4cac3a4c733
5
5
  SHA512:
6
- metadata.gz: 2bcf5f48bb51ed0f433919b8a64b0671510b17159daea4e5cded9a7666384de6468ed3ee47531fd9ee144425f5b7de46e6c657292c2e36823e404f65b99d1958
7
- data.tar.gz: 5e6875c898fbb2f7239ab6c471aa1016f57ba789ecb9e32753e56039c9ab7751eb95ec6c54e08cdfd1794656dea6f3238d873e7e34334893f4f7b5cce9ace5bd
6
+ metadata.gz: 5360b860e911a0dfbdef2b3eaba176e9eb762f843b5ed5a8b1cb39196d6356394b7fe9b1e1e5316b5118a84ae3a325085a0445621d11bf1905acf446075deee5
7
+ data.tar.gz: b69312ebcc6f5073d8280aa052ab34a6c38ddb065285634e0d3d8b054ce5de429fe4749cb9a3f7e82f30669d8f45c7d17f0edbd92bb2eb20bdb0222d3ee07f06
data/lib/logasm.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'inflecto'
2
1
  require 'logger'
3
2
  require 'oj'
4
3
  require_relative 'logasm/adapters'
@@ -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, @service_name)
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
@@ -1,8 +1,17 @@
1
1
  class Logasm
2
2
  module Preprocessors
3
3
  def self.get(type, arguments)
4
- require_relative "preprocessors/#{type.to_s}"
5
- preprocessor = const_get(Inflecto.camelize(type.to_s))
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, service_name)
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(service_name),
19
- level: level.to_s.downcase
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
- Inflecto.underscore(service_name)
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.reduce({}) do |hash, (key, value)|
44
- hash.merge(key => serialize_time_objects(value))
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.map(&method(:serialize_time_objects))
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.0.0'
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, service_name)
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, service_name) }
5
+ subject(:event) { described_class.build_event(metadata, level, application_name) }
6
6
 
7
- let(:service_name) { 'test_service' }
8
- let(:level) { 'INFO' }
9
- let(:metadata) { {x: 'y'} }
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
- context 'when service name is in correct format' do
16
- it 'includes it in the event as application' do
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 as a lower case string' do
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.0.0
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-27 00:00:00.000000000 Z
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