rumbrl 0.2.0 → 0.2.1

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: d09f858d6e4b21b750bc86e2c64f0fb0722f8852
4
- data.tar.gz: 7b3276e0238d6ea731542ea0fe1f34bb16ec18e6
3
+ metadata.gz: 42416cc7739466e12403fea5b1ee7b01cfaad5be
4
+ data.tar.gz: 65e5d4448dad98dc236c8b0a8cfb55b731ca7311
5
5
  SHA512:
6
- metadata.gz: 3ec5fea485d8fdeca29adea6c3dc394da6ea15de408d5bef464fb860887c0e9a597ccf689074a00d6eb2bf5cce6958fdd8fae919b965010cc6ad797d4dbb0ee9
7
- data.tar.gz: 0a70e465679698669febefaae3d1892ce0dfd4c57739ca5c489ebf54238d1c04c2ba6cac7ab1906dc7d5784b48387d1d1f07157138ac675eafd2c069686721bb
6
+ metadata.gz: 0b095ec959d537604908b41ce6838f8b3832179b5a761ba7033e5e202ac613f7d3f6d55061bdd4dab88e0039ce5a467547d7b1b4108e8c69d40622f932de3e6e
7
+ data.tar.gz: f6c40a1ae5910fce413f4a8a3c07c7bb2e8549212ceb4fa01fde04d3444e65465998dd4302e10c88d2dfab559efdfdbe893ce3b24f5b6db3c171ed7d961cc233
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rumbrl (0.2.0)
4
+ rumbrl (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,7 +2,7 @@ rumbrl
2
2
  ======
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/rumbrl.svg)](http://badge.fury.io/rb/rumbrl)
5
- [![Code Climate](https://codeclimate.com/github/behance/rumbrl/badges/gpa.svg)](https://codeclimate.com/github/behance/rumbrl)
5
+ [![Dependency Status](https://gemnasium.com/behance/rumbrl.svg)](https://gemnasium.com/behance/rumbrl)
6
6
  [![Code Climate](https://codeclimate.com/github/behance/rumbrl/badges/gpa.svg)](https://codeclimate.com/github/behance/rumbrl)
7
7
 
8
8
  **R**eally d**UMB** **R**uby **L**ogger
@@ -0,0 +1,21 @@
1
+ require 'rumbrl/log'
2
+
3
+ module Rumbrl
4
+ # Behance specific logger
5
+ class Grumble < Log
6
+ BASE_DATA_FORMAT = "CHANNEL='%s' MESSAGE='%s'"
7
+ BASE_LOG_FORMAT = "[%datetime%] LEVEL='%severity%' %message%"
8
+
9
+ def initialize(path, age, size)
10
+ super path, age, size, BASE_DATA_FORMAT, BASE_LOG_FORMAT
11
+ self.datetime_format = '%F %T'
12
+ end
13
+
14
+ def method_missing(name, channel, message, **args)
15
+ format = BASE_LOG_FORMAT
16
+ args.each { |k, v| format += " #{k.upcase}='#{v.gsub("'", '"')}'" }
17
+ setup_format(format)
18
+ super(*[name, channel, message])
19
+ end
20
+ end
21
+ end
data/lib/rumbrl/log.rb CHANGED
@@ -23,7 +23,7 @@ module Rumbrl
23
23
  def initialize(path, age, size, data_format, log_format = nil)
24
24
  @logger = ::Logger.new(log_file(path), shift_age: age, shift_size: size)
25
25
  @data_format = data_format
26
- @logger.formatter = log_formatter(log_format) if log_format
26
+ setup_format(log_format) if log_format
27
27
  end
28
28
 
29
29
  def method_missing(name, *args)
@@ -32,6 +32,10 @@ module Rumbrl
32
32
  write(args, level: name)
33
33
  end
34
34
 
35
+ def setup_format(format)
36
+ @logger.formatter = log_formatter(format)
37
+ end
38
+
35
39
  private
36
40
 
37
41
  def log_file(path)
@@ -0,0 +1,23 @@
1
+ module Rumbrl
2
+ # serializes & flattens hashes
3
+ class Smash
4
+ def self.face(namespace: '', **target)
5
+ res = {}
6
+ # flattens a hash
7
+ target.each do |k, v|
8
+ cur_nspace = build_namespace(namespace, k)
9
+ if v.is_a? Hash
10
+ res.update face(**v, namespace: cur_nspace)
11
+ next
12
+ end
13
+ res[cur_nspace.to_sym] = v
14
+ end
15
+ res
16
+ end
17
+
18
+ def self.build_namespace(prev = '', cur = '')
19
+ prev = "#{prev}_" unless prev.empty?
20
+ "#{prev}#{cur}"
21
+ end
22
+ end
23
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module Rumbrl
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  end
data/lib/rumbrl.rb CHANGED
@@ -2,4 +2,6 @@ require 'rumbrl/version'
2
2
 
3
3
  require 'rumbrl/env'
4
4
  require 'rumbrl/factory'
5
+ require 'rumbrl/grumble'
5
6
  require 'rumbrl/log'
7
+ require 'rumbrl/smash'
@@ -0,0 +1,44 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Rumbrl::Grumble do
4
+ let(:log) { Rumbrl::Grumble.new 'path/to/log', 'weekly', 123 }
5
+
6
+ before(:each) do
7
+ allow_any_instance_of(Logger::LogDevice).to receive(:write)
8
+
9
+ # TODO: make this...less hacky
10
+ allow(::File).to receive(:open).and_return(STDOUT)
11
+ end
12
+
13
+ describe 'delegates' do
14
+ it { expect(log).to delegate_method(:log).to(:logger) }
15
+ it { expect(log).to delegate_method(:debug?).to(:logger) }
16
+ it { expect(log).to delegate_method(:error?).to(:logger) }
17
+ it { expect(log).to delegate_method(:fatal?).to(:logger) }
18
+ it { expect(log).to delegate_method(:info?).to(:logger) }
19
+ it do
20
+ expect(log).to delegate_method(:datetime_format=)
21
+ .with_arguments('').to(:logger)
22
+ end
23
+ end
24
+
25
+ describe '#method_missing' do
26
+ context 'unknown method is called' do
27
+ it 'fails on unknown method call' do
28
+ expect { log.this_is_a_missing_method 'channel', 'sadtimes', {} }
29
+ .to raise_error(NoMethodError)
30
+ end
31
+ end
32
+
33
+ context 'method is known' do
34
+ it 'logs correctly' do
35
+ log = Rumbrl::Grumble.new('path/to/log', 'weekly', 123)
36
+
37
+ line = /\[.*\] LEVEL='INFO' CHANNEL='channel' MESSAGE='msg' FOO='bar'\n/
38
+ expect_any_instance_of(Logger::LogDevice).to receive(:write).with(line)
39
+
40
+ log.info('channel', 'msg', foo: 'bar')
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Rumbrl::Smash do
4
+ describe '.face' do
5
+ it 'does not change flat hash' do
6
+ target = { bar: 'foo' }
7
+ expect(Rumbrl::Smash.face(target)).to eql target
8
+ end
9
+
10
+ it 'flattens nested hashes with namespaced keys' do
11
+ target = { bar: 'foo', baz: { wee: 'boo' } }
12
+ flattened = { bar: 'foo', baz_wee: 'boo' }
13
+ expect(Rumbrl::Smash.face(target)).to eql flattened
14
+ end
15
+ end
16
+
17
+ describe '.build_namespace' do
18
+ it 'works' do
19
+ expect(Rumbrl::Smash.build_namespace('foo', 'bar')).to eql 'foo_bar'
20
+ end
21
+
22
+ it 'does not prepend when previous namespace is empty' do
23
+ expect(Rumbrl::Smash.build_namespace('', 'bar')).to eql 'bar'
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumbrl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - chr0n1x
@@ -97,11 +97,15 @@ files:
97
97
  - lib/rumbrl.rb
98
98
  - lib/rumbrl/env.rb
99
99
  - lib/rumbrl/factory.rb
100
+ - lib/rumbrl/grumble.rb
100
101
  - lib/rumbrl/log.rb
102
+ - lib/rumbrl/smash.rb
101
103
  - lib/rumbrl/version.rb
102
104
  - rumbrl.gemspec
103
105
  - spec/rumbrl/factory_spec.rb
106
+ - spec/rumbrl/grumble_spec.rb
104
107
  - spec/rumbrl/log_spec.rb
108
+ - spec/rumbrl/smash_spec.rb
105
109
  - spec/spec_helper.rb
106
110
  homepage: ''
107
111
  licenses:
@@ -129,5 +133,7 @@ specification_version: 4
129
133
  summary: ''
130
134
  test_files:
131
135
  - spec/rumbrl/factory_spec.rb
136
+ - spec/rumbrl/grumble_spec.rb
132
137
  - spec/rumbrl/log_spec.rb
138
+ - spec/rumbrl/smash_spec.rb
133
139
  - spec/spec_helper.rb