rumbrl 0.5.1 → 1.0.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: 2631d704e0e398c4c16f607f4a57301bac65aba7
4
- data.tar.gz: fea322ed8b32b8273a958a4c14db0eae74ed4125
3
+ metadata.gz: cc82af5529740703aec6e83ed9b4464b81b2fb9f
4
+ data.tar.gz: f34cac33f367edb3a0831ab58d95cef6d83a05e2
5
5
  SHA512:
6
- metadata.gz: 09eb688930ff8d487b0ea91f216e977bb46b84a0658d3383b17613fe5e3f0bc356e5c29edbdc8a10749fa7cacbea162011c965dcc4eaebc15709b94f00149ee0
7
- data.tar.gz: 72c7635b743c847a58ef7770870251f438406a925edd4aeb2b7aa0a08e70b3ce04ffe968a53c5db8b103fec4146a941ff75b6f97d76af52b725b16a8137ab2b0
6
+ metadata.gz: f85a35b5aabadcfeef69b3a354e4c4a24f59cfcfe68ae5f891c9f7c6fae6ca91d63ee0af9f1bdb1dfe4574f221b22d48551ef06fc429f10f41b264d82435d2d1
7
+ data.tar.gz: 8f7bca73de095dd2fe4203410d5150ae20ee0929a4b0371b387303807249044c9fdd5137e5b922ae1c3fe0186e9e7adeba2b12d91b4052972144ab5a3d7c7f5c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rumbrl (0.5.1)
4
+ rumbrl (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -5,5 +5,8 @@ require 'rumbrl/factory'
5
5
  require 'rumbrl/formatter'
6
6
  require 'rumbrl/grumble'
7
7
  require 'rumbrl/grumble_factory'
8
+ require 'rumbrl/kv'
8
9
  require 'rumbrl/log'
10
+ require 'rumbrl/logger'
9
11
  require 'rumbrl/smash'
12
+ require 'rumbrl/sumologic'
@@ -4,10 +4,10 @@ require 'rumbrl/smash'
4
4
  module Rumbrl
5
5
  # Log4r formatter
6
6
  class Formatter < ::Logger::Formatter
7
- def call(severity, _timestamp, prog, msg)
7
+ def call(_severity, _timestamp, _prog, msg)
8
8
  return '' if omit_empty? && empty?(msg)
9
9
 
10
- "APP_NAME=#{appname(prog)} SEVERITY=#{severity} #{format_msg(msg)}\n"
10
+ "#{format_msg(msg)}\n"
11
11
  end
12
12
 
13
13
  def omit_empty(switch)
@@ -32,14 +32,5 @@ module Rumbrl
32
32
  def empty?(obj)
33
33
  obj.respond_to?(:empty?) && obj.empty?
34
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
35
  end
45
36
  end
@@ -0,0 +1,2 @@
1
+ require 'rumbrl/kv/formatter'
2
+ require 'rumbrl/kv/logger'
@@ -0,0 +1,26 @@
1
+ require 'rumbrl/formatter'
2
+ require 'rumbrl/smash'
3
+
4
+ module Rumbrl
5
+ # Rumbrl KV module
6
+ module KV
7
+ # Log4r formatter that turns hashable objects into KV log entries
8
+ class Formatter < ::Rumbrl::Formatter
9
+ def format_msg(msg)
10
+ return "MESSAGE='#{super}'" unless msg.is_a?(Hash)
11
+
12
+ format_data ::Rumbrl::Smash.flatten(msg)
13
+ end
14
+
15
+ private
16
+
17
+ def format_data(data)
18
+ entry = ''
19
+ data.each do |k, v|
20
+ entry += " #{k.to_s.upcase}='#{v.to_s.gsub("'", '"')}'"
21
+ end
22
+ entry.strip
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ require 'logger'
2
+
3
+ module Rumbrl
4
+ # Rumbrl KV module
5
+ module KV
6
+ # Log4r logger that uses the KV formatter
7
+ class Logger < ::Logger
8
+ def initialize(*args)
9
+ super
10
+ @formatter = ::Rumbrl::KV::Formatter.new
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'logger'
2
+
3
+ module Rumbrl
4
+ # Default logger that uses Rumbrl::Formatter
5
+ class Logger < ::Logger
6
+ def initialize(*args)
7
+ super
8
+ @formatter = Formatter.new
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ require 'rumbrl/sumologic/formatter'
2
+ require 'rumbrl/sumologic/logger'
@@ -0,0 +1,34 @@
1
+ require 'rumbrl/kv/formatter'
2
+
3
+ module Rumbrl
4
+ # Rumbrl Sumologic module
5
+ module Sumologic
6
+ # Log4r formatter that turns hashable objects into KV log entries
7
+ # with some decorations specifically for sumologic
8
+ class Formatter < ::Rumbrl::KV::Formatter
9
+ def call(severity, timestamp, prg, msg)
10
+ return super if empty?(msg)
11
+
12
+ format_entry appname(prg), severity, timestamp, format_msg(msg)
13
+ end
14
+
15
+ private
16
+
17
+ def format_entry(app, sev, time, msg)
18
+ format(
19
+ "APP_NAME='%s' SEVERITY='%s' TIMESTAMP='%s' %s\n",
20
+ app, sev, time, msg
21
+ )
22
+ end
23
+
24
+ def app_namespace
25
+ ENV.fetch('LOG_APP_NAME', 'RubyApplication')
26
+ end
27
+
28
+ def appname(prog)
29
+ prog = (prog.nil? || prog.strip.empty?) ? '' : prog.strip
30
+ (prog.empty?) ? app_namespace : "#{app_namespace}::#{prog}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ require 'logger'
2
+
3
+ module Rumbrl
4
+ # Rumbrl Sumologic module
5
+ module Sumologic
6
+ # Log4r logger that uses the KV formatter
7
+ class Logger < ::Logger
8
+ def initialize(*args)
9
+ super
10
+ @formatter = ::Rumbrl::Sumologic::Formatter.new
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module Rumbrl
5
- VERSION = '0.5.1'
5
+ VERSION = '1.0.0'
6
6
  end
@@ -3,10 +3,6 @@ require_relative '../spec_helper'
3
3
  describe Rumbrl::Formatter do
4
4
  let(:formatter) { Rumbrl::Formatter.new }
5
5
 
6
- before :each do
7
- allow(ENV).to receive(:fetch).and_return 'SPECDEFAULT'
8
- end
9
-
10
6
  describe '#omit_empty?' do
11
7
  it 'defaults to true' do
12
8
  expect(formatter.omit_empty?).to be true
@@ -47,7 +43,7 @@ describe Rumbrl::Formatter do
47
43
 
48
44
  context 'and msg is a string' do
49
45
  it 'it returns a formatted string' do
50
- expected = "APP_NAME=SPECDEFAULT::SPECS SEVERITY=INFO stuff\n"
46
+ expected = "stuff\n"
51
47
  res = formatter.call('INFO', nil, 'SPECS', 'stuff')
52
48
 
53
49
  expect(res).to eq expected
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.5.1
4
+ version: 1.0.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-07-07 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -100,8 +100,15 @@ files:
100
100
  - lib/rumbrl/formatter.rb
101
101
  - lib/rumbrl/grumble.rb
102
102
  - lib/rumbrl/grumble_factory.rb
103
+ - lib/rumbrl/kv.rb
104
+ - lib/rumbrl/kv/formatter.rb
105
+ - lib/rumbrl/kv/logger.rb
103
106
  - lib/rumbrl/log.rb
107
+ - lib/rumbrl/logger.rb
104
108
  - lib/rumbrl/smash.rb
109
+ - lib/rumbrl/sumologic.rb
110
+ - lib/rumbrl/sumologic/formatter.rb
111
+ - lib/rumbrl/sumologic/logger.rb
105
112
  - lib/rumbrl/version.rb
106
113
  - rumbrl.gemspec
107
114
  - spec/rumbrl/factory_spec.rb