rumbrl 0.4.2 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 454f23a5e4d1da6e787cabe2b3401342497a91d3
4
- data.tar.gz: 1f940e971b54e5b8f99284d0cad0b1bdf8f3a509
3
+ metadata.gz: 20177fee591c71454318f66d334b5eead85f937b
4
+ data.tar.gz: 2757a19d5b1ef05f63d28cba1ae7155031c7d7a8
5
5
  SHA512:
6
- metadata.gz: ff0395cf81c81a6478da4f7ecf17b63e639e6156639e2dd6bd37c1ac7d8fe55caa7434bf06b2baae78390f12d6bdf219c3e670c2a05cc468e1d3ca284f40579a
7
- data.tar.gz: 41add027e16840152392fa2af81d9695c3c875c3271c4470dd03b7e8dbe22f2aa9674d9d30c9043fc309b76370b9be1a919170de30208b02502458192290f93b
6
+ metadata.gz: 638033f9fb67cbd181d6f5f62a9981b0efab4a021661e063ac1c970dc28d6c85fd21525f9ed50fbad292c54a6485bfba255d1b7127fa408b548c0b40ba623993
7
+ data.tar.gz: 5e60535c9e432886c68c1711eb133431b4c6c51673b514f55150019fed931a4cf83ad09b972d65f3ae1d7650053b9fd5c0968e8dc10369864188bf54ed7c5492
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rumbrl (0.4.2)
4
+ rumbrl (0.5.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -46,3 +46,15 @@ Time format (`::Logger#datetime_format`). Defaults to `"[%F %T %z]"`
46
46
  #### `LOG_DATA_FORMAT`
47
47
 
48
48
  How to format log data. Defaults to `[%s] [%s]`
49
+
50
+ #### `LOG_APP_NAME`
51
+
52
+ Used by the formatter object to create a KV `APP_NAME=` string in the log entry. Full format is:
53
+
54
+ ```
55
+ APP_NAME="#{ENV['LOG_APP_NAME']}::#{progname}"
56
+ ```
57
+
58
+ Where `progname` is set in your logger.
59
+
60
+ The formatter is meant to be inherited from, you can implement your own version of `format_msg`. In conjunction with the `Smash` object, you can easily format objects into log entries that are readily consumed by [SumoLogic](https://www.sumologic.com/)
@@ -0,0 +1,45 @@
1
+ require 'logger'
2
+ require 'rumbrl/smash'
3
+
4
+ module Rumbrl
5
+ # Log4r formatter
6
+ class Formatter < ::Logger::Formatter
7
+ def call(severity, _timestamp, prog, msg)
8
+ return '' if omit_empty? && empty?(msg)
9
+
10
+ "[#{severity}] APP_NAME=#{appname(prog)} #{format_msg(msg)}\n"
11
+ end
12
+
13
+ def omit_empty(switch)
14
+ if [TrueClass, FalseClass].include? switch.class
15
+ @omit_empty = switch
16
+ else
17
+ @omit_empty = false
18
+ end
19
+ end
20
+
21
+ def omit_empty?
22
+ @omit_empty.nil? || @omit_empty
23
+ end
24
+
25
+ # overwrite this to format objects that are passed in
26
+ def format_msg(msg)
27
+ "#{msg}"
28
+ end
29
+
30
+ private
31
+
32
+ def empty?(obj)
33
+ obj.respond_to?(:empty?) && obj.empty?
34
+ end
35
+
36
+ def app_namespace
37
+ ENV.fetch('LOG_APP_NAME', 'RubyApplication')
38
+ end
39
+
40
+ def appname(progname)
41
+ progname = (progname.nil? || progname.strip.empty?) ? '' : progname.strip
42
+ (progname.empty?) ? app_namespace : "#{app_namespace}::#{progname}"
43
+ end
44
+ end
45
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module Rumbrl
5
- VERSION = '0.4.2'
5
+ VERSION = '0.5.0'
6
6
  end
data/lib/rumbrl.rb CHANGED
@@ -2,6 +2,7 @@ require 'rumbrl/version'
2
2
 
3
3
  require 'rumbrl/env'
4
4
  require 'rumbrl/factory'
5
+ require 'rumbrl/formatter'
5
6
  require 'rumbrl/grumble'
6
7
  require 'rumbrl/grumble_factory'
7
8
  require 'rumbrl/log'
@@ -0,0 +1,58 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe Rumbrl::Formatter do
4
+ let(:formatter) { Rumbrl::Formatter.new }
5
+
6
+ before :each do
7
+ allow(ENV).to receive(:fetch).and_return 'SPECDEFAULT'
8
+ end
9
+
10
+ describe '#omit_empty?' do
11
+ it 'defaults to true' do
12
+ expect(formatter.omit_empty?).to be true
13
+ end
14
+ end
15
+
16
+ describe '#omit_empty' do
17
+ it 'sets the flag correctly' do
18
+ formatter.omit_empty(false)
19
+
20
+ expect(formatter.omit_empty?).to be false
21
+ end
22
+
23
+ it 'non-boolean args sets flag to false' do
24
+ formatter.omit_empty(0)
25
+ expect(formatter.omit_empty?).to be false
26
+
27
+ formatter.omit_empty('false')
28
+ expect(formatter.omit_empty?).to be false
29
+ end
30
+ end
31
+
32
+ describe '#call' do
33
+ context 'when omit_empty? is set' do
34
+ before :each do
35
+ formatter.omit_empty(true)
36
+ end
37
+
38
+ it 'it returns empty string' do
39
+ expect(formatter.call('INFO', Time.now, 'SPECS', ''))
40
+ end
41
+ end
42
+
43
+ context 'when omit_empty? is not set' do
44
+ before :each do
45
+ formatter.omit_empty(false)
46
+ end
47
+
48
+ context 'and msg is a string' do
49
+ it 'it returns a formatted string' do
50
+ expected = "[INFO] APP_NAME=SPECDEFAULT::SPECS stuff\n"
51
+ res = formatter.call('INFO', nil, 'SPECS', 'stuff')
52
+
53
+ expect(res).to eq expected
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumbrl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chr0n1x
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-21 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -97,6 +97,7 @@ files:
97
97
  - lib/rumbrl.rb
98
98
  - lib/rumbrl/env.rb
99
99
  - lib/rumbrl/factory.rb
100
+ - lib/rumbrl/formatter.rb
100
101
  - lib/rumbrl/grumble.rb
101
102
  - lib/rumbrl/grumble_factory.rb
102
103
  - lib/rumbrl/log.rb
@@ -104,6 +105,7 @@ files:
104
105
  - lib/rumbrl/version.rb
105
106
  - rumbrl.gemspec
106
107
  - spec/rumbrl/factory_spec.rb
108
+ - spec/rumbrl/formatter_spec.rb
107
109
  - spec/rumbrl/grumble_factory_spec.rb
108
110
  - spec/rumbrl/grumble_spec.rb
109
111
  - spec/rumbrl/log_spec.rb
@@ -135,6 +137,7 @@ specification_version: 4
135
137
  summary: ''
136
138
  test_files:
137
139
  - spec/rumbrl/factory_spec.rb
140
+ - spec/rumbrl/formatter_spec.rb
138
141
  - spec/rumbrl/grumble_factory_spec.rb
139
142
  - spec/rumbrl/grumble_spec.rb
140
143
  - spec/rumbrl/log_spec.rb